1 // error-pattern:cargo-clippy
3 #![feature(box_syntax)]
4 #![feature(rustc_private)]
5 #![feature(slice_patterns)]
6 #![feature(stmt_expr_attributes)]
7 #![feature(range_contains)]
8 #![feature(str_escape)]
9 #![allow(clippy::missing_docs_in_private_items)]
10 #![recursion_limit = "256"]
11 #![warn(rust_2018_idioms, trivial_casts, trivial_numeric_casts)]
12 #![feature(crate_visibility_modifier)]
15 // FIXME: switch to something more ergonomic here, once available.
16 // (currently there is no way to opt into sysroot crates w/o `extern crate`)
17 #[allow(unused_extern_crates)]
18 extern crate fmt_macros;
19 #[allow(unused_extern_crates)]
21 #[allow(unused_extern_crates)]
22 extern crate rustc_data_structures;
23 #[allow(unused_extern_crates)]
24 extern crate rustc_errors;
25 #[allow(unused_extern_crates)]
26 extern crate rustc_plugin;
27 #[allow(unused_extern_crates)]
28 extern crate rustc_target;
29 #[allow(unused_extern_crates)]
30 extern crate rustc_typeck;
31 #[allow(unused_extern_crates)]
33 #[allow(unused_extern_crates)]
34 extern crate syntax_pos;
38 // Currently, categories "style", "correctness", "complexity" and "perf" are enabled by default,
39 // as said in the README.md of this repository. If this changes, please update README.md.
41 macro_rules! declare_clippy_lint {
42 { pub $name:tt, style, $description:tt } => {
43 declare_tool_lint! { pub clippy::$name, Warn, $description, report_in_external_macro: true }
45 { pub $name:tt, correctness, $description:tt } => {
46 declare_tool_lint! { pub clippy::$name, Deny, $description, report_in_external_macro: true }
48 { pub $name:tt, complexity, $description:tt } => {
49 declare_tool_lint! { pub clippy::$name, Warn, $description, report_in_external_macro: true }
51 { pub $name:tt, perf, $description:tt } => {
52 declare_tool_lint! { pub clippy::$name, Warn, $description, report_in_external_macro: true }
54 { pub $name:tt, pedantic, $description:tt } => {
55 declare_tool_lint! { pub clippy::$name, Allow, $description, report_in_external_macro: true }
57 { pub $name:tt, restriction, $description:tt } => {
58 declare_tool_lint! { pub clippy::$name, Allow, $description, report_in_external_macro: true }
60 { pub $name:tt, cargo, $description:tt } => {
61 declare_tool_lint! { pub clippy::$name, Allow, $description, report_in_external_macro: true }
63 { pub $name:tt, nursery, $description:tt } => {
64 declare_tool_lint! { pub clippy::$name, Allow, $description, report_in_external_macro: true }
66 { pub $name:tt, internal, $description:tt } => {
67 declare_tool_lint! { pub clippy::$name, Allow, $description, report_in_external_macro: true }
69 { pub $name:tt, internal_warn, $description:tt } => {
70 declare_tool_lint! { pub clippy::$name, Warn, $description, report_in_external_macro: true }
78 // begin lints modules, do not remove this comment, it’s used in `update_lints`
84 pub mod blacklisted_name;
85 pub mod block_in_if_condition;
88 pub mod cargo_common_metadata;
89 pub mod collapsible_if;
90 pub mod const_static_lifetime;
92 pub mod copy_iterator;
93 pub mod cyclomatic_complexity;
94 pub mod default_trait_access;
97 pub mod double_comparison;
98 pub mod double_parens;
99 pub mod drop_forget_ref;
100 pub mod duration_subsec;
101 pub mod else_if_without_else;
105 pub mod enum_glob_use;
106 pub mod enum_variants;
110 pub mod eta_reduction;
111 pub mod eval_order_dependence;
112 pub mod excessive_precision;
113 pub mod explicit_write;
114 pub mod fallible_impl_from;
118 pub mod identity_conversion;
121 pub mod implicit_return;
122 pub mod indexing_slicing;
123 pub mod infallible_destructuring_match;
124 pub mod infinite_iter;
125 pub mod inherent_impl;
126 pub mod inline_fn_without_body;
127 pub mod int_plus_one;
129 pub mod items_after_statements;
130 pub mod large_enum_variant;
134 pub mod literal_representation;
139 pub mod mem_discriminant;
147 pub mod missing_inline;
148 pub mod multiple_crate_versions;
150 pub mod mut_reference;
151 pub mod mutex_atomic;
152 pub mod needless_bool;
153 pub mod needless_borrow;
154 pub mod needless_borrowed_ref;
155 pub mod needless_continue;
156 pub mod needless_pass_by_value;
157 pub mod needless_update;
158 pub mod neg_cmp_op_on_partial_ord;
159 pub mod neg_multiply;
160 pub mod new_without_default;
162 pub mod non_copy_const;
163 pub mod non_expressive_names;
165 pub mod open_options;
166 pub mod overflow_check_conditional;
167 pub mod panic_unimplemented;
168 pub mod partialeq_ne_impl;
171 pub mod ptr_offset_with_cast;
172 pub mod question_mark;
174 pub mod redundant_clone;
175 pub mod redundant_field_names;
176 pub mod redundant_pattern_matching;
179 pub mod replace_consts;
183 pub mod slow_vector_initialization;
185 pub mod suspicious_trait_impl;
187 pub mod temporary_assignment;
189 pub mod trivially_copy_pass_by_ref;
192 pub mod unsafe_removed_from_name;
193 pub mod unused_io_amount;
194 pub mod unused_label;
198 pub mod wildcard_dependencies;
200 pub mod zero_div_zero;
201 // end lints modules, do not remove this comment, it’s used in `update_lints`
203 pub use crate::utils::conf::Conf;
206 crate use syntax::ast::{Name, NodeId};
209 pub fn register_pre_expansion_lints(
210 session: &rustc::session::Session,
211 store: &mut rustc::lint::LintStore,
214 store.register_pre_expansion_pass(Some(session), box write::Pass);
215 store.register_pre_expansion_pass(Some(session), box redundant_field_names::RedundantFieldNames);
216 store.register_pre_expansion_pass(
218 box non_expressive_names::NonExpressiveNames {
219 single_char_binding_names_threshold: conf.single_char_binding_names_threshold,
222 store.register_pre_expansion_pass(Some(session), box attrs::CfgAttrPass);
225 pub fn read_conf(reg: &rustc_plugin::Registry<'_>) -> Conf {
226 match utils::conf::file_from_args(reg.args()) {
228 // if the user specified a file, it must exist, otherwise default to `clippy.toml` but
229 // do not require the file to exist
230 let file_name = if let Some(file_name) = file_name {
233 match utils::conf::lookup_conf_file() {
237 .struct_err(&format!("error finding Clippy's configuration file: {}", error))
244 let file_name = file_name.map(|file_name| {
245 if file_name.is_relative() {
247 .local_crate_source_file
249 .and_then(|file| std::path::Path::new(&file).parent().map(std::path::Path::to_path_buf))
257 let (conf, errors) = utils::conf::read(file_name.as_ref().map(|p| p.as_ref()));
259 // all conf errors are non-fatal, we just use the default conf in case of error
260 for error in errors {
262 .struct_err(&format!(
263 "error reading Clippy's configuration file `{}`: {}",
264 file_name.as_ref().and_then(|p| p.to_str()).unwrap_or(""),
272 Err((err, span)) => {
274 .struct_span_err(span, err)
275 .span_note(span, "Clippy will use default configuration")
277 toml::from_str("").expect("we never error on empty config files")
283 pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
284 let mut store = reg.sess.lint_store.borrow_mut();
285 // begin deprecated lints, do not remove this comment, it’s used in `update_lints`
286 store.register_removed(
288 "`assert!()` will be more flexible with RFC 2011",
290 store.register_removed(
292 "`.extend_from_slice(_)` is a faster way to extend a Vec by a slice",
294 store.register_removed(
295 "range_step_by_zero",
296 "`iterator.step_by(0)` panics nowadays",
298 store.register_removed(
300 "`Vec::as_slice` has been stabilized in 1.7",
302 store.register_removed(
303 "unstable_as_mut_slice",
304 "`Vec::as_mut_slice` has been stabilized in 1.7",
306 store.register_removed(
308 "using `str::to_string` is common even today and specialization will likely happen soon",
310 store.register_removed(
312 "using `string::to_string` is common even today and specialization will likely happen soon",
314 store.register_removed(
315 "misaligned_transmute",
316 "this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr",
318 store.register_removed(
320 "using compound assignment operators (e.g. `+=`) is harmless",
322 store.register_removed(
323 "if_let_redundant_pattern_matching",
324 "this lint has been changed to redundant_pattern_matching",
326 store.register_removed(
327 "unsafe_vector_initialization",
328 "the replacement suggested by this lint had substantially different behavior",
330 // end deprecated lints, do not remove this comment, it’s used in `update_lints`
332 reg.register_late_lint_pass(box serde_api::Serde);
333 reg.register_early_lint_pass(box utils::internal_lints::Clippy);
334 reg.register_late_lint_pass(box utils::internal_lints::CompilerLintFunctions::new());
335 reg.register_early_lint_pass(box utils::internal_lints::DefaultHashTypes::default());
336 reg.register_late_lint_pass(box utils::internal_lints::LintWithoutLintPass::default());
337 reg.register_late_lint_pass(box utils::inspector::Pass);
338 reg.register_late_lint_pass(box utils::author::Pass);
339 reg.register_late_lint_pass(box types::TypePass);
340 reg.register_late_lint_pass(box booleans::NonminimalBool);
341 reg.register_late_lint_pass(box eq_op::EqOp);
342 reg.register_early_lint_pass(box enum_variants::EnumVariantNames::new(conf.enum_variant_name_threshold));
343 reg.register_late_lint_pass(box enum_glob_use::EnumGlobUse);
344 reg.register_late_lint_pass(box enum_clike::UnportableVariant);
345 reg.register_late_lint_pass(box excessive_precision::ExcessivePrecision);
346 reg.register_late_lint_pass(box bit_mask::BitMask::new(conf.verbose_bit_mask_threshold));
347 reg.register_late_lint_pass(box ptr::PointerPass);
348 reg.register_late_lint_pass(box needless_bool::NeedlessBool);
349 reg.register_late_lint_pass(box needless_bool::BoolComparison);
350 reg.register_late_lint_pass(box approx_const::Pass);
351 reg.register_late_lint_pass(box misc::Pass);
352 reg.register_early_lint_pass(box precedence::Precedence);
353 reg.register_early_lint_pass(box needless_continue::NeedlessContinue);
354 reg.register_late_lint_pass(box eta_reduction::EtaPass);
355 reg.register_late_lint_pass(box identity_op::IdentityOp);
356 reg.register_late_lint_pass(box erasing_op::ErasingOp);
357 reg.register_early_lint_pass(box items_after_statements::ItemsAfterStatements);
358 reg.register_late_lint_pass(box mut_mut::MutMut);
359 reg.register_late_lint_pass(box mut_reference::UnnecessaryMutPassed);
360 reg.register_late_lint_pass(box len_zero::LenZero);
361 reg.register_late_lint_pass(box attrs::AttrPass);
362 reg.register_early_lint_pass(box collapsible_if::CollapsibleIf);
363 reg.register_late_lint_pass(box block_in_if_condition::BlockInIfCondition);
364 reg.register_late_lint_pass(box unicode::Unicode);
365 reg.register_late_lint_pass(box strings::StringAdd);
366 reg.register_early_lint_pass(box returns::ReturnPass);
367 reg.register_late_lint_pass(box implicit_return::Pass);
368 reg.register_late_lint_pass(box methods::Pass);
369 reg.register_late_lint_pass(box map_clone::Pass);
370 reg.register_late_lint_pass(box shadow::Pass);
371 reg.register_late_lint_pass(box types::LetPass);
372 reg.register_late_lint_pass(box types::UnitCmp);
373 reg.register_late_lint_pass(box loops::Pass);
374 reg.register_late_lint_pass(box lifetimes::LifetimePass);
375 reg.register_late_lint_pass(box entry::HashMapLint);
376 reg.register_late_lint_pass(box ranges::Pass);
377 reg.register_late_lint_pass(box types::CastPass);
378 reg.register_late_lint_pass(box types::TypeComplexityPass::new(conf.type_complexity_threshold));
379 reg.register_late_lint_pass(box matches::MatchPass);
380 reg.register_late_lint_pass(box minmax::MinMaxPass);
381 reg.register_late_lint_pass(box open_options::NonSensical);
382 reg.register_late_lint_pass(box zero_div_zero::Pass);
383 reg.register_late_lint_pass(box mutex_atomic::MutexAtomic);
384 reg.register_late_lint_pass(box needless_update::Pass);
385 reg.register_late_lint_pass(box needless_borrow::NeedlessBorrow::default());
386 reg.register_late_lint_pass(box needless_borrowed_ref::NeedlessBorrowedRef);
387 reg.register_late_lint_pass(box no_effect::Pass);
388 reg.register_late_lint_pass(box temporary_assignment::Pass);
389 reg.register_late_lint_pass(box transmute::Transmute);
390 reg.register_late_lint_pass(
391 box cyclomatic_complexity::CyclomaticComplexity::new(conf.cyclomatic_complexity_threshold)
393 reg.register_late_lint_pass(box escape::Pass{too_large_for_stack: conf.too_large_for_stack});
394 reg.register_early_lint_pass(box misc_early::MiscEarly);
395 reg.register_late_lint_pass(box panic_unimplemented::Pass);
396 reg.register_late_lint_pass(box strings::StringLitAsBytes);
397 reg.register_late_lint_pass(box derive::Derive);
398 reg.register_late_lint_pass(box types::CharLitAsU8);
399 reg.register_late_lint_pass(box vec::Pass);
400 reg.register_late_lint_pass(box drop_forget_ref::Pass);
401 reg.register_late_lint_pass(box empty_enum::EmptyEnum);
402 reg.register_late_lint_pass(box types::AbsurdExtremeComparisons);
403 reg.register_late_lint_pass(box types::InvalidUpcastComparisons);
404 reg.register_late_lint_pass(box regex::Pass::default());
405 reg.register_late_lint_pass(box copies::CopyAndPaste);
406 reg.register_late_lint_pass(box copy_iterator::CopyIterator);
407 reg.register_late_lint_pass(box format::Pass);
408 reg.register_early_lint_pass(box formatting::Formatting);
409 reg.register_late_lint_pass(box swap::Swap);
410 reg.register_early_lint_pass(box if_not_else::IfNotElse);
411 reg.register_early_lint_pass(box else_if_without_else::ElseIfWithoutElse);
412 reg.register_early_lint_pass(box int_plus_one::IntPlusOne);
413 reg.register_late_lint_pass(box overflow_check_conditional::OverflowCheckConditional);
414 reg.register_late_lint_pass(box unused_label::UnusedLabel);
415 reg.register_late_lint_pass(box new_without_default::NewWithoutDefault::default());
416 reg.register_late_lint_pass(box blacklisted_name::BlackListedName::new(
417 conf.blacklisted_names.iter().cloned().collect()
419 reg.register_late_lint_pass(box functions::Functions::new(conf.too_many_arguments_threshold));
420 reg.register_early_lint_pass(box doc::Doc::new(conf.doc_valid_idents.iter().cloned().collect()));
421 reg.register_late_lint_pass(box neg_multiply::NegMultiply);
422 reg.register_early_lint_pass(box unsafe_removed_from_name::UnsafeNameRemoval);
423 reg.register_late_lint_pass(box mem_discriminant::MemDiscriminant);
424 reg.register_late_lint_pass(box mem_forget::MemForget);
425 reg.register_late_lint_pass(box mem_replace::MemReplace);
426 reg.register_late_lint_pass(box arithmetic::Arithmetic::default());
427 reg.register_late_lint_pass(box assign_ops::AssignOps);
428 reg.register_late_lint_pass(box let_if_seq::LetIfSeq);
429 reg.register_late_lint_pass(box eval_order_dependence::EvalOrderDependence);
430 reg.register_late_lint_pass(box missing_doc::MissingDoc::new());
431 reg.register_late_lint_pass(box missing_inline::MissingInline);
432 reg.register_late_lint_pass(box ok_if_let::Pass);
433 reg.register_late_lint_pass(box redundant_pattern_matching::Pass);
434 reg.register_late_lint_pass(box partialeq_ne_impl::Pass);
435 reg.register_early_lint_pass(box reference::Pass);
436 reg.register_early_lint_pass(box reference::DerefPass);
437 reg.register_early_lint_pass(box double_parens::DoubleParens);
438 reg.register_late_lint_pass(box unused_io_amount::UnusedIoAmount);
439 reg.register_late_lint_pass(box large_enum_variant::LargeEnumVariant::new(conf.enum_variant_size_threshold));
440 reg.register_late_lint_pass(box explicit_write::Pass);
441 reg.register_late_lint_pass(box needless_pass_by_value::NeedlessPassByValue);
442 reg.register_late_lint_pass(box trivially_copy_pass_by_ref::TriviallyCopyPassByRef::new(
443 conf.trivial_copy_size_limit,
446 reg.register_early_lint_pass(box literal_representation::LiteralDigitGrouping);
447 reg.register_early_lint_pass(box literal_representation::LiteralRepresentation::new(
448 conf.literal_representation_threshold
450 reg.register_late_lint_pass(box use_self::UseSelf);
451 reg.register_late_lint_pass(box bytecount::ByteCount);
452 reg.register_late_lint_pass(box infinite_iter::Pass);
453 reg.register_late_lint_pass(box inline_fn_without_body::Pass);
454 reg.register_late_lint_pass(box invalid_ref::InvalidRef);
455 reg.register_late_lint_pass(box identity_conversion::IdentityConversion::default());
456 reg.register_late_lint_pass(box types::ImplicitHasher);
457 reg.register_early_lint_pass(box const_static_lifetime::StaticConst);
458 reg.register_late_lint_pass(box fallible_impl_from::FallibleImplFrom);
459 reg.register_late_lint_pass(box replace_consts::ReplaceConsts);
460 reg.register_late_lint_pass(box types::UnitArg);
461 reg.register_late_lint_pass(box double_comparison::Pass);
462 reg.register_late_lint_pass(box question_mark::Pass);
463 reg.register_late_lint_pass(box suspicious_trait_impl::SuspiciousImpl);
464 reg.register_early_lint_pass(box cargo_common_metadata::Pass);
465 reg.register_early_lint_pass(box multiple_crate_versions::Pass);
466 reg.register_early_lint_pass(box wildcard_dependencies::Pass);
467 reg.register_late_lint_pass(box map_unit_fn::Pass);
468 reg.register_late_lint_pass(box infallible_destructuring_match::Pass);
469 reg.register_late_lint_pass(box inherent_impl::Pass::default());
470 reg.register_late_lint_pass(box neg_cmp_op_on_partial_ord::NoNegCompOpForPartialOrd);
471 reg.register_late_lint_pass(box unwrap::Pass);
472 reg.register_late_lint_pass(box duration_subsec::DurationSubsec);
473 reg.register_late_lint_pass(box default_trait_access::DefaultTraitAccess);
474 reg.register_late_lint_pass(box indexing_slicing::IndexingSlicing);
475 reg.register_late_lint_pass(box non_copy_const::NonCopyConst);
476 reg.register_late_lint_pass(box ptr_offset_with_cast::Pass);
477 reg.register_late_lint_pass(box redundant_clone::RedundantClone);
478 reg.register_late_lint_pass(box slow_vector_initialization::Pass);
479 reg.register_late_lint_pass(box types::RefToMut);
481 reg.register_lint_group("clippy::restriction", Some("clippy_restriction"), vec![
482 arithmetic::FLOAT_ARITHMETIC,
483 arithmetic::INTEGER_ARITHMETIC,
484 else_if_without_else::ELSE_IF_WITHOUT_ELSE,
485 implicit_return::IMPLICIT_RETURN,
486 indexing_slicing::INDEXING_SLICING,
487 inherent_impl::MULTIPLE_INHERENT_IMPL,
488 literal_representation::DECIMAL_LITERAL_REPRESENTATION,
489 mem_forget::MEM_FORGET,
490 methods::CLONE_ON_REF_PTR,
491 methods::OPTION_UNWRAP_USED,
492 methods::RESULT_UNWRAP_USED,
493 methods::WRONG_PUB_SELF_CONVENTION,
494 misc::FLOAT_CMP_CONST,
495 missing_doc::MISSING_DOCS_IN_PRIVATE_ITEMS,
496 missing_inline::MISSING_INLINE_IN_PUBLIC_ITEMS,
497 panic_unimplemented::UNIMPLEMENTED,
498 shadow::SHADOW_REUSE,
505 reg.register_lint_group("clippy::pedantic", Some("clippy_pedantic"), vec![
506 attrs::INLINE_ALWAYS,
507 copies::MATCH_SAME_ARMS,
508 copy_iterator::COPY_ITERATOR,
509 default_trait_access::DEFAULT_TRAIT_ACCESS,
510 derive::EXPL_IMPL_CLONE_ON_COPY,
512 empty_enum::EMPTY_ENUM,
513 enum_glob_use::ENUM_GLOB_USE,
514 enum_variants::MODULE_NAME_REPETITIONS,
515 enum_variants::PUB_ENUM_VARIANT_NAMES,
516 if_not_else::IF_NOT_ELSE,
517 infinite_iter::MAYBE_INFINITE_ITER,
518 items_after_statements::ITEMS_AFTER_STATEMENTS,
519 literal_representation::LARGE_DIGIT_GROUPS,
520 loops::EXPLICIT_INTO_ITER_LOOP,
521 loops::EXPLICIT_ITER_LOOP,
522 matches::SINGLE_MATCH_ELSE,
524 methods::MAP_FLATTEN,
525 methods::OPTION_MAP_UNWRAP_OR,
526 methods::OPTION_MAP_UNWRAP_OR_ELSE,
527 methods::RESULT_MAP_UNWRAP_OR_ELSE,
528 misc::USED_UNDERSCORE_BINDING,
529 misc_early::UNSEPARATED_LITERAL_SUFFIX,
531 needless_continue::NEEDLESS_CONTINUE,
532 needless_pass_by_value::NEEDLESS_PASS_BY_VALUE,
533 non_expressive_names::SIMILAR_NAMES,
534 replace_consts::REPLACE_CONSTS,
535 shadow::SHADOW_UNRELATED,
536 strings::STRING_ADD_ASSIGN,
537 types::CAST_POSSIBLE_TRUNCATION,
538 types::CAST_POSSIBLE_WRAP,
539 types::CAST_PRECISION_LOSS,
540 types::CAST_SIGN_LOSS,
541 types::INVALID_UPCAST_COMPARISONS,
543 unicode::NON_ASCII_LITERAL,
544 unicode::UNICODE_NOT_NFC,
548 reg.register_lint_group("clippy::internal", Some("clippy_internal"), vec![
549 utils::internal_lints::CLIPPY_LINTS_INTERNAL,
550 utils::internal_lints::COMPILER_LINT_FUNCTIONS,
551 utils::internal_lints::DEFAULT_HASH_TYPES,
552 utils::internal_lints::LINT_WITHOUT_LINT_PASS,
555 reg.register_lint_group("clippy::all", Some("clippy"), vec![
556 approx_const::APPROX_CONSTANT,
557 assign_ops::ASSIGN_OP_PATTERN,
558 assign_ops::MISREFACTORED_ASSIGN_OP,
559 attrs::DEPRECATED_CFG_ATTR,
560 attrs::DEPRECATED_SEMVER,
561 attrs::UNKNOWN_CLIPPY_LINTS,
562 attrs::USELESS_ATTRIBUTE,
563 bit_mask::BAD_BIT_MASK,
564 bit_mask::INEFFECTIVE_BIT_MASK,
565 bit_mask::VERBOSE_BIT_MASK,
566 blacklisted_name::BLACKLISTED_NAME,
567 block_in_if_condition::BLOCK_IN_IF_CONDITION_EXPR,
568 block_in_if_condition::BLOCK_IN_IF_CONDITION_STMT,
570 booleans::NONMINIMAL_BOOL,
571 bytecount::NAIVE_BYTECOUNT,
572 collapsible_if::COLLAPSIBLE_IF,
573 const_static_lifetime::CONST_STATIC_LIFETIME,
574 copies::IFS_SAME_COND,
575 copies::IF_SAME_THEN_ELSE,
576 cyclomatic_complexity::CYCLOMATIC_COMPLEXITY,
577 derive::DERIVE_HASH_XOR_EQ,
578 double_comparison::DOUBLE_COMPARISONS,
579 double_parens::DOUBLE_PARENS,
580 drop_forget_ref::DROP_COPY,
581 drop_forget_ref::DROP_REF,
582 drop_forget_ref::FORGET_COPY,
583 drop_forget_ref::FORGET_REF,
584 duration_subsec::DURATION_SUBSEC,
586 enum_clike::ENUM_CLIKE_UNPORTABLE_VARIANT,
587 enum_variants::ENUM_VARIANT_NAMES,
588 enum_variants::MODULE_INCEPTION,
591 erasing_op::ERASING_OP,
593 eta_reduction::REDUNDANT_CLOSURE,
594 eval_order_dependence::DIVERGING_SUB_EXPRESSION,
595 eval_order_dependence::EVAL_ORDER_DEPENDENCE,
596 excessive_precision::EXCESSIVE_PRECISION,
597 explicit_write::EXPLICIT_WRITE,
598 format::USELESS_FORMAT,
599 formatting::POSSIBLE_MISSING_COMMA,
600 formatting::SUSPICIOUS_ASSIGNMENT_FORMATTING,
601 formatting::SUSPICIOUS_ELSE_FORMATTING,
602 functions::NOT_UNSAFE_PTR_ARG_DEREF,
603 functions::TOO_MANY_ARGUMENTS,
604 identity_conversion::IDENTITY_CONVERSION,
605 identity_op::IDENTITY_OP,
606 indexing_slicing::OUT_OF_BOUNDS_INDEXING,
607 infallible_destructuring_match::INFALLIBLE_DESTRUCTURING_MATCH,
608 infinite_iter::INFINITE_ITER,
609 inline_fn_without_body::INLINE_FN_WITHOUT_BODY,
610 int_plus_one::INT_PLUS_ONE,
611 invalid_ref::INVALID_REF,
612 large_enum_variant::LARGE_ENUM_VARIANT,
613 len_zero::LEN_WITHOUT_IS_EMPTY,
615 let_if_seq::USELESS_LET_IF_SEQ,
616 lifetimes::EXTRA_UNUSED_LIFETIMES,
617 lifetimes::NEEDLESS_LIFETIMES,
618 literal_representation::INCONSISTENT_DIGIT_GROUPING,
619 literal_representation::MISTYPED_LITERAL_SUFFIXES,
620 literal_representation::UNREADABLE_LITERAL,
622 loops::EXPLICIT_COUNTER_LOOP,
624 loops::FOR_LOOP_OVER_OPTION,
625 loops::FOR_LOOP_OVER_RESULT,
626 loops::ITER_NEXT_LOOP,
627 loops::MANUAL_MEMCPY,
628 loops::MUT_RANGE_BOUND,
629 loops::NEEDLESS_COLLECT,
630 loops::NEEDLESS_RANGE_LOOP,
632 loops::REVERSE_RANGE_LOOP,
633 loops::UNUSED_COLLECT,
634 loops::WHILE_IMMUTABLE_CONDITION,
635 loops::WHILE_LET_LOOP,
636 loops::WHILE_LET_ON_ITERATOR,
637 map_clone::MAP_CLONE,
638 map_unit_fn::OPTION_MAP_UNIT_FN,
639 map_unit_fn::RESULT_MAP_UNIT_FN,
640 matches::MATCH_AS_REF,
642 matches::MATCH_OVERLAPPING_ARM,
643 matches::MATCH_REF_PATS,
644 matches::MATCH_WILD_ERR_ARM,
645 matches::SINGLE_MATCH,
646 mem_discriminant::MEM_DISCRIMINANT_NON_ENUM,
647 mem_replace::MEM_REPLACE_OPTION_WITH_NONE,
648 methods::CHARS_LAST_CMP,
649 methods::CHARS_NEXT_CMP,
650 methods::CLONE_DOUBLE_REF,
651 methods::CLONE_ON_COPY,
652 methods::EXPECT_FUN_CALL,
653 methods::FILTER_NEXT,
655 methods::INTO_ITER_ON_ARRAY,
656 methods::INTO_ITER_ON_REF,
657 methods::ITER_CLONED_COLLECT,
659 methods::ITER_SKIP_NEXT,
660 methods::NEW_RET_NO_SELF,
662 methods::OPTION_MAP_OR_NONE,
663 methods::OR_FUN_CALL,
664 methods::SEARCH_IS_SOME,
665 methods::SHOULD_IMPLEMENT_TRAIT,
666 methods::SINGLE_CHAR_PATTERN,
667 methods::STRING_EXTEND_CHARS,
668 methods::TEMPORARY_CSTRING_AS_PTR,
669 methods::UNNECESSARY_FILTER_MAP,
670 methods::UNNECESSARY_FOLD,
671 methods::USELESS_ASREF,
672 methods::WRONG_SELF_CONVENTION,
678 misc::REDUNDANT_PATTERN,
679 misc::SHORT_CIRCUIT_STATEMENT,
680 misc::TOPLEVEL_REF_ARG,
682 misc_early::BUILTIN_TYPE_SHADOW,
683 misc_early::DOUBLE_NEG,
684 misc_early::DUPLICATE_UNDERSCORE_ARGUMENT,
685 misc_early::MIXED_CASE_HEX_LITERALS,
686 misc_early::REDUNDANT_CLOSURE_CALL,
687 misc_early::UNNEEDED_FIELD_PATTERN,
688 misc_early::ZERO_PREFIXED_LITERAL,
689 mut_reference::UNNECESSARY_MUT_PASSED,
690 mutex_atomic::MUTEX_ATOMIC,
691 needless_bool::BOOL_COMPARISON,
692 needless_bool::NEEDLESS_BOOL,
693 needless_borrowed_ref::NEEDLESS_BORROWED_REFERENCE,
694 needless_update::NEEDLESS_UPDATE,
695 neg_cmp_op_on_partial_ord::NEG_CMP_OP_ON_PARTIAL_ORD,
696 neg_multiply::NEG_MULTIPLY,
697 new_without_default::NEW_WITHOUT_DEFAULT,
698 no_effect::NO_EFFECT,
699 no_effect::UNNECESSARY_OPERATION,
700 non_copy_const::BORROW_INTERIOR_MUTABLE_CONST,
701 non_copy_const::DECLARE_INTERIOR_MUTABLE_CONST,
702 non_expressive_names::JUST_UNDERSCORES_AND_DIGITS,
703 non_expressive_names::MANY_SINGLE_CHAR_NAMES,
704 ok_if_let::IF_LET_SOME_RESULT,
705 open_options::NONSENSICAL_OPEN_OPTIONS,
706 overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL,
707 panic_unimplemented::PANIC_PARAMS,
708 partialeq_ne_impl::PARTIALEQ_NE_IMPL,
709 precedence::PRECEDENCE,
713 ptr_offset_with_cast::PTR_OFFSET_WITH_CAST,
714 question_mark::QUESTION_MARK,
715 ranges::ITERATOR_STEP_BY_ZERO,
716 ranges::RANGE_MINUS_ONE,
717 ranges::RANGE_PLUS_ONE,
718 ranges::RANGE_ZIP_WITH_LEN,
719 redundant_field_names::REDUNDANT_FIELD_NAMES,
720 redundant_pattern_matching::REDUNDANT_PATTERN_MATCHING,
721 reference::DEREF_ADDROF,
722 reference::REF_IN_DEREF,
723 regex::INVALID_REGEX,
725 regex::TRIVIAL_REGEX,
726 returns::LET_AND_RETURN,
727 returns::NEEDLESS_RETURN,
728 returns::UNUSED_UNIT,
729 serde_api::SERDE_API_MISUSE,
730 slow_vector_initialization::SLOW_VECTOR_INITIALIZATION,
731 strings::STRING_LIT_AS_BYTES,
732 suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL,
733 suspicious_trait_impl::SUSPICIOUS_OP_ASSIGN_IMPL,
734 swap::ALMOST_SWAPPED,
736 temporary_assignment::TEMPORARY_ASSIGNMENT,
737 transmute::CROSSPOINTER_TRANSMUTE,
738 transmute::TRANSMUTE_BYTES_TO_STR,
739 transmute::TRANSMUTE_INT_TO_BOOL,
740 transmute::TRANSMUTE_INT_TO_CHAR,
741 transmute::TRANSMUTE_INT_TO_FLOAT,
742 transmute::TRANSMUTE_PTR_TO_PTR,
743 transmute::TRANSMUTE_PTR_TO_REF,
744 transmute::USELESS_TRANSMUTE,
745 transmute::WRONG_TRANSMUTE,
746 trivially_copy_pass_by_ref::TRIVIALLY_COPY_PASS_BY_REF,
747 types::ABSURD_EXTREME_COMPARISONS,
750 types::CAST_LOSSLESS,
751 types::CAST_PTR_ALIGNMENT,
752 types::CAST_REF_TO_MUT,
753 types::CHAR_LIT_AS_U8,
754 types::FN_TO_NUMERIC_CAST,
755 types::FN_TO_NUMERIC_CAST_WITH_TRUNCATION,
756 types::IMPLICIT_HASHER,
757 types::LET_UNIT_VALUE,
758 types::OPTION_OPTION,
759 types::TYPE_COMPLEXITY,
762 types::UNNECESSARY_CAST,
764 unicode::ZERO_WIDTH_SPACE,
765 unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME,
766 unused_io_amount::UNUSED_IO_AMOUNT,
767 unused_label::UNUSED_LABEL,
769 write::PRINTLN_EMPTY_STRING,
770 write::PRINT_LITERAL,
771 write::PRINT_WITH_NEWLINE,
772 write::WRITELN_EMPTY_STRING,
773 write::WRITE_LITERAL,
774 write::WRITE_WITH_NEWLINE,
775 zero_div_zero::ZERO_DIVIDED_BY_ZERO,
778 reg.register_lint_group("clippy::style", Some("clippy_style"), vec![
779 assign_ops::ASSIGN_OP_PATTERN,
780 attrs::UNKNOWN_CLIPPY_LINTS,
781 bit_mask::VERBOSE_BIT_MASK,
782 blacklisted_name::BLACKLISTED_NAME,
783 block_in_if_condition::BLOCK_IN_IF_CONDITION_EXPR,
784 block_in_if_condition::BLOCK_IN_IF_CONDITION_STMT,
785 collapsible_if::COLLAPSIBLE_IF,
786 const_static_lifetime::CONST_STATIC_LIFETIME,
787 enum_variants::ENUM_VARIANT_NAMES,
788 enum_variants::MODULE_INCEPTION,
790 eta_reduction::REDUNDANT_CLOSURE,
791 excessive_precision::EXCESSIVE_PRECISION,
792 formatting::SUSPICIOUS_ASSIGNMENT_FORMATTING,
793 formatting::SUSPICIOUS_ELSE_FORMATTING,
794 infallible_destructuring_match::INFALLIBLE_DESTRUCTURING_MATCH,
795 len_zero::LEN_WITHOUT_IS_EMPTY,
797 let_if_seq::USELESS_LET_IF_SEQ,
798 literal_representation::INCONSISTENT_DIGIT_GROUPING,
799 literal_representation::UNREADABLE_LITERAL,
802 loops::NEEDLESS_RANGE_LOOP,
803 loops::WHILE_LET_ON_ITERATOR,
804 map_clone::MAP_CLONE,
806 matches::MATCH_OVERLAPPING_ARM,
807 matches::MATCH_REF_PATS,
808 matches::MATCH_WILD_ERR_ARM,
809 matches::SINGLE_MATCH,
810 mem_replace::MEM_REPLACE_OPTION_WITH_NONE,
811 methods::CHARS_LAST_CMP,
813 methods::INTO_ITER_ON_REF,
814 methods::ITER_CLONED_COLLECT,
815 methods::ITER_SKIP_NEXT,
816 methods::NEW_RET_NO_SELF,
818 methods::OPTION_MAP_OR_NONE,
819 methods::SHOULD_IMPLEMENT_TRAIT,
820 methods::STRING_EXTEND_CHARS,
821 methods::UNNECESSARY_FOLD,
822 methods::WRONG_SELF_CONVENTION,
823 misc::REDUNDANT_PATTERN,
824 misc::TOPLEVEL_REF_ARG,
826 misc_early::BUILTIN_TYPE_SHADOW,
827 misc_early::DOUBLE_NEG,
828 misc_early::DUPLICATE_UNDERSCORE_ARGUMENT,
829 misc_early::MIXED_CASE_HEX_LITERALS,
830 misc_early::UNNEEDED_FIELD_PATTERN,
831 mut_reference::UNNECESSARY_MUT_PASSED,
832 neg_multiply::NEG_MULTIPLY,
833 new_without_default::NEW_WITHOUT_DEFAULT,
834 non_expressive_names::JUST_UNDERSCORES_AND_DIGITS,
835 non_expressive_names::MANY_SINGLE_CHAR_NAMES,
836 ok_if_let::IF_LET_SOME_RESULT,
837 panic_unimplemented::PANIC_PARAMS,
840 question_mark::QUESTION_MARK,
841 redundant_field_names::REDUNDANT_FIELD_NAMES,
842 redundant_pattern_matching::REDUNDANT_PATTERN_MATCHING,
844 regex::TRIVIAL_REGEX,
845 returns::LET_AND_RETURN,
846 returns::NEEDLESS_RETURN,
847 returns::UNUSED_UNIT,
848 strings::STRING_LIT_AS_BYTES,
849 types::FN_TO_NUMERIC_CAST,
850 types::FN_TO_NUMERIC_CAST_WITH_TRUNCATION,
851 types::IMPLICIT_HASHER,
852 types::LET_UNIT_VALUE,
853 unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME,
854 write::PRINTLN_EMPTY_STRING,
855 write::PRINT_LITERAL,
856 write::PRINT_WITH_NEWLINE,
857 write::WRITELN_EMPTY_STRING,
858 write::WRITE_LITERAL,
859 write::WRITE_WITH_NEWLINE,
862 reg.register_lint_group("clippy::complexity", Some("clippy_complexity"), vec![
863 assign_ops::MISREFACTORED_ASSIGN_OP,
864 attrs::DEPRECATED_CFG_ATTR,
865 booleans::NONMINIMAL_BOOL,
866 cyclomatic_complexity::CYCLOMATIC_COMPLEXITY,
867 double_comparison::DOUBLE_COMPARISONS,
868 double_parens::DOUBLE_PARENS,
869 duration_subsec::DURATION_SUBSEC,
870 eval_order_dependence::DIVERGING_SUB_EXPRESSION,
871 eval_order_dependence::EVAL_ORDER_DEPENDENCE,
872 explicit_write::EXPLICIT_WRITE,
873 format::USELESS_FORMAT,
874 functions::TOO_MANY_ARGUMENTS,
875 identity_conversion::IDENTITY_CONVERSION,
876 identity_op::IDENTITY_OP,
877 int_plus_one::INT_PLUS_ONE,
878 lifetimes::EXTRA_UNUSED_LIFETIMES,
879 lifetimes::NEEDLESS_LIFETIMES,
880 loops::EXPLICIT_COUNTER_LOOP,
881 loops::MUT_RANGE_BOUND,
882 loops::WHILE_LET_LOOP,
883 map_unit_fn::OPTION_MAP_UNIT_FN,
884 map_unit_fn::RESULT_MAP_UNIT_FN,
885 matches::MATCH_AS_REF,
886 methods::CHARS_NEXT_CMP,
887 methods::CLONE_ON_COPY,
888 methods::FILTER_NEXT,
889 methods::SEARCH_IS_SOME,
890 methods::UNNECESSARY_FILTER_MAP,
891 methods::USELESS_ASREF,
892 misc::SHORT_CIRCUIT_STATEMENT,
893 misc_early::REDUNDANT_CLOSURE_CALL,
894 misc_early::ZERO_PREFIXED_LITERAL,
895 needless_bool::BOOL_COMPARISON,
896 needless_bool::NEEDLESS_BOOL,
897 needless_borrowed_ref::NEEDLESS_BORROWED_REFERENCE,
898 needless_update::NEEDLESS_UPDATE,
899 neg_cmp_op_on_partial_ord::NEG_CMP_OP_ON_PARTIAL_ORD,
900 no_effect::NO_EFFECT,
901 no_effect::UNNECESSARY_OPERATION,
902 overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL,
903 partialeq_ne_impl::PARTIALEQ_NE_IMPL,
904 precedence::PRECEDENCE,
905 ptr_offset_with_cast::PTR_OFFSET_WITH_CAST,
906 ranges::RANGE_MINUS_ONE,
907 ranges::RANGE_PLUS_ONE,
908 ranges::RANGE_ZIP_WITH_LEN,
909 reference::DEREF_ADDROF,
910 reference::REF_IN_DEREF,
912 temporary_assignment::TEMPORARY_ASSIGNMENT,
913 transmute::CROSSPOINTER_TRANSMUTE,
914 transmute::TRANSMUTE_BYTES_TO_STR,
915 transmute::TRANSMUTE_INT_TO_BOOL,
916 transmute::TRANSMUTE_INT_TO_CHAR,
917 transmute::TRANSMUTE_INT_TO_FLOAT,
918 transmute::TRANSMUTE_PTR_TO_PTR,
919 transmute::TRANSMUTE_PTR_TO_REF,
920 transmute::USELESS_TRANSMUTE,
922 types::CAST_LOSSLESS,
923 types::CHAR_LIT_AS_U8,
924 types::OPTION_OPTION,
925 types::TYPE_COMPLEXITY,
927 types::UNNECESSARY_CAST,
929 unused_label::UNUSED_LABEL,
930 zero_div_zero::ZERO_DIVIDED_BY_ZERO,
933 reg.register_lint_group("clippy::correctness", Some("clippy_correctness"), vec![
934 approx_const::APPROX_CONSTANT,
935 attrs::DEPRECATED_SEMVER,
936 attrs::USELESS_ATTRIBUTE,
937 bit_mask::BAD_BIT_MASK,
938 bit_mask::INEFFECTIVE_BIT_MASK,
940 copies::IFS_SAME_COND,
941 copies::IF_SAME_THEN_ELSE,
942 derive::DERIVE_HASH_XOR_EQ,
943 drop_forget_ref::DROP_COPY,
944 drop_forget_ref::DROP_REF,
945 drop_forget_ref::FORGET_COPY,
946 drop_forget_ref::FORGET_REF,
947 enum_clike::ENUM_CLIKE_UNPORTABLE_VARIANT,
949 erasing_op::ERASING_OP,
950 formatting::POSSIBLE_MISSING_COMMA,
951 functions::NOT_UNSAFE_PTR_ARG_DEREF,
952 indexing_slicing::OUT_OF_BOUNDS_INDEXING,
953 infinite_iter::INFINITE_ITER,
954 inline_fn_without_body::INLINE_FN_WITHOUT_BODY,
955 invalid_ref::INVALID_REF,
956 literal_representation::MISTYPED_LITERAL_SUFFIXES,
957 loops::FOR_LOOP_OVER_OPTION,
958 loops::FOR_LOOP_OVER_RESULT,
959 loops::ITER_NEXT_LOOP,
961 loops::REVERSE_RANGE_LOOP,
962 loops::WHILE_IMMUTABLE_CONDITION,
963 mem_discriminant::MEM_DISCRIMINANT_NON_ENUM,
964 methods::CLONE_DOUBLE_REF,
965 methods::INTO_ITER_ON_ARRAY,
966 methods::TEMPORARY_CSTRING_AS_PTR,
971 non_copy_const::BORROW_INTERIOR_MUTABLE_CONST,
972 non_copy_const::DECLARE_INTERIOR_MUTABLE_CONST,
973 open_options::NONSENSICAL_OPEN_OPTIONS,
975 ranges::ITERATOR_STEP_BY_ZERO,
976 regex::INVALID_REGEX,
977 serde_api::SERDE_API_MISUSE,
978 suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL,
979 suspicious_trait_impl::SUSPICIOUS_OP_ASSIGN_IMPL,
980 swap::ALMOST_SWAPPED,
981 transmute::WRONG_TRANSMUTE,
982 types::ABSURD_EXTREME_COMPARISONS,
983 types::CAST_PTR_ALIGNMENT,
984 types::CAST_REF_TO_MUT,
986 unicode::ZERO_WIDTH_SPACE,
987 unused_io_amount::UNUSED_IO_AMOUNT,
990 reg.register_lint_group("clippy::perf", Some("clippy_perf"), vec![
991 bytecount::NAIVE_BYTECOUNT,
994 large_enum_variant::LARGE_ENUM_VARIANT,
995 loops::MANUAL_MEMCPY,
996 loops::NEEDLESS_COLLECT,
997 loops::UNUSED_COLLECT,
998 methods::EXPECT_FUN_CALL,
1000 methods::OR_FUN_CALL,
1001 methods::SINGLE_CHAR_PATTERN,
1003 mutex_atomic::MUTEX_ATOMIC,
1004 slow_vector_initialization::SLOW_VECTOR_INITIALIZATION,
1005 trivially_copy_pass_by_ref::TRIVIALLY_COPY_PASS_BY_REF,
1010 reg.register_lint_group("clippy::cargo", Some("clippy_cargo"), vec![
1011 cargo_common_metadata::CARGO_COMMON_METADATA,
1012 multiple_crate_versions::MULTIPLE_CRATE_VERSIONS,
1013 wildcard_dependencies::WILDCARD_DEPENDENCIES,
1016 reg.register_lint_group("clippy::nursery", Some("clippy_nursery"), vec![
1017 attrs::EMPTY_LINE_AFTER_OUTER_ATTR,
1018 fallible_impl_from::FALLIBLE_IMPL_FROM,
1019 mutex_atomic::MUTEX_INTEGER,
1020 needless_borrow::NEEDLESS_BORROW,
1021 redundant_clone::REDUNDANT_CLONE,
1022 unwrap::PANICKING_UNWRAP,
1023 unwrap::UNNECESSARY_UNWRAP,
1027 pub fn register_renamed(ls: &mut rustc::lint::LintStore) {
1028 ls.register_renamed("clippy::stutter", "clippy::module_name_repetitions");
1029 ls.register_renamed("clippy::new_without_default_derive", "clippy::new_without_default");
1032 // only exists to let the dogfood integration test works.
1033 // Don't run clippy as an executable directly
1036 panic!("Please use the cargo-clippy executable");