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_mir;
27 #[allow(unused_extern_crates)]
28 extern crate rustc_plugin;
29 #[allow(unused_extern_crates)]
30 extern crate rustc_target;
31 #[allow(unused_extern_crates)]
32 extern crate rustc_typeck;
33 #[allow(unused_extern_crates)]
35 #[allow(unused_extern_crates)]
36 extern crate syntax_pos;
40 // Currently, categories "style", "correctness", "complexity" and "perf" are enabled by default,
41 // as said in the README.md of this repository. If this changes, please update README.md.
43 macro_rules! declare_clippy_lint {
44 { pub $name:tt, style, $description:tt } => {
45 declare_tool_lint! { pub clippy::$name, Warn, $description, report_in_external_macro: true }
47 { pub $name:tt, correctness, $description:tt } => {
48 declare_tool_lint! { pub clippy::$name, Deny, $description, report_in_external_macro: true }
50 { pub $name:tt, complexity, $description:tt } => {
51 declare_tool_lint! { pub clippy::$name, Warn, $description, report_in_external_macro: true }
53 { pub $name:tt, perf, $description:tt } => {
54 declare_tool_lint! { pub clippy::$name, Warn, $description, report_in_external_macro: true }
56 { pub $name:tt, pedantic, $description:tt } => {
57 declare_tool_lint! { pub clippy::$name, Allow, $description, report_in_external_macro: true }
59 { pub $name:tt, restriction, $description:tt } => {
60 declare_tool_lint! { pub clippy::$name, Allow, $description, report_in_external_macro: true }
62 { pub $name:tt, cargo, $description:tt } => {
63 declare_tool_lint! { pub clippy::$name, Allow, $description, report_in_external_macro: true }
65 { pub $name:tt, nursery, $description:tt } => {
66 declare_tool_lint! { pub clippy::$name, Allow, $description, report_in_external_macro: true }
68 { pub $name:tt, internal, $description:tt } => {
69 declare_tool_lint! { pub clippy::$name, Allow, $description, report_in_external_macro: true }
71 { pub $name:tt, internal_warn, $description:tt } => {
72 declare_tool_lint! { pub clippy::$name, Warn, $description, report_in_external_macro: true }
80 // begin lints modules, do not remove this comment, it’s used in `update_lints`
83 pub mod assertions_on_constants;
87 pub mod blacklisted_name;
88 pub mod block_in_if_condition;
91 pub mod cargo_common_metadata;
92 pub mod collapsible_if;
93 pub mod const_static_lifetime;
95 pub mod copy_iterator;
96 pub mod cyclomatic_complexity;
97 pub mod default_trait_access;
100 pub mod double_comparison;
101 pub mod double_parens;
102 pub mod drop_forget_ref;
103 pub mod duration_subsec;
104 pub mod else_if_without_else;
108 pub mod enum_glob_use;
109 pub mod enum_variants;
113 pub mod eta_reduction;
114 pub mod eval_order_dependence;
115 pub mod excessive_precision;
116 pub mod explicit_write;
117 pub mod fallible_impl_from;
121 pub mod identity_conversion;
124 pub mod implicit_return;
125 pub mod indexing_slicing;
126 pub mod infallible_destructuring_match;
127 pub mod infinite_iter;
128 pub mod inherent_impl;
129 pub mod inline_fn_without_body;
130 pub mod int_plus_one;
132 pub mod items_after_statements;
133 pub mod large_enum_variant;
137 pub mod literal_representation;
142 pub mod mem_discriminant;
149 pub mod missing_const_for_fn;
151 pub mod missing_inline;
152 pub mod multiple_crate_versions;
154 pub mod mut_reference;
155 pub mod mutex_atomic;
156 pub mod needless_bool;
157 pub mod needless_borrow;
158 pub mod needless_borrowed_ref;
159 pub mod needless_continue;
160 pub mod needless_pass_by_value;
161 pub mod needless_update;
162 pub mod neg_cmp_op_on_partial_ord;
163 pub mod neg_multiply;
164 pub mod new_without_default;
166 pub mod non_copy_const;
167 pub mod non_expressive_names;
169 pub mod open_options;
170 pub mod overflow_check_conditional;
171 pub mod panic_unimplemented;
172 pub mod partialeq_ne_impl;
175 pub mod ptr_offset_with_cast;
176 pub mod question_mark;
178 pub mod redundant_clone;
179 pub mod redundant_field_names;
180 pub mod redundant_pattern_matching;
183 pub mod replace_consts;
187 pub mod slow_vector_initialization;
189 pub mod suspicious_trait_impl;
191 pub mod temporary_assignment;
193 pub mod trivially_copy_pass_by_ref;
196 pub mod unsafe_removed_from_name;
197 pub mod unused_io_amount;
198 pub mod unused_label;
202 pub mod wildcard_dependencies;
204 pub mod zero_div_zero;
205 // end lints modules, do not remove this comment, it’s used in `update_lints`
207 pub use crate::utils::conf::Conf;
210 crate use syntax::ast::{Name, NodeId};
213 pub fn register_pre_expansion_lints(
214 session: &rustc::session::Session,
215 store: &mut rustc::lint::LintStore,
218 store.register_pre_expansion_pass(Some(session), true, false, box write::Pass);
219 store.register_pre_expansion_pass(
223 box redundant_field_names::RedundantFieldNames,
225 store.register_pre_expansion_pass(
229 box non_expressive_names::NonExpressiveNames {
230 single_char_binding_names_threshold: conf.single_char_binding_names_threshold,
233 store.register_pre_expansion_pass(Some(session), true, false, box attrs::CfgAttrPass);
236 pub fn read_conf(reg: &rustc_plugin::Registry<'_>) -> Conf {
237 match utils::conf::file_from_args(reg.args()) {
239 // if the user specified a file, it must exist, otherwise default to `clippy.toml` but
240 // do not require the file to exist
241 let file_name = if let Some(file_name) = file_name {
244 match utils::conf::lookup_conf_file() {
248 .struct_err(&format!("error finding Clippy's configuration file: {}", error))
255 let file_name = file_name.map(|file_name| {
256 if file_name.is_relative() {
258 .local_crate_source_file
260 .and_then(|file| std::path::Path::new(&file).parent().map(std::path::Path::to_path_buf))
268 let (conf, errors) = utils::conf::read(file_name.as_ref().map(|p| p.as_ref()));
270 // all conf errors are non-fatal, we just use the default conf in case of error
271 for error in errors {
273 .struct_err(&format!(
274 "error reading Clippy's configuration file `{}`: {}",
275 file_name.as_ref().and_then(|p| p.to_str()).unwrap_or(""),
283 Err((err, span)) => {
285 .struct_span_err(span, err)
286 .span_note(span, "Clippy will use default configuration")
288 toml::from_str("").expect("we never error on empty config files")
294 pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
295 let mut store = reg.sess.lint_store.borrow_mut();
296 // begin deprecated lints, do not remove this comment, it’s used in `update_lints`
297 store.register_removed(
299 "`assert!()` will be more flexible with RFC 2011",
301 store.register_removed(
303 "`.extend_from_slice(_)` is a faster way to extend a Vec by a slice",
305 store.register_removed(
306 "range_step_by_zero",
307 "`iterator.step_by(0)` panics nowadays",
309 store.register_removed(
311 "`Vec::as_slice` has been stabilized in 1.7",
313 store.register_removed(
314 "unstable_as_mut_slice",
315 "`Vec::as_mut_slice` has been stabilized in 1.7",
317 store.register_removed(
319 "using `str::to_string` is common even today and specialization will likely happen soon",
321 store.register_removed(
323 "using `string::to_string` is common even today and specialization will likely happen soon",
325 store.register_removed(
326 "misaligned_transmute",
327 "this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr",
329 store.register_removed(
331 "using compound assignment operators (e.g. `+=`) is harmless",
333 store.register_removed(
334 "if_let_redundant_pattern_matching",
335 "this lint has been changed to redundant_pattern_matching",
337 store.register_removed(
338 "unsafe_vector_initialization",
339 "the replacement suggested by this lint had substantially different behavior",
341 // end deprecated lints, do not remove this comment, it’s used in `update_lints`
343 reg.register_late_lint_pass(box serde_api::Serde);
344 reg.register_early_lint_pass(box utils::internal_lints::Clippy);
345 reg.register_late_lint_pass(box utils::internal_lints::CompilerLintFunctions::new());
346 reg.register_early_lint_pass(box utils::internal_lints::DefaultHashTypes::default());
347 reg.register_late_lint_pass(box utils::internal_lints::LintWithoutLintPass::default());
348 reg.register_late_lint_pass(box utils::inspector::Pass);
349 reg.register_late_lint_pass(box utils::author::Pass);
350 reg.register_late_lint_pass(box types::TypePass);
351 reg.register_late_lint_pass(box booleans::NonminimalBool);
352 reg.register_late_lint_pass(box eq_op::EqOp);
353 reg.register_early_lint_pass(box enum_variants::EnumVariantNames::new(conf.enum_variant_name_threshold));
354 reg.register_late_lint_pass(box enum_glob_use::EnumGlobUse);
355 reg.register_late_lint_pass(box enum_clike::UnportableVariant);
356 reg.register_late_lint_pass(box excessive_precision::ExcessivePrecision);
357 reg.register_late_lint_pass(box bit_mask::BitMask::new(conf.verbose_bit_mask_threshold));
358 reg.register_late_lint_pass(box ptr::PointerPass);
359 reg.register_late_lint_pass(box needless_bool::NeedlessBool);
360 reg.register_late_lint_pass(box needless_bool::BoolComparison);
361 reg.register_late_lint_pass(box approx_const::Pass);
362 reg.register_late_lint_pass(box misc::Pass);
363 reg.register_early_lint_pass(box precedence::Precedence);
364 reg.register_early_lint_pass(box needless_continue::NeedlessContinue);
365 reg.register_late_lint_pass(box eta_reduction::EtaPass);
366 reg.register_late_lint_pass(box identity_op::IdentityOp);
367 reg.register_late_lint_pass(box erasing_op::ErasingOp);
368 reg.register_early_lint_pass(box items_after_statements::ItemsAfterStatements);
369 reg.register_late_lint_pass(box mut_mut::MutMut);
370 reg.register_late_lint_pass(box mut_reference::UnnecessaryMutPassed);
371 reg.register_late_lint_pass(box len_zero::LenZero);
372 reg.register_late_lint_pass(box attrs::AttrPass);
373 reg.register_early_lint_pass(box collapsible_if::CollapsibleIf);
374 reg.register_late_lint_pass(box block_in_if_condition::BlockInIfCondition);
375 reg.register_late_lint_pass(box unicode::Unicode);
376 reg.register_late_lint_pass(box strings::StringAdd);
377 reg.register_early_lint_pass(box returns::ReturnPass);
378 reg.register_late_lint_pass(box implicit_return::Pass);
379 reg.register_late_lint_pass(box methods::Pass);
380 reg.register_late_lint_pass(box map_clone::Pass);
381 reg.register_late_lint_pass(box shadow::Pass);
382 reg.register_late_lint_pass(box types::LetPass);
383 reg.register_late_lint_pass(box types::UnitCmp);
384 reg.register_late_lint_pass(box loops::Pass);
385 reg.register_late_lint_pass(box lifetimes::LifetimePass);
386 reg.register_late_lint_pass(box entry::HashMapLint);
387 reg.register_late_lint_pass(box ranges::Pass);
388 reg.register_late_lint_pass(box types::CastPass);
389 reg.register_late_lint_pass(box types::TypeComplexityPass::new(conf.type_complexity_threshold));
390 reg.register_late_lint_pass(box matches::MatchPass);
391 reg.register_late_lint_pass(box minmax::MinMaxPass);
392 reg.register_late_lint_pass(box open_options::NonSensical);
393 reg.register_late_lint_pass(box zero_div_zero::Pass);
394 reg.register_late_lint_pass(box mutex_atomic::MutexAtomic);
395 reg.register_late_lint_pass(box needless_update::Pass);
396 reg.register_late_lint_pass(box needless_borrow::NeedlessBorrow::default());
397 reg.register_late_lint_pass(box needless_borrowed_ref::NeedlessBorrowedRef);
398 reg.register_late_lint_pass(box no_effect::Pass);
399 reg.register_late_lint_pass(box temporary_assignment::Pass);
400 reg.register_late_lint_pass(box transmute::Transmute);
401 reg.register_late_lint_pass(
402 box cyclomatic_complexity::CyclomaticComplexity::new(conf.cyclomatic_complexity_threshold)
404 reg.register_late_lint_pass(box escape::Pass{too_large_for_stack: conf.too_large_for_stack});
405 reg.register_early_lint_pass(box misc_early::MiscEarly);
406 reg.register_late_lint_pass(box panic_unimplemented::Pass);
407 reg.register_late_lint_pass(box strings::StringLitAsBytes);
408 reg.register_late_lint_pass(box derive::Derive);
409 reg.register_late_lint_pass(box types::CharLitAsU8);
410 reg.register_late_lint_pass(box vec::Pass);
411 reg.register_late_lint_pass(box drop_forget_ref::Pass);
412 reg.register_late_lint_pass(box empty_enum::EmptyEnum);
413 reg.register_late_lint_pass(box types::AbsurdExtremeComparisons);
414 reg.register_late_lint_pass(box types::InvalidUpcastComparisons);
415 reg.register_late_lint_pass(box regex::Pass::default());
416 reg.register_late_lint_pass(box copies::CopyAndPaste);
417 reg.register_late_lint_pass(box copy_iterator::CopyIterator);
418 reg.register_late_lint_pass(box format::Pass);
419 reg.register_early_lint_pass(box formatting::Formatting);
420 reg.register_late_lint_pass(box swap::Swap);
421 reg.register_early_lint_pass(box if_not_else::IfNotElse);
422 reg.register_early_lint_pass(box else_if_without_else::ElseIfWithoutElse);
423 reg.register_early_lint_pass(box int_plus_one::IntPlusOne);
424 reg.register_late_lint_pass(box overflow_check_conditional::OverflowCheckConditional);
425 reg.register_late_lint_pass(box unused_label::UnusedLabel);
426 reg.register_late_lint_pass(box new_without_default::NewWithoutDefault::default());
427 reg.register_late_lint_pass(box blacklisted_name::BlackListedName::new(
428 conf.blacklisted_names.iter().cloned().collect()
430 reg.register_late_lint_pass(box functions::Functions::new(conf.too_many_arguments_threshold));
431 reg.register_early_lint_pass(box doc::Doc::new(conf.doc_valid_idents.iter().cloned().collect()));
432 reg.register_late_lint_pass(box neg_multiply::NegMultiply);
433 reg.register_early_lint_pass(box unsafe_removed_from_name::UnsafeNameRemoval);
434 reg.register_late_lint_pass(box mem_discriminant::MemDiscriminant);
435 reg.register_late_lint_pass(box mem_forget::MemForget);
436 reg.register_late_lint_pass(box mem_replace::MemReplace);
437 reg.register_late_lint_pass(box arithmetic::Arithmetic::default());
438 reg.register_late_lint_pass(box assign_ops::AssignOps);
439 reg.register_late_lint_pass(box let_if_seq::LetIfSeq);
440 reg.register_late_lint_pass(box eval_order_dependence::EvalOrderDependence);
441 reg.register_late_lint_pass(box missing_doc::MissingDoc::new());
442 reg.register_late_lint_pass(box missing_inline::MissingInline);
443 reg.register_late_lint_pass(box ok_if_let::Pass);
444 reg.register_late_lint_pass(box redundant_pattern_matching::Pass);
445 reg.register_late_lint_pass(box partialeq_ne_impl::Pass);
446 reg.register_early_lint_pass(box reference::Pass);
447 reg.register_early_lint_pass(box reference::DerefPass);
448 reg.register_early_lint_pass(box double_parens::DoubleParens);
449 reg.register_late_lint_pass(box unused_io_amount::UnusedIoAmount);
450 reg.register_late_lint_pass(box large_enum_variant::LargeEnumVariant::new(conf.enum_variant_size_threshold));
451 reg.register_late_lint_pass(box explicit_write::Pass);
452 reg.register_late_lint_pass(box needless_pass_by_value::NeedlessPassByValue);
453 reg.register_late_lint_pass(box trivially_copy_pass_by_ref::TriviallyCopyPassByRef::new(
454 conf.trivial_copy_size_limit,
457 reg.register_early_lint_pass(box literal_representation::LiteralDigitGrouping);
458 reg.register_early_lint_pass(box literal_representation::LiteralRepresentation::new(
459 conf.literal_representation_threshold
461 reg.register_late_lint_pass(box use_self::UseSelf);
462 reg.register_late_lint_pass(box bytecount::ByteCount);
463 reg.register_late_lint_pass(box infinite_iter::Pass);
464 reg.register_late_lint_pass(box inline_fn_without_body::Pass);
465 reg.register_late_lint_pass(box invalid_ref::InvalidRef);
466 reg.register_late_lint_pass(box identity_conversion::IdentityConversion::default());
467 reg.register_late_lint_pass(box types::ImplicitHasher);
468 reg.register_early_lint_pass(box const_static_lifetime::StaticConst);
469 reg.register_late_lint_pass(box fallible_impl_from::FallibleImplFrom);
470 reg.register_late_lint_pass(box replace_consts::ReplaceConsts);
471 reg.register_late_lint_pass(box types::UnitArg);
472 reg.register_late_lint_pass(box double_comparison::Pass);
473 reg.register_late_lint_pass(box question_mark::Pass);
474 reg.register_late_lint_pass(box suspicious_trait_impl::SuspiciousImpl);
475 reg.register_early_lint_pass(box cargo_common_metadata::Pass);
476 reg.register_early_lint_pass(box multiple_crate_versions::Pass);
477 reg.register_early_lint_pass(box wildcard_dependencies::Pass);
478 reg.register_late_lint_pass(box map_unit_fn::Pass);
479 reg.register_late_lint_pass(box infallible_destructuring_match::Pass);
480 reg.register_late_lint_pass(box inherent_impl::Pass::default());
481 reg.register_late_lint_pass(box neg_cmp_op_on_partial_ord::NoNegCompOpForPartialOrd);
482 reg.register_late_lint_pass(box unwrap::Pass);
483 reg.register_late_lint_pass(box duration_subsec::DurationSubsec);
484 reg.register_late_lint_pass(box default_trait_access::DefaultTraitAccess);
485 reg.register_late_lint_pass(box indexing_slicing::IndexingSlicing);
486 reg.register_late_lint_pass(box non_copy_const::NonCopyConst);
487 reg.register_late_lint_pass(box ptr_offset_with_cast::Pass);
488 reg.register_late_lint_pass(box redundant_clone::RedundantClone);
489 reg.register_late_lint_pass(box slow_vector_initialization::Pass);
490 reg.register_late_lint_pass(box types::RefToMut);
491 reg.register_late_lint_pass(box assertions_on_constants::AssertionsOnConstants);
492 reg.register_late_lint_pass(box missing_const_for_fn::MissingConstForFn);
494 reg.register_lint_group("clippy::restriction", Some("clippy_restriction"), vec![
495 arithmetic::FLOAT_ARITHMETIC,
496 arithmetic::INTEGER_ARITHMETIC,
497 else_if_without_else::ELSE_IF_WITHOUT_ELSE,
498 implicit_return::IMPLICIT_RETURN,
499 indexing_slicing::INDEXING_SLICING,
500 inherent_impl::MULTIPLE_INHERENT_IMPL,
501 literal_representation::DECIMAL_LITERAL_REPRESENTATION,
502 matches::WILDCARD_MATCH_ARM,
503 mem_forget::MEM_FORGET,
504 methods::CLONE_ON_REF_PTR,
505 methods::OPTION_UNWRAP_USED,
506 methods::RESULT_UNWRAP_USED,
507 methods::WRONG_PUB_SELF_CONVENTION,
508 misc::FLOAT_CMP_CONST,
509 missing_doc::MISSING_DOCS_IN_PRIVATE_ITEMS,
510 missing_inline::MISSING_INLINE_IN_PUBLIC_ITEMS,
511 panic_unimplemented::UNIMPLEMENTED,
512 shadow::SHADOW_REUSE,
519 reg.register_lint_group("clippy::pedantic", Some("clippy_pedantic"), vec![
520 attrs::INLINE_ALWAYS,
521 copies::MATCH_SAME_ARMS,
522 copy_iterator::COPY_ITERATOR,
523 default_trait_access::DEFAULT_TRAIT_ACCESS,
524 derive::EXPL_IMPL_CLONE_ON_COPY,
526 empty_enum::EMPTY_ENUM,
527 enum_glob_use::ENUM_GLOB_USE,
528 enum_variants::MODULE_NAME_REPETITIONS,
529 enum_variants::PUB_ENUM_VARIANT_NAMES,
530 if_not_else::IF_NOT_ELSE,
531 infinite_iter::MAYBE_INFINITE_ITER,
532 items_after_statements::ITEMS_AFTER_STATEMENTS,
533 literal_representation::LARGE_DIGIT_GROUPS,
534 loops::EXPLICIT_INTO_ITER_LOOP,
535 loops::EXPLICIT_ITER_LOOP,
536 matches::SINGLE_MATCH_ELSE,
538 methods::MAP_FLATTEN,
539 methods::OPTION_MAP_UNWRAP_OR,
540 methods::OPTION_MAP_UNWRAP_OR_ELSE,
541 methods::RESULT_MAP_UNWRAP_OR_ELSE,
542 misc::USED_UNDERSCORE_BINDING,
543 misc_early::UNSEPARATED_LITERAL_SUFFIX,
545 needless_continue::NEEDLESS_CONTINUE,
546 needless_pass_by_value::NEEDLESS_PASS_BY_VALUE,
547 non_expressive_names::SIMILAR_NAMES,
548 replace_consts::REPLACE_CONSTS,
549 shadow::SHADOW_UNRELATED,
550 strings::STRING_ADD_ASSIGN,
551 types::CAST_POSSIBLE_TRUNCATION,
552 types::CAST_POSSIBLE_WRAP,
553 types::CAST_PRECISION_LOSS,
554 types::CAST_SIGN_LOSS,
555 types::INVALID_UPCAST_COMPARISONS,
557 unicode::NON_ASCII_LITERAL,
558 unicode::UNICODE_NOT_NFC,
562 reg.register_lint_group("clippy::internal", Some("clippy_internal"), vec![
563 utils::internal_lints::CLIPPY_LINTS_INTERNAL,
564 utils::internal_lints::COMPILER_LINT_FUNCTIONS,
565 utils::internal_lints::DEFAULT_HASH_TYPES,
566 utils::internal_lints::LINT_WITHOUT_LINT_PASS,
569 reg.register_lint_group("clippy::all", Some("clippy"), vec![
570 approx_const::APPROX_CONSTANT,
571 assertions_on_constants::ASSERTIONS_ON_CONSTANTS,
572 assign_ops::ASSIGN_OP_PATTERN,
573 assign_ops::MISREFACTORED_ASSIGN_OP,
574 attrs::DEPRECATED_CFG_ATTR,
575 attrs::DEPRECATED_SEMVER,
576 attrs::UNKNOWN_CLIPPY_LINTS,
577 attrs::USELESS_ATTRIBUTE,
578 bit_mask::BAD_BIT_MASK,
579 bit_mask::INEFFECTIVE_BIT_MASK,
580 bit_mask::VERBOSE_BIT_MASK,
581 blacklisted_name::BLACKLISTED_NAME,
582 block_in_if_condition::BLOCK_IN_IF_CONDITION_EXPR,
583 block_in_if_condition::BLOCK_IN_IF_CONDITION_STMT,
585 booleans::NONMINIMAL_BOOL,
586 bytecount::NAIVE_BYTECOUNT,
587 collapsible_if::COLLAPSIBLE_IF,
588 const_static_lifetime::CONST_STATIC_LIFETIME,
589 copies::IFS_SAME_COND,
590 copies::IF_SAME_THEN_ELSE,
591 cyclomatic_complexity::CYCLOMATIC_COMPLEXITY,
592 derive::DERIVE_HASH_XOR_EQ,
593 double_comparison::DOUBLE_COMPARISONS,
594 double_parens::DOUBLE_PARENS,
595 drop_forget_ref::DROP_COPY,
596 drop_forget_ref::DROP_REF,
597 drop_forget_ref::FORGET_COPY,
598 drop_forget_ref::FORGET_REF,
599 duration_subsec::DURATION_SUBSEC,
601 enum_clike::ENUM_CLIKE_UNPORTABLE_VARIANT,
602 enum_variants::ENUM_VARIANT_NAMES,
603 enum_variants::MODULE_INCEPTION,
606 erasing_op::ERASING_OP,
608 eta_reduction::REDUNDANT_CLOSURE,
609 eval_order_dependence::DIVERGING_SUB_EXPRESSION,
610 eval_order_dependence::EVAL_ORDER_DEPENDENCE,
611 excessive_precision::EXCESSIVE_PRECISION,
612 explicit_write::EXPLICIT_WRITE,
613 format::USELESS_FORMAT,
614 formatting::POSSIBLE_MISSING_COMMA,
615 formatting::SUSPICIOUS_ASSIGNMENT_FORMATTING,
616 formatting::SUSPICIOUS_ELSE_FORMATTING,
617 functions::NOT_UNSAFE_PTR_ARG_DEREF,
618 functions::TOO_MANY_ARGUMENTS,
619 identity_conversion::IDENTITY_CONVERSION,
620 identity_op::IDENTITY_OP,
621 indexing_slicing::OUT_OF_BOUNDS_INDEXING,
622 infallible_destructuring_match::INFALLIBLE_DESTRUCTURING_MATCH,
623 infinite_iter::INFINITE_ITER,
624 inline_fn_without_body::INLINE_FN_WITHOUT_BODY,
625 int_plus_one::INT_PLUS_ONE,
626 invalid_ref::INVALID_REF,
627 large_enum_variant::LARGE_ENUM_VARIANT,
628 len_zero::LEN_WITHOUT_IS_EMPTY,
630 let_if_seq::USELESS_LET_IF_SEQ,
631 lifetimes::EXTRA_UNUSED_LIFETIMES,
632 lifetimes::NEEDLESS_LIFETIMES,
633 literal_representation::INCONSISTENT_DIGIT_GROUPING,
634 literal_representation::MISTYPED_LITERAL_SUFFIXES,
635 literal_representation::UNREADABLE_LITERAL,
637 loops::EXPLICIT_COUNTER_LOOP,
639 loops::FOR_LOOP_OVER_OPTION,
640 loops::FOR_LOOP_OVER_RESULT,
641 loops::ITER_NEXT_LOOP,
642 loops::MANUAL_MEMCPY,
643 loops::MUT_RANGE_BOUND,
644 loops::NEEDLESS_COLLECT,
645 loops::NEEDLESS_RANGE_LOOP,
647 loops::REVERSE_RANGE_LOOP,
648 loops::UNUSED_COLLECT,
649 loops::WHILE_IMMUTABLE_CONDITION,
650 loops::WHILE_LET_LOOP,
651 loops::WHILE_LET_ON_ITERATOR,
652 map_clone::MAP_CLONE,
653 map_unit_fn::OPTION_MAP_UNIT_FN,
654 map_unit_fn::RESULT_MAP_UNIT_FN,
655 matches::MATCH_AS_REF,
657 matches::MATCH_OVERLAPPING_ARM,
658 matches::MATCH_REF_PATS,
659 matches::MATCH_WILD_ERR_ARM,
660 matches::SINGLE_MATCH,
661 mem_discriminant::MEM_DISCRIMINANT_NON_ENUM,
662 mem_replace::MEM_REPLACE_OPTION_WITH_NONE,
663 methods::CHARS_LAST_CMP,
664 methods::CHARS_NEXT_CMP,
665 methods::CLONE_DOUBLE_REF,
666 methods::CLONE_ON_COPY,
667 methods::EXPECT_FUN_CALL,
668 methods::FILTER_NEXT,
670 methods::INTO_ITER_ON_ARRAY,
671 methods::INTO_ITER_ON_REF,
672 methods::ITER_CLONED_COLLECT,
674 methods::ITER_SKIP_NEXT,
675 methods::NEW_RET_NO_SELF,
677 methods::OPTION_MAP_OR_NONE,
678 methods::OR_FUN_CALL,
679 methods::SEARCH_IS_SOME,
680 methods::SHOULD_IMPLEMENT_TRAIT,
681 methods::SINGLE_CHAR_PATTERN,
682 methods::STRING_EXTEND_CHARS,
683 methods::TEMPORARY_CSTRING_AS_PTR,
684 methods::UNNECESSARY_FILTER_MAP,
685 methods::UNNECESSARY_FOLD,
686 methods::USELESS_ASREF,
687 methods::WRONG_SELF_CONVENTION,
693 misc::REDUNDANT_PATTERN,
694 misc::SHORT_CIRCUIT_STATEMENT,
695 misc::TOPLEVEL_REF_ARG,
697 misc_early::BUILTIN_TYPE_SHADOW,
698 misc_early::DOUBLE_NEG,
699 misc_early::DUPLICATE_UNDERSCORE_ARGUMENT,
700 misc_early::MIXED_CASE_HEX_LITERALS,
701 misc_early::REDUNDANT_CLOSURE_CALL,
702 misc_early::UNNEEDED_FIELD_PATTERN,
703 misc_early::ZERO_PREFIXED_LITERAL,
704 mut_reference::UNNECESSARY_MUT_PASSED,
705 mutex_atomic::MUTEX_ATOMIC,
706 needless_bool::BOOL_COMPARISON,
707 needless_bool::NEEDLESS_BOOL,
708 needless_borrowed_ref::NEEDLESS_BORROWED_REFERENCE,
709 needless_update::NEEDLESS_UPDATE,
710 neg_cmp_op_on_partial_ord::NEG_CMP_OP_ON_PARTIAL_ORD,
711 neg_multiply::NEG_MULTIPLY,
712 new_without_default::NEW_WITHOUT_DEFAULT,
713 no_effect::NO_EFFECT,
714 no_effect::UNNECESSARY_OPERATION,
715 non_copy_const::BORROW_INTERIOR_MUTABLE_CONST,
716 non_copy_const::DECLARE_INTERIOR_MUTABLE_CONST,
717 non_expressive_names::JUST_UNDERSCORES_AND_DIGITS,
718 non_expressive_names::MANY_SINGLE_CHAR_NAMES,
719 ok_if_let::IF_LET_SOME_RESULT,
720 open_options::NONSENSICAL_OPEN_OPTIONS,
721 overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL,
722 panic_unimplemented::PANIC_PARAMS,
723 partialeq_ne_impl::PARTIALEQ_NE_IMPL,
724 precedence::PRECEDENCE,
728 ptr_offset_with_cast::PTR_OFFSET_WITH_CAST,
729 question_mark::QUESTION_MARK,
730 ranges::ITERATOR_STEP_BY_ZERO,
731 ranges::RANGE_MINUS_ONE,
732 ranges::RANGE_PLUS_ONE,
733 ranges::RANGE_ZIP_WITH_LEN,
734 redundant_field_names::REDUNDANT_FIELD_NAMES,
735 redundant_pattern_matching::REDUNDANT_PATTERN_MATCHING,
736 reference::DEREF_ADDROF,
737 reference::REF_IN_DEREF,
738 regex::INVALID_REGEX,
740 regex::TRIVIAL_REGEX,
741 returns::LET_AND_RETURN,
742 returns::NEEDLESS_RETURN,
743 returns::UNUSED_UNIT,
744 serde_api::SERDE_API_MISUSE,
745 slow_vector_initialization::SLOW_VECTOR_INITIALIZATION,
746 strings::STRING_LIT_AS_BYTES,
747 suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL,
748 suspicious_trait_impl::SUSPICIOUS_OP_ASSIGN_IMPL,
749 swap::ALMOST_SWAPPED,
751 temporary_assignment::TEMPORARY_ASSIGNMENT,
752 transmute::CROSSPOINTER_TRANSMUTE,
753 transmute::TRANSMUTE_BYTES_TO_STR,
754 transmute::TRANSMUTE_INT_TO_BOOL,
755 transmute::TRANSMUTE_INT_TO_CHAR,
756 transmute::TRANSMUTE_INT_TO_FLOAT,
757 transmute::TRANSMUTE_PTR_TO_PTR,
758 transmute::TRANSMUTE_PTR_TO_REF,
759 transmute::USELESS_TRANSMUTE,
760 transmute::WRONG_TRANSMUTE,
761 trivially_copy_pass_by_ref::TRIVIALLY_COPY_PASS_BY_REF,
762 types::ABSURD_EXTREME_COMPARISONS,
765 types::CAST_LOSSLESS,
766 types::CAST_PTR_ALIGNMENT,
767 types::CAST_REF_TO_MUT,
768 types::CHAR_LIT_AS_U8,
769 types::FN_TO_NUMERIC_CAST,
770 types::FN_TO_NUMERIC_CAST_WITH_TRUNCATION,
771 types::IMPLICIT_HASHER,
772 types::LET_UNIT_VALUE,
773 types::OPTION_OPTION,
774 types::TYPE_COMPLEXITY,
777 types::UNNECESSARY_CAST,
779 unicode::ZERO_WIDTH_SPACE,
780 unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME,
781 unused_io_amount::UNUSED_IO_AMOUNT,
782 unused_label::UNUSED_LABEL,
784 write::PRINTLN_EMPTY_STRING,
785 write::PRINT_LITERAL,
786 write::PRINT_WITH_NEWLINE,
787 write::WRITELN_EMPTY_STRING,
788 write::WRITE_LITERAL,
789 write::WRITE_WITH_NEWLINE,
790 zero_div_zero::ZERO_DIVIDED_BY_ZERO,
793 reg.register_lint_group("clippy::style", Some("clippy_style"), vec![
794 assertions_on_constants::ASSERTIONS_ON_CONSTANTS,
795 assign_ops::ASSIGN_OP_PATTERN,
796 attrs::UNKNOWN_CLIPPY_LINTS,
797 bit_mask::VERBOSE_BIT_MASK,
798 blacklisted_name::BLACKLISTED_NAME,
799 block_in_if_condition::BLOCK_IN_IF_CONDITION_EXPR,
800 block_in_if_condition::BLOCK_IN_IF_CONDITION_STMT,
801 collapsible_if::COLLAPSIBLE_IF,
802 const_static_lifetime::CONST_STATIC_LIFETIME,
803 enum_variants::ENUM_VARIANT_NAMES,
804 enum_variants::MODULE_INCEPTION,
806 eta_reduction::REDUNDANT_CLOSURE,
807 excessive_precision::EXCESSIVE_PRECISION,
808 formatting::SUSPICIOUS_ASSIGNMENT_FORMATTING,
809 formatting::SUSPICIOUS_ELSE_FORMATTING,
810 infallible_destructuring_match::INFALLIBLE_DESTRUCTURING_MATCH,
811 len_zero::LEN_WITHOUT_IS_EMPTY,
813 let_if_seq::USELESS_LET_IF_SEQ,
814 literal_representation::INCONSISTENT_DIGIT_GROUPING,
815 literal_representation::UNREADABLE_LITERAL,
818 loops::NEEDLESS_RANGE_LOOP,
819 loops::WHILE_LET_ON_ITERATOR,
820 map_clone::MAP_CLONE,
822 matches::MATCH_OVERLAPPING_ARM,
823 matches::MATCH_REF_PATS,
824 matches::MATCH_WILD_ERR_ARM,
825 matches::SINGLE_MATCH,
826 mem_replace::MEM_REPLACE_OPTION_WITH_NONE,
827 methods::CHARS_LAST_CMP,
829 methods::INTO_ITER_ON_REF,
830 methods::ITER_CLONED_COLLECT,
831 methods::ITER_SKIP_NEXT,
832 methods::NEW_RET_NO_SELF,
834 methods::OPTION_MAP_OR_NONE,
835 methods::SHOULD_IMPLEMENT_TRAIT,
836 methods::STRING_EXTEND_CHARS,
837 methods::UNNECESSARY_FOLD,
838 methods::WRONG_SELF_CONVENTION,
839 misc::REDUNDANT_PATTERN,
840 misc::TOPLEVEL_REF_ARG,
842 misc_early::BUILTIN_TYPE_SHADOW,
843 misc_early::DOUBLE_NEG,
844 misc_early::DUPLICATE_UNDERSCORE_ARGUMENT,
845 misc_early::MIXED_CASE_HEX_LITERALS,
846 misc_early::UNNEEDED_FIELD_PATTERN,
847 mut_reference::UNNECESSARY_MUT_PASSED,
848 neg_multiply::NEG_MULTIPLY,
849 new_without_default::NEW_WITHOUT_DEFAULT,
850 non_expressive_names::JUST_UNDERSCORES_AND_DIGITS,
851 non_expressive_names::MANY_SINGLE_CHAR_NAMES,
852 ok_if_let::IF_LET_SOME_RESULT,
853 panic_unimplemented::PANIC_PARAMS,
856 question_mark::QUESTION_MARK,
857 redundant_field_names::REDUNDANT_FIELD_NAMES,
858 redundant_pattern_matching::REDUNDANT_PATTERN_MATCHING,
860 regex::TRIVIAL_REGEX,
861 returns::LET_AND_RETURN,
862 returns::NEEDLESS_RETURN,
863 returns::UNUSED_UNIT,
864 strings::STRING_LIT_AS_BYTES,
865 types::FN_TO_NUMERIC_CAST,
866 types::FN_TO_NUMERIC_CAST_WITH_TRUNCATION,
867 types::IMPLICIT_HASHER,
868 types::LET_UNIT_VALUE,
869 unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME,
870 write::PRINTLN_EMPTY_STRING,
871 write::PRINT_LITERAL,
872 write::PRINT_WITH_NEWLINE,
873 write::WRITELN_EMPTY_STRING,
874 write::WRITE_LITERAL,
875 write::WRITE_WITH_NEWLINE,
878 reg.register_lint_group("clippy::complexity", Some("clippy_complexity"), vec![
879 assign_ops::MISREFACTORED_ASSIGN_OP,
880 attrs::DEPRECATED_CFG_ATTR,
881 booleans::NONMINIMAL_BOOL,
882 cyclomatic_complexity::CYCLOMATIC_COMPLEXITY,
883 double_comparison::DOUBLE_COMPARISONS,
884 double_parens::DOUBLE_PARENS,
885 duration_subsec::DURATION_SUBSEC,
886 eval_order_dependence::DIVERGING_SUB_EXPRESSION,
887 eval_order_dependence::EVAL_ORDER_DEPENDENCE,
888 explicit_write::EXPLICIT_WRITE,
889 format::USELESS_FORMAT,
890 functions::TOO_MANY_ARGUMENTS,
891 identity_conversion::IDENTITY_CONVERSION,
892 identity_op::IDENTITY_OP,
893 int_plus_one::INT_PLUS_ONE,
894 lifetimes::EXTRA_UNUSED_LIFETIMES,
895 lifetimes::NEEDLESS_LIFETIMES,
896 loops::EXPLICIT_COUNTER_LOOP,
897 loops::MUT_RANGE_BOUND,
898 loops::WHILE_LET_LOOP,
899 map_unit_fn::OPTION_MAP_UNIT_FN,
900 map_unit_fn::RESULT_MAP_UNIT_FN,
901 matches::MATCH_AS_REF,
902 methods::CHARS_NEXT_CMP,
903 methods::CLONE_ON_COPY,
904 methods::FILTER_NEXT,
905 methods::SEARCH_IS_SOME,
906 methods::UNNECESSARY_FILTER_MAP,
907 methods::USELESS_ASREF,
908 misc::SHORT_CIRCUIT_STATEMENT,
909 misc_early::REDUNDANT_CLOSURE_CALL,
910 misc_early::ZERO_PREFIXED_LITERAL,
911 needless_bool::BOOL_COMPARISON,
912 needless_bool::NEEDLESS_BOOL,
913 needless_borrowed_ref::NEEDLESS_BORROWED_REFERENCE,
914 needless_update::NEEDLESS_UPDATE,
915 neg_cmp_op_on_partial_ord::NEG_CMP_OP_ON_PARTIAL_ORD,
916 no_effect::NO_EFFECT,
917 no_effect::UNNECESSARY_OPERATION,
918 overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL,
919 partialeq_ne_impl::PARTIALEQ_NE_IMPL,
920 precedence::PRECEDENCE,
921 ptr_offset_with_cast::PTR_OFFSET_WITH_CAST,
922 ranges::RANGE_MINUS_ONE,
923 ranges::RANGE_PLUS_ONE,
924 ranges::RANGE_ZIP_WITH_LEN,
925 reference::DEREF_ADDROF,
926 reference::REF_IN_DEREF,
928 temporary_assignment::TEMPORARY_ASSIGNMENT,
929 transmute::CROSSPOINTER_TRANSMUTE,
930 transmute::TRANSMUTE_BYTES_TO_STR,
931 transmute::TRANSMUTE_INT_TO_BOOL,
932 transmute::TRANSMUTE_INT_TO_CHAR,
933 transmute::TRANSMUTE_INT_TO_FLOAT,
934 transmute::TRANSMUTE_PTR_TO_PTR,
935 transmute::TRANSMUTE_PTR_TO_REF,
936 transmute::USELESS_TRANSMUTE,
938 types::CAST_LOSSLESS,
939 types::CHAR_LIT_AS_U8,
940 types::OPTION_OPTION,
941 types::TYPE_COMPLEXITY,
943 types::UNNECESSARY_CAST,
945 unused_label::UNUSED_LABEL,
946 zero_div_zero::ZERO_DIVIDED_BY_ZERO,
949 reg.register_lint_group("clippy::correctness", Some("clippy_correctness"), vec![
950 approx_const::APPROX_CONSTANT,
951 attrs::DEPRECATED_SEMVER,
952 attrs::USELESS_ATTRIBUTE,
953 bit_mask::BAD_BIT_MASK,
954 bit_mask::INEFFECTIVE_BIT_MASK,
956 copies::IFS_SAME_COND,
957 copies::IF_SAME_THEN_ELSE,
958 derive::DERIVE_HASH_XOR_EQ,
959 drop_forget_ref::DROP_COPY,
960 drop_forget_ref::DROP_REF,
961 drop_forget_ref::FORGET_COPY,
962 drop_forget_ref::FORGET_REF,
963 enum_clike::ENUM_CLIKE_UNPORTABLE_VARIANT,
965 erasing_op::ERASING_OP,
966 formatting::POSSIBLE_MISSING_COMMA,
967 functions::NOT_UNSAFE_PTR_ARG_DEREF,
968 indexing_slicing::OUT_OF_BOUNDS_INDEXING,
969 infinite_iter::INFINITE_ITER,
970 inline_fn_without_body::INLINE_FN_WITHOUT_BODY,
971 invalid_ref::INVALID_REF,
972 literal_representation::MISTYPED_LITERAL_SUFFIXES,
973 loops::FOR_LOOP_OVER_OPTION,
974 loops::FOR_LOOP_OVER_RESULT,
975 loops::ITER_NEXT_LOOP,
977 loops::REVERSE_RANGE_LOOP,
978 loops::WHILE_IMMUTABLE_CONDITION,
979 mem_discriminant::MEM_DISCRIMINANT_NON_ENUM,
980 methods::CLONE_DOUBLE_REF,
981 methods::INTO_ITER_ON_ARRAY,
982 methods::TEMPORARY_CSTRING_AS_PTR,
987 non_copy_const::BORROW_INTERIOR_MUTABLE_CONST,
988 non_copy_const::DECLARE_INTERIOR_MUTABLE_CONST,
989 open_options::NONSENSICAL_OPEN_OPTIONS,
991 ranges::ITERATOR_STEP_BY_ZERO,
992 regex::INVALID_REGEX,
993 serde_api::SERDE_API_MISUSE,
994 suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL,
995 suspicious_trait_impl::SUSPICIOUS_OP_ASSIGN_IMPL,
996 swap::ALMOST_SWAPPED,
997 transmute::WRONG_TRANSMUTE,
998 types::ABSURD_EXTREME_COMPARISONS,
999 types::CAST_PTR_ALIGNMENT,
1000 types::CAST_REF_TO_MUT,
1002 unicode::ZERO_WIDTH_SPACE,
1003 unused_io_amount::UNUSED_IO_AMOUNT,
1006 reg.register_lint_group("clippy::perf", Some("clippy_perf"), vec![
1007 bytecount::NAIVE_BYTECOUNT,
1009 escape::BOXED_LOCAL,
1010 large_enum_variant::LARGE_ENUM_VARIANT,
1011 loops::MANUAL_MEMCPY,
1012 loops::NEEDLESS_COLLECT,
1013 loops::UNUSED_COLLECT,
1014 methods::EXPECT_FUN_CALL,
1016 methods::OR_FUN_CALL,
1017 methods::SINGLE_CHAR_PATTERN,
1019 mutex_atomic::MUTEX_ATOMIC,
1020 slow_vector_initialization::SLOW_VECTOR_INITIALIZATION,
1021 trivially_copy_pass_by_ref::TRIVIALLY_COPY_PASS_BY_REF,
1026 reg.register_lint_group("clippy::cargo", Some("clippy_cargo"), vec![
1027 cargo_common_metadata::CARGO_COMMON_METADATA,
1028 multiple_crate_versions::MULTIPLE_CRATE_VERSIONS,
1029 wildcard_dependencies::WILDCARD_DEPENDENCIES,
1032 reg.register_lint_group("clippy::nursery", Some("clippy_nursery"), vec![
1033 attrs::EMPTY_LINE_AFTER_OUTER_ATTR,
1034 fallible_impl_from::FALLIBLE_IMPL_FROM,
1035 missing_const_for_fn::MISSING_CONST_FOR_FN,
1036 mutex_atomic::MUTEX_INTEGER,
1037 needless_borrow::NEEDLESS_BORROW,
1038 redundant_clone::REDUNDANT_CLONE,
1039 unwrap::PANICKING_UNWRAP,
1040 unwrap::UNNECESSARY_UNWRAP,
1044 pub fn register_renamed(ls: &mut rustc::lint::LintStore) {
1045 ls.register_renamed("clippy::stutter", "clippy::module_name_repetitions");
1046 ls.register_renamed("clippy::new_without_default_derive", "clippy::new_without_default");
1049 // only exists to let the dogfood integration test works.
1050 // Don't run clippy as an executable directly
1053 panic!("Please use the cargo-clippy executable");