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")
293 #[allow(clippy::too_many_lines)]
295 pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
296 let mut store = reg.sess.lint_store.borrow_mut();
297 // begin deprecated lints, do not remove this comment, it’s used in `update_lints`
298 store.register_removed(
300 "`assert!()` will be more flexible with RFC 2011",
302 store.register_removed(
304 "`.extend_from_slice(_)` is a faster way to extend a Vec by a slice",
306 store.register_removed(
307 "range_step_by_zero",
308 "`iterator.step_by(0)` panics nowadays",
310 store.register_removed(
312 "`Vec::as_slice` has been stabilized in 1.7",
314 store.register_removed(
315 "unstable_as_mut_slice",
316 "`Vec::as_mut_slice` has been stabilized in 1.7",
318 store.register_removed(
320 "using `str::to_string` is common even today and specialization will likely happen soon",
322 store.register_removed(
324 "using `string::to_string` is common even today and specialization will likely happen soon",
326 store.register_removed(
327 "misaligned_transmute",
328 "this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr",
330 store.register_removed(
332 "using compound assignment operators (e.g. `+=`) is harmless",
334 store.register_removed(
335 "if_let_redundant_pattern_matching",
336 "this lint has been changed to redundant_pattern_matching",
338 store.register_removed(
339 "unsafe_vector_initialization",
340 "the replacement suggested by this lint had substantially different behavior",
342 // end deprecated lints, do not remove this comment, it’s used in `update_lints`
344 reg.register_late_lint_pass(box serde_api::Serde);
345 reg.register_early_lint_pass(box utils::internal_lints::Clippy);
346 reg.register_late_lint_pass(box utils::internal_lints::CompilerLintFunctions::new());
347 reg.register_early_lint_pass(box utils::internal_lints::DefaultHashTypes::default());
348 reg.register_late_lint_pass(box utils::internal_lints::LintWithoutLintPass::default());
349 reg.register_late_lint_pass(box utils::inspector::Pass);
350 reg.register_late_lint_pass(box utils::author::Pass);
351 reg.register_late_lint_pass(box types::TypePass);
352 reg.register_late_lint_pass(box booleans::NonminimalBool);
353 reg.register_late_lint_pass(box eq_op::EqOp);
354 reg.register_early_lint_pass(box enum_variants::EnumVariantNames::new(conf.enum_variant_name_threshold));
355 reg.register_late_lint_pass(box enum_glob_use::EnumGlobUse);
356 reg.register_late_lint_pass(box enum_clike::UnportableVariant);
357 reg.register_late_lint_pass(box excessive_precision::ExcessivePrecision);
358 reg.register_late_lint_pass(box bit_mask::BitMask::new(conf.verbose_bit_mask_threshold));
359 reg.register_late_lint_pass(box ptr::PointerPass);
360 reg.register_late_lint_pass(box needless_bool::NeedlessBool);
361 reg.register_late_lint_pass(box needless_bool::BoolComparison);
362 reg.register_late_lint_pass(box approx_const::Pass);
363 reg.register_late_lint_pass(box misc::Pass);
364 reg.register_early_lint_pass(box precedence::Precedence);
365 reg.register_early_lint_pass(box needless_continue::NeedlessContinue);
366 reg.register_late_lint_pass(box eta_reduction::EtaPass);
367 reg.register_late_lint_pass(box identity_op::IdentityOp);
368 reg.register_late_lint_pass(box erasing_op::ErasingOp);
369 reg.register_early_lint_pass(box items_after_statements::ItemsAfterStatements);
370 reg.register_late_lint_pass(box mut_mut::MutMut);
371 reg.register_late_lint_pass(box mut_reference::UnnecessaryMutPassed);
372 reg.register_late_lint_pass(box len_zero::LenZero);
373 reg.register_late_lint_pass(box attrs::AttrPass);
374 reg.register_early_lint_pass(box collapsible_if::CollapsibleIf);
375 reg.register_late_lint_pass(box block_in_if_condition::BlockInIfCondition);
376 reg.register_late_lint_pass(box unicode::Unicode);
377 reg.register_late_lint_pass(box strings::StringAdd);
378 reg.register_early_lint_pass(box returns::ReturnPass);
379 reg.register_late_lint_pass(box implicit_return::Pass);
380 reg.register_late_lint_pass(box methods::Pass);
381 reg.register_late_lint_pass(box map_clone::Pass);
382 reg.register_late_lint_pass(box shadow::Pass);
383 reg.register_late_lint_pass(box types::LetPass);
384 reg.register_late_lint_pass(box types::UnitCmp);
385 reg.register_late_lint_pass(box loops::Pass);
386 reg.register_late_lint_pass(box lifetimes::LifetimePass);
387 reg.register_late_lint_pass(box entry::HashMapLint);
388 reg.register_late_lint_pass(box ranges::Pass);
389 reg.register_late_lint_pass(box types::CastPass);
390 reg.register_late_lint_pass(box types::TypeComplexityPass::new(conf.type_complexity_threshold));
391 reg.register_late_lint_pass(box matches::MatchPass);
392 reg.register_late_lint_pass(box minmax::MinMaxPass);
393 reg.register_late_lint_pass(box open_options::NonSensical);
394 reg.register_late_lint_pass(box zero_div_zero::Pass);
395 reg.register_late_lint_pass(box mutex_atomic::MutexAtomic);
396 reg.register_late_lint_pass(box needless_update::Pass);
397 reg.register_late_lint_pass(box needless_borrow::NeedlessBorrow::default());
398 reg.register_late_lint_pass(box needless_borrowed_ref::NeedlessBorrowedRef);
399 reg.register_late_lint_pass(box no_effect::Pass);
400 reg.register_late_lint_pass(box temporary_assignment::Pass);
401 reg.register_late_lint_pass(box transmute::Transmute);
402 reg.register_late_lint_pass(
403 box cyclomatic_complexity::CyclomaticComplexity::new(conf.cyclomatic_complexity_threshold)
405 reg.register_late_lint_pass(box escape::Pass{too_large_for_stack: conf.too_large_for_stack});
406 reg.register_early_lint_pass(box misc_early::MiscEarly);
407 reg.register_late_lint_pass(box panic_unimplemented::Pass);
408 reg.register_late_lint_pass(box strings::StringLitAsBytes);
409 reg.register_late_lint_pass(box derive::Derive);
410 reg.register_late_lint_pass(box types::CharLitAsU8);
411 reg.register_late_lint_pass(box vec::Pass);
412 reg.register_late_lint_pass(box drop_forget_ref::Pass);
413 reg.register_late_lint_pass(box empty_enum::EmptyEnum);
414 reg.register_late_lint_pass(box types::AbsurdExtremeComparisons);
415 reg.register_late_lint_pass(box types::InvalidUpcastComparisons);
416 reg.register_late_lint_pass(box regex::Pass::default());
417 reg.register_late_lint_pass(box copies::CopyAndPaste);
418 reg.register_late_lint_pass(box copy_iterator::CopyIterator);
419 reg.register_late_lint_pass(box format::Pass);
420 reg.register_early_lint_pass(box formatting::Formatting);
421 reg.register_late_lint_pass(box swap::Swap);
422 reg.register_early_lint_pass(box if_not_else::IfNotElse);
423 reg.register_early_lint_pass(box else_if_without_else::ElseIfWithoutElse);
424 reg.register_early_lint_pass(box int_plus_one::IntPlusOne);
425 reg.register_late_lint_pass(box overflow_check_conditional::OverflowCheckConditional);
426 reg.register_late_lint_pass(box unused_label::UnusedLabel);
427 reg.register_late_lint_pass(box new_without_default::NewWithoutDefault::default());
428 reg.register_late_lint_pass(box blacklisted_name::BlackListedName::new(
429 conf.blacklisted_names.iter().cloned().collect()
431 reg.register_late_lint_pass(box functions::Functions::new(conf.too_many_arguments_threshold, conf.too_many_lines_threshold));
432 reg.register_early_lint_pass(box doc::Doc::new(conf.doc_valid_idents.iter().cloned().collect()));
433 reg.register_late_lint_pass(box neg_multiply::NegMultiply);
434 reg.register_early_lint_pass(box unsafe_removed_from_name::UnsafeNameRemoval);
435 reg.register_late_lint_pass(box mem_discriminant::MemDiscriminant);
436 reg.register_late_lint_pass(box mem_forget::MemForget);
437 reg.register_late_lint_pass(box mem_replace::MemReplace);
438 reg.register_late_lint_pass(box arithmetic::Arithmetic::default());
439 reg.register_late_lint_pass(box assign_ops::AssignOps);
440 reg.register_late_lint_pass(box let_if_seq::LetIfSeq);
441 reg.register_late_lint_pass(box eval_order_dependence::EvalOrderDependence);
442 reg.register_late_lint_pass(box missing_doc::MissingDoc::new());
443 reg.register_late_lint_pass(box missing_inline::MissingInline);
444 reg.register_late_lint_pass(box ok_if_let::Pass);
445 reg.register_late_lint_pass(box redundant_pattern_matching::Pass);
446 reg.register_late_lint_pass(box partialeq_ne_impl::Pass);
447 reg.register_early_lint_pass(box reference::Pass);
448 reg.register_early_lint_pass(box reference::DerefPass);
449 reg.register_early_lint_pass(box double_parens::DoubleParens);
450 reg.register_late_lint_pass(box unused_io_amount::UnusedIoAmount);
451 reg.register_late_lint_pass(box large_enum_variant::LargeEnumVariant::new(conf.enum_variant_size_threshold));
452 reg.register_late_lint_pass(box explicit_write::Pass);
453 reg.register_late_lint_pass(box needless_pass_by_value::NeedlessPassByValue);
454 reg.register_late_lint_pass(box trivially_copy_pass_by_ref::TriviallyCopyPassByRef::new(
455 conf.trivial_copy_size_limit,
458 reg.register_early_lint_pass(box literal_representation::LiteralDigitGrouping);
459 reg.register_early_lint_pass(box literal_representation::LiteralRepresentation::new(
460 conf.literal_representation_threshold
462 reg.register_late_lint_pass(box use_self::UseSelf);
463 reg.register_late_lint_pass(box bytecount::ByteCount);
464 reg.register_late_lint_pass(box infinite_iter::Pass);
465 reg.register_late_lint_pass(box inline_fn_without_body::Pass);
466 reg.register_late_lint_pass(box invalid_ref::InvalidRef);
467 reg.register_late_lint_pass(box identity_conversion::IdentityConversion::default());
468 reg.register_late_lint_pass(box types::ImplicitHasher);
469 reg.register_early_lint_pass(box const_static_lifetime::StaticConst);
470 reg.register_late_lint_pass(box fallible_impl_from::FallibleImplFrom);
471 reg.register_late_lint_pass(box replace_consts::ReplaceConsts);
472 reg.register_late_lint_pass(box types::UnitArg);
473 reg.register_late_lint_pass(box double_comparison::Pass);
474 reg.register_late_lint_pass(box question_mark::Pass);
475 reg.register_late_lint_pass(box suspicious_trait_impl::SuspiciousImpl);
476 reg.register_early_lint_pass(box cargo_common_metadata::Pass);
477 reg.register_early_lint_pass(box multiple_crate_versions::Pass);
478 reg.register_early_lint_pass(box wildcard_dependencies::Pass);
479 reg.register_late_lint_pass(box map_unit_fn::Pass);
480 reg.register_late_lint_pass(box infallible_destructuring_match::Pass);
481 reg.register_late_lint_pass(box inherent_impl::Pass::default());
482 reg.register_late_lint_pass(box neg_cmp_op_on_partial_ord::NoNegCompOpForPartialOrd);
483 reg.register_late_lint_pass(box unwrap::Pass);
484 reg.register_late_lint_pass(box duration_subsec::DurationSubsec);
485 reg.register_late_lint_pass(box default_trait_access::DefaultTraitAccess);
486 reg.register_late_lint_pass(box indexing_slicing::IndexingSlicing);
487 reg.register_late_lint_pass(box non_copy_const::NonCopyConst);
488 reg.register_late_lint_pass(box ptr_offset_with_cast::Pass);
489 reg.register_late_lint_pass(box redundant_clone::RedundantClone);
490 reg.register_late_lint_pass(box slow_vector_initialization::Pass);
491 reg.register_late_lint_pass(box types::RefToMut);
492 reg.register_late_lint_pass(box assertions_on_constants::AssertionsOnConstants);
493 reg.register_late_lint_pass(box missing_const_for_fn::MissingConstForFn);
495 reg.register_lint_group("clippy::restriction", Some("clippy_restriction"), vec![
496 arithmetic::FLOAT_ARITHMETIC,
497 arithmetic::INTEGER_ARITHMETIC,
498 else_if_without_else::ELSE_IF_WITHOUT_ELSE,
499 implicit_return::IMPLICIT_RETURN,
500 indexing_slicing::INDEXING_SLICING,
501 inherent_impl::MULTIPLE_INHERENT_IMPL,
502 literal_representation::DECIMAL_LITERAL_REPRESENTATION,
503 matches::WILDCARD_ENUM_MATCH_ARM,
504 mem_forget::MEM_FORGET,
505 methods::CLONE_ON_REF_PTR,
506 methods::OPTION_UNWRAP_USED,
507 methods::RESULT_UNWRAP_USED,
508 methods::WRONG_PUB_SELF_CONVENTION,
509 misc::FLOAT_CMP_CONST,
510 missing_doc::MISSING_DOCS_IN_PRIVATE_ITEMS,
511 missing_inline::MISSING_INLINE_IN_PUBLIC_ITEMS,
512 panic_unimplemented::UNIMPLEMENTED,
513 shadow::SHADOW_REUSE,
520 reg.register_lint_group("clippy::pedantic", Some("clippy_pedantic"), vec![
521 attrs::INLINE_ALWAYS,
522 copies::MATCH_SAME_ARMS,
523 copy_iterator::COPY_ITERATOR,
524 default_trait_access::DEFAULT_TRAIT_ACCESS,
525 derive::EXPL_IMPL_CLONE_ON_COPY,
527 empty_enum::EMPTY_ENUM,
528 enum_glob_use::ENUM_GLOB_USE,
529 enum_variants::MODULE_NAME_REPETITIONS,
530 enum_variants::PUB_ENUM_VARIANT_NAMES,
531 functions::TOO_MANY_LINES,
532 if_not_else::IF_NOT_ELSE,
533 infinite_iter::MAYBE_INFINITE_ITER,
534 items_after_statements::ITEMS_AFTER_STATEMENTS,
535 literal_representation::LARGE_DIGIT_GROUPS,
536 loops::EXPLICIT_INTO_ITER_LOOP,
537 loops::EXPLICIT_ITER_LOOP,
538 matches::SINGLE_MATCH_ELSE,
540 methods::MAP_FLATTEN,
541 methods::OPTION_MAP_UNWRAP_OR,
542 methods::OPTION_MAP_UNWRAP_OR_ELSE,
543 methods::RESULT_MAP_UNWRAP_OR_ELSE,
544 misc::USED_UNDERSCORE_BINDING,
545 misc_early::UNSEPARATED_LITERAL_SUFFIX,
547 needless_continue::NEEDLESS_CONTINUE,
548 needless_pass_by_value::NEEDLESS_PASS_BY_VALUE,
549 non_expressive_names::SIMILAR_NAMES,
550 replace_consts::REPLACE_CONSTS,
551 shadow::SHADOW_UNRELATED,
552 strings::STRING_ADD_ASSIGN,
553 types::CAST_POSSIBLE_TRUNCATION,
554 types::CAST_POSSIBLE_WRAP,
555 types::CAST_PRECISION_LOSS,
556 types::CAST_SIGN_LOSS,
557 types::INVALID_UPCAST_COMPARISONS,
559 unicode::NON_ASCII_LITERAL,
560 unicode::UNICODE_NOT_NFC,
564 reg.register_lint_group("clippy::internal", Some("clippy_internal"), vec![
565 utils::internal_lints::CLIPPY_LINTS_INTERNAL,
566 utils::internal_lints::COMPILER_LINT_FUNCTIONS,
567 utils::internal_lints::DEFAULT_HASH_TYPES,
568 utils::internal_lints::LINT_WITHOUT_LINT_PASS,
571 reg.register_lint_group("clippy::all", Some("clippy"), vec![
572 approx_const::APPROX_CONSTANT,
573 assertions_on_constants::ASSERTIONS_ON_CONSTANTS,
574 assign_ops::ASSIGN_OP_PATTERN,
575 assign_ops::MISREFACTORED_ASSIGN_OP,
576 attrs::DEPRECATED_CFG_ATTR,
577 attrs::DEPRECATED_SEMVER,
578 attrs::UNKNOWN_CLIPPY_LINTS,
579 attrs::USELESS_ATTRIBUTE,
580 bit_mask::BAD_BIT_MASK,
581 bit_mask::INEFFECTIVE_BIT_MASK,
582 bit_mask::VERBOSE_BIT_MASK,
583 blacklisted_name::BLACKLISTED_NAME,
584 block_in_if_condition::BLOCK_IN_IF_CONDITION_EXPR,
585 block_in_if_condition::BLOCK_IN_IF_CONDITION_STMT,
587 booleans::NONMINIMAL_BOOL,
588 bytecount::NAIVE_BYTECOUNT,
589 collapsible_if::COLLAPSIBLE_IF,
590 const_static_lifetime::CONST_STATIC_LIFETIME,
591 copies::IFS_SAME_COND,
592 copies::IF_SAME_THEN_ELSE,
593 cyclomatic_complexity::CYCLOMATIC_COMPLEXITY,
594 derive::DERIVE_HASH_XOR_EQ,
595 double_comparison::DOUBLE_COMPARISONS,
596 double_parens::DOUBLE_PARENS,
597 drop_forget_ref::DROP_COPY,
598 drop_forget_ref::DROP_REF,
599 drop_forget_ref::FORGET_COPY,
600 drop_forget_ref::FORGET_REF,
601 duration_subsec::DURATION_SUBSEC,
603 enum_clike::ENUM_CLIKE_UNPORTABLE_VARIANT,
604 enum_variants::ENUM_VARIANT_NAMES,
605 enum_variants::MODULE_INCEPTION,
608 erasing_op::ERASING_OP,
610 eta_reduction::REDUNDANT_CLOSURE,
611 eval_order_dependence::DIVERGING_SUB_EXPRESSION,
612 eval_order_dependence::EVAL_ORDER_DEPENDENCE,
613 excessive_precision::EXCESSIVE_PRECISION,
614 explicit_write::EXPLICIT_WRITE,
615 format::USELESS_FORMAT,
616 formatting::POSSIBLE_MISSING_COMMA,
617 formatting::SUSPICIOUS_ASSIGNMENT_FORMATTING,
618 formatting::SUSPICIOUS_ELSE_FORMATTING,
619 functions::NOT_UNSAFE_PTR_ARG_DEREF,
620 functions::TOO_MANY_ARGUMENTS,
621 identity_conversion::IDENTITY_CONVERSION,
622 identity_op::IDENTITY_OP,
623 indexing_slicing::OUT_OF_BOUNDS_INDEXING,
624 infallible_destructuring_match::INFALLIBLE_DESTRUCTURING_MATCH,
625 infinite_iter::INFINITE_ITER,
626 inline_fn_without_body::INLINE_FN_WITHOUT_BODY,
627 int_plus_one::INT_PLUS_ONE,
628 invalid_ref::INVALID_REF,
629 large_enum_variant::LARGE_ENUM_VARIANT,
630 len_zero::LEN_WITHOUT_IS_EMPTY,
632 let_if_seq::USELESS_LET_IF_SEQ,
633 lifetimes::EXTRA_UNUSED_LIFETIMES,
634 lifetimes::NEEDLESS_LIFETIMES,
635 literal_representation::INCONSISTENT_DIGIT_GROUPING,
636 literal_representation::MISTYPED_LITERAL_SUFFIXES,
637 literal_representation::UNREADABLE_LITERAL,
639 loops::EXPLICIT_COUNTER_LOOP,
641 loops::FOR_LOOP_OVER_OPTION,
642 loops::FOR_LOOP_OVER_RESULT,
643 loops::ITER_NEXT_LOOP,
644 loops::MANUAL_MEMCPY,
645 loops::MUT_RANGE_BOUND,
646 loops::NEEDLESS_COLLECT,
647 loops::NEEDLESS_RANGE_LOOP,
649 loops::REVERSE_RANGE_LOOP,
650 loops::UNUSED_COLLECT,
651 loops::WHILE_IMMUTABLE_CONDITION,
652 loops::WHILE_LET_LOOP,
653 loops::WHILE_LET_ON_ITERATOR,
654 map_clone::MAP_CLONE,
655 map_unit_fn::OPTION_MAP_UNIT_FN,
656 map_unit_fn::RESULT_MAP_UNIT_FN,
657 matches::MATCH_AS_REF,
659 matches::MATCH_OVERLAPPING_ARM,
660 matches::MATCH_REF_PATS,
661 matches::MATCH_WILD_ERR_ARM,
662 matches::SINGLE_MATCH,
663 mem_discriminant::MEM_DISCRIMINANT_NON_ENUM,
664 mem_replace::MEM_REPLACE_OPTION_WITH_NONE,
665 methods::CHARS_LAST_CMP,
666 methods::CHARS_NEXT_CMP,
667 methods::CLONE_DOUBLE_REF,
668 methods::CLONE_ON_COPY,
669 methods::EXPECT_FUN_CALL,
670 methods::FILTER_NEXT,
672 methods::INTO_ITER_ON_ARRAY,
673 methods::INTO_ITER_ON_REF,
674 methods::ITER_CLONED_COLLECT,
676 methods::ITER_SKIP_NEXT,
677 methods::NEW_RET_NO_SELF,
679 methods::OPTION_MAP_OR_NONE,
680 methods::OR_FUN_CALL,
681 methods::SEARCH_IS_SOME,
682 methods::SHOULD_IMPLEMENT_TRAIT,
683 methods::SINGLE_CHAR_PATTERN,
684 methods::STRING_EXTEND_CHARS,
685 methods::TEMPORARY_CSTRING_AS_PTR,
686 methods::UNNECESSARY_FILTER_MAP,
687 methods::UNNECESSARY_FOLD,
688 methods::USELESS_ASREF,
689 methods::WRONG_SELF_CONVENTION,
695 misc::REDUNDANT_PATTERN,
696 misc::SHORT_CIRCUIT_STATEMENT,
697 misc::TOPLEVEL_REF_ARG,
699 misc_early::BUILTIN_TYPE_SHADOW,
700 misc_early::DOUBLE_NEG,
701 misc_early::DUPLICATE_UNDERSCORE_ARGUMENT,
702 misc_early::MIXED_CASE_HEX_LITERALS,
703 misc_early::REDUNDANT_CLOSURE_CALL,
704 misc_early::UNNEEDED_FIELD_PATTERN,
705 misc_early::ZERO_PREFIXED_LITERAL,
706 mut_reference::UNNECESSARY_MUT_PASSED,
707 mutex_atomic::MUTEX_ATOMIC,
708 needless_bool::BOOL_COMPARISON,
709 needless_bool::NEEDLESS_BOOL,
710 needless_borrowed_ref::NEEDLESS_BORROWED_REFERENCE,
711 needless_update::NEEDLESS_UPDATE,
712 neg_cmp_op_on_partial_ord::NEG_CMP_OP_ON_PARTIAL_ORD,
713 neg_multiply::NEG_MULTIPLY,
714 new_without_default::NEW_WITHOUT_DEFAULT,
715 no_effect::NO_EFFECT,
716 no_effect::UNNECESSARY_OPERATION,
717 non_copy_const::BORROW_INTERIOR_MUTABLE_CONST,
718 non_copy_const::DECLARE_INTERIOR_MUTABLE_CONST,
719 non_expressive_names::JUST_UNDERSCORES_AND_DIGITS,
720 non_expressive_names::MANY_SINGLE_CHAR_NAMES,
721 ok_if_let::IF_LET_SOME_RESULT,
722 open_options::NONSENSICAL_OPEN_OPTIONS,
723 overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL,
724 panic_unimplemented::PANIC_PARAMS,
725 partialeq_ne_impl::PARTIALEQ_NE_IMPL,
726 precedence::PRECEDENCE,
730 ptr_offset_with_cast::PTR_OFFSET_WITH_CAST,
731 question_mark::QUESTION_MARK,
732 ranges::ITERATOR_STEP_BY_ZERO,
733 ranges::RANGE_MINUS_ONE,
734 ranges::RANGE_PLUS_ONE,
735 ranges::RANGE_ZIP_WITH_LEN,
736 redundant_field_names::REDUNDANT_FIELD_NAMES,
737 redundant_pattern_matching::REDUNDANT_PATTERN_MATCHING,
738 reference::DEREF_ADDROF,
739 reference::REF_IN_DEREF,
740 regex::INVALID_REGEX,
742 regex::TRIVIAL_REGEX,
743 returns::LET_AND_RETURN,
744 returns::NEEDLESS_RETURN,
745 returns::UNUSED_UNIT,
746 serde_api::SERDE_API_MISUSE,
747 slow_vector_initialization::SLOW_VECTOR_INITIALIZATION,
748 strings::STRING_LIT_AS_BYTES,
749 suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL,
750 suspicious_trait_impl::SUSPICIOUS_OP_ASSIGN_IMPL,
751 swap::ALMOST_SWAPPED,
753 temporary_assignment::TEMPORARY_ASSIGNMENT,
754 transmute::CROSSPOINTER_TRANSMUTE,
755 transmute::TRANSMUTE_BYTES_TO_STR,
756 transmute::TRANSMUTE_INT_TO_BOOL,
757 transmute::TRANSMUTE_INT_TO_CHAR,
758 transmute::TRANSMUTE_INT_TO_FLOAT,
759 transmute::TRANSMUTE_PTR_TO_PTR,
760 transmute::TRANSMUTE_PTR_TO_REF,
761 transmute::USELESS_TRANSMUTE,
762 transmute::WRONG_TRANSMUTE,
763 trivially_copy_pass_by_ref::TRIVIALLY_COPY_PASS_BY_REF,
764 types::ABSURD_EXTREME_COMPARISONS,
767 types::CAST_LOSSLESS,
768 types::CAST_PTR_ALIGNMENT,
769 types::CAST_REF_TO_MUT,
770 types::CHAR_LIT_AS_U8,
771 types::FN_TO_NUMERIC_CAST,
772 types::FN_TO_NUMERIC_CAST_WITH_TRUNCATION,
773 types::IMPLICIT_HASHER,
774 types::LET_UNIT_VALUE,
775 types::OPTION_OPTION,
776 types::TYPE_COMPLEXITY,
779 types::UNNECESSARY_CAST,
781 unicode::ZERO_WIDTH_SPACE,
782 unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME,
783 unused_io_amount::UNUSED_IO_AMOUNT,
784 unused_label::UNUSED_LABEL,
786 write::PRINTLN_EMPTY_STRING,
787 write::PRINT_LITERAL,
788 write::PRINT_WITH_NEWLINE,
789 write::WRITELN_EMPTY_STRING,
790 write::WRITE_LITERAL,
791 write::WRITE_WITH_NEWLINE,
792 zero_div_zero::ZERO_DIVIDED_BY_ZERO,
795 reg.register_lint_group("clippy::style", Some("clippy_style"), vec![
796 assertions_on_constants::ASSERTIONS_ON_CONSTANTS,
797 assign_ops::ASSIGN_OP_PATTERN,
798 attrs::UNKNOWN_CLIPPY_LINTS,
799 bit_mask::VERBOSE_BIT_MASK,
800 blacklisted_name::BLACKLISTED_NAME,
801 block_in_if_condition::BLOCK_IN_IF_CONDITION_EXPR,
802 block_in_if_condition::BLOCK_IN_IF_CONDITION_STMT,
803 collapsible_if::COLLAPSIBLE_IF,
804 const_static_lifetime::CONST_STATIC_LIFETIME,
805 enum_variants::ENUM_VARIANT_NAMES,
806 enum_variants::MODULE_INCEPTION,
808 eta_reduction::REDUNDANT_CLOSURE,
809 excessive_precision::EXCESSIVE_PRECISION,
810 formatting::SUSPICIOUS_ASSIGNMENT_FORMATTING,
811 formatting::SUSPICIOUS_ELSE_FORMATTING,
812 infallible_destructuring_match::INFALLIBLE_DESTRUCTURING_MATCH,
813 len_zero::LEN_WITHOUT_IS_EMPTY,
815 let_if_seq::USELESS_LET_IF_SEQ,
816 literal_representation::INCONSISTENT_DIGIT_GROUPING,
817 literal_representation::UNREADABLE_LITERAL,
820 loops::NEEDLESS_RANGE_LOOP,
821 loops::WHILE_LET_ON_ITERATOR,
822 map_clone::MAP_CLONE,
824 matches::MATCH_OVERLAPPING_ARM,
825 matches::MATCH_REF_PATS,
826 matches::MATCH_WILD_ERR_ARM,
827 matches::SINGLE_MATCH,
828 mem_replace::MEM_REPLACE_OPTION_WITH_NONE,
829 methods::CHARS_LAST_CMP,
831 methods::INTO_ITER_ON_REF,
832 methods::ITER_CLONED_COLLECT,
833 methods::ITER_SKIP_NEXT,
834 methods::NEW_RET_NO_SELF,
836 methods::OPTION_MAP_OR_NONE,
837 methods::SHOULD_IMPLEMENT_TRAIT,
838 methods::STRING_EXTEND_CHARS,
839 methods::UNNECESSARY_FOLD,
840 methods::WRONG_SELF_CONVENTION,
841 misc::REDUNDANT_PATTERN,
842 misc::TOPLEVEL_REF_ARG,
844 misc_early::BUILTIN_TYPE_SHADOW,
845 misc_early::DOUBLE_NEG,
846 misc_early::DUPLICATE_UNDERSCORE_ARGUMENT,
847 misc_early::MIXED_CASE_HEX_LITERALS,
848 misc_early::UNNEEDED_FIELD_PATTERN,
849 mut_reference::UNNECESSARY_MUT_PASSED,
850 neg_multiply::NEG_MULTIPLY,
851 new_without_default::NEW_WITHOUT_DEFAULT,
852 non_expressive_names::JUST_UNDERSCORES_AND_DIGITS,
853 non_expressive_names::MANY_SINGLE_CHAR_NAMES,
854 ok_if_let::IF_LET_SOME_RESULT,
855 panic_unimplemented::PANIC_PARAMS,
858 question_mark::QUESTION_MARK,
859 redundant_field_names::REDUNDANT_FIELD_NAMES,
860 redundant_pattern_matching::REDUNDANT_PATTERN_MATCHING,
862 regex::TRIVIAL_REGEX,
863 returns::LET_AND_RETURN,
864 returns::NEEDLESS_RETURN,
865 returns::UNUSED_UNIT,
866 strings::STRING_LIT_AS_BYTES,
867 types::FN_TO_NUMERIC_CAST,
868 types::FN_TO_NUMERIC_CAST_WITH_TRUNCATION,
869 types::IMPLICIT_HASHER,
870 types::LET_UNIT_VALUE,
871 unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME,
872 write::PRINTLN_EMPTY_STRING,
873 write::PRINT_LITERAL,
874 write::PRINT_WITH_NEWLINE,
875 write::WRITELN_EMPTY_STRING,
876 write::WRITE_LITERAL,
877 write::WRITE_WITH_NEWLINE,
880 reg.register_lint_group("clippy::complexity", Some("clippy_complexity"), vec![
881 assign_ops::MISREFACTORED_ASSIGN_OP,
882 attrs::DEPRECATED_CFG_ATTR,
883 booleans::NONMINIMAL_BOOL,
884 cyclomatic_complexity::CYCLOMATIC_COMPLEXITY,
885 double_comparison::DOUBLE_COMPARISONS,
886 double_parens::DOUBLE_PARENS,
887 duration_subsec::DURATION_SUBSEC,
888 eval_order_dependence::DIVERGING_SUB_EXPRESSION,
889 eval_order_dependence::EVAL_ORDER_DEPENDENCE,
890 explicit_write::EXPLICIT_WRITE,
891 format::USELESS_FORMAT,
892 functions::TOO_MANY_ARGUMENTS,
893 identity_conversion::IDENTITY_CONVERSION,
894 identity_op::IDENTITY_OP,
895 int_plus_one::INT_PLUS_ONE,
896 lifetimes::EXTRA_UNUSED_LIFETIMES,
897 lifetimes::NEEDLESS_LIFETIMES,
898 loops::EXPLICIT_COUNTER_LOOP,
899 loops::MUT_RANGE_BOUND,
900 loops::WHILE_LET_LOOP,
901 map_unit_fn::OPTION_MAP_UNIT_FN,
902 map_unit_fn::RESULT_MAP_UNIT_FN,
903 matches::MATCH_AS_REF,
904 methods::CHARS_NEXT_CMP,
905 methods::CLONE_ON_COPY,
906 methods::FILTER_NEXT,
907 methods::SEARCH_IS_SOME,
908 methods::UNNECESSARY_FILTER_MAP,
909 methods::USELESS_ASREF,
910 misc::SHORT_CIRCUIT_STATEMENT,
911 misc_early::REDUNDANT_CLOSURE_CALL,
912 misc_early::ZERO_PREFIXED_LITERAL,
913 needless_bool::BOOL_COMPARISON,
914 needless_bool::NEEDLESS_BOOL,
915 needless_borrowed_ref::NEEDLESS_BORROWED_REFERENCE,
916 needless_update::NEEDLESS_UPDATE,
917 neg_cmp_op_on_partial_ord::NEG_CMP_OP_ON_PARTIAL_ORD,
918 no_effect::NO_EFFECT,
919 no_effect::UNNECESSARY_OPERATION,
920 overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL,
921 partialeq_ne_impl::PARTIALEQ_NE_IMPL,
922 precedence::PRECEDENCE,
923 ptr_offset_with_cast::PTR_OFFSET_WITH_CAST,
924 ranges::RANGE_MINUS_ONE,
925 ranges::RANGE_PLUS_ONE,
926 ranges::RANGE_ZIP_WITH_LEN,
927 reference::DEREF_ADDROF,
928 reference::REF_IN_DEREF,
930 temporary_assignment::TEMPORARY_ASSIGNMENT,
931 transmute::CROSSPOINTER_TRANSMUTE,
932 transmute::TRANSMUTE_BYTES_TO_STR,
933 transmute::TRANSMUTE_INT_TO_BOOL,
934 transmute::TRANSMUTE_INT_TO_CHAR,
935 transmute::TRANSMUTE_INT_TO_FLOAT,
936 transmute::TRANSMUTE_PTR_TO_PTR,
937 transmute::TRANSMUTE_PTR_TO_REF,
938 transmute::USELESS_TRANSMUTE,
940 types::CAST_LOSSLESS,
941 types::CHAR_LIT_AS_U8,
942 types::OPTION_OPTION,
943 types::TYPE_COMPLEXITY,
945 types::UNNECESSARY_CAST,
947 unused_label::UNUSED_LABEL,
948 zero_div_zero::ZERO_DIVIDED_BY_ZERO,
951 reg.register_lint_group("clippy::correctness", Some("clippy_correctness"), vec![
952 approx_const::APPROX_CONSTANT,
953 attrs::DEPRECATED_SEMVER,
954 attrs::USELESS_ATTRIBUTE,
955 bit_mask::BAD_BIT_MASK,
956 bit_mask::INEFFECTIVE_BIT_MASK,
958 copies::IFS_SAME_COND,
959 copies::IF_SAME_THEN_ELSE,
960 derive::DERIVE_HASH_XOR_EQ,
961 drop_forget_ref::DROP_COPY,
962 drop_forget_ref::DROP_REF,
963 drop_forget_ref::FORGET_COPY,
964 drop_forget_ref::FORGET_REF,
965 enum_clike::ENUM_CLIKE_UNPORTABLE_VARIANT,
967 erasing_op::ERASING_OP,
968 formatting::POSSIBLE_MISSING_COMMA,
969 functions::NOT_UNSAFE_PTR_ARG_DEREF,
970 indexing_slicing::OUT_OF_BOUNDS_INDEXING,
971 infinite_iter::INFINITE_ITER,
972 inline_fn_without_body::INLINE_FN_WITHOUT_BODY,
973 invalid_ref::INVALID_REF,
974 literal_representation::MISTYPED_LITERAL_SUFFIXES,
975 loops::FOR_LOOP_OVER_OPTION,
976 loops::FOR_LOOP_OVER_RESULT,
977 loops::ITER_NEXT_LOOP,
979 loops::REVERSE_RANGE_LOOP,
980 loops::WHILE_IMMUTABLE_CONDITION,
981 mem_discriminant::MEM_DISCRIMINANT_NON_ENUM,
982 methods::CLONE_DOUBLE_REF,
983 methods::INTO_ITER_ON_ARRAY,
984 methods::TEMPORARY_CSTRING_AS_PTR,
989 non_copy_const::BORROW_INTERIOR_MUTABLE_CONST,
990 non_copy_const::DECLARE_INTERIOR_MUTABLE_CONST,
991 open_options::NONSENSICAL_OPEN_OPTIONS,
993 ranges::ITERATOR_STEP_BY_ZERO,
994 regex::INVALID_REGEX,
995 serde_api::SERDE_API_MISUSE,
996 suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL,
997 suspicious_trait_impl::SUSPICIOUS_OP_ASSIGN_IMPL,
998 swap::ALMOST_SWAPPED,
999 transmute::WRONG_TRANSMUTE,
1000 types::ABSURD_EXTREME_COMPARISONS,
1001 types::CAST_PTR_ALIGNMENT,
1002 types::CAST_REF_TO_MUT,
1004 unicode::ZERO_WIDTH_SPACE,
1005 unused_io_amount::UNUSED_IO_AMOUNT,
1008 reg.register_lint_group("clippy::perf", Some("clippy_perf"), vec![
1009 bytecount::NAIVE_BYTECOUNT,
1011 escape::BOXED_LOCAL,
1012 large_enum_variant::LARGE_ENUM_VARIANT,
1013 loops::MANUAL_MEMCPY,
1014 loops::NEEDLESS_COLLECT,
1015 loops::UNUSED_COLLECT,
1016 methods::EXPECT_FUN_CALL,
1018 methods::OR_FUN_CALL,
1019 methods::SINGLE_CHAR_PATTERN,
1021 mutex_atomic::MUTEX_ATOMIC,
1022 slow_vector_initialization::SLOW_VECTOR_INITIALIZATION,
1023 trivially_copy_pass_by_ref::TRIVIALLY_COPY_PASS_BY_REF,
1028 reg.register_lint_group("clippy::cargo", Some("clippy_cargo"), vec![
1029 cargo_common_metadata::CARGO_COMMON_METADATA,
1030 multiple_crate_versions::MULTIPLE_CRATE_VERSIONS,
1031 wildcard_dependencies::WILDCARD_DEPENDENCIES,
1034 reg.register_lint_group("clippy::nursery", Some("clippy_nursery"), vec![
1035 attrs::EMPTY_LINE_AFTER_OUTER_ATTR,
1036 fallible_impl_from::FALLIBLE_IMPL_FROM,
1037 missing_const_for_fn::MISSING_CONST_FOR_FN,
1038 mutex_atomic::MUTEX_INTEGER,
1039 needless_borrow::NEEDLESS_BORROW,
1040 redundant_clone::REDUNDANT_CLONE,
1041 unwrap::PANICKING_UNWRAP,
1042 unwrap::UNNECESSARY_UNWRAP,
1046 pub fn register_renamed(ls: &mut rustc::lint::LintStore) {
1047 ls.register_renamed("clippy::stutter", "clippy::module_name_repetitions");
1048 ls.register_renamed("clippy::new_without_default_derive", "clippy::new_without_default");
1051 // only exists to let the dogfood integration test works.
1052 // Don't run clippy as an executable directly
1055 panic!("Please use the cargo-clippy executable");