1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
10 // error-pattern:cargo-clippy
12 #![feature(box_syntax)]
13 #![feature(rustc_private)]
14 #![feature(slice_patterns)]
15 #![feature(stmt_expr_attributes)]
16 #![feature(range_contains)]
17 #![feature(str_escape)]
18 #![allow(clippy::missing_docs_in_private_items)]
19 #![recursion_limit = "256"]
20 #![warn(rust_2018_idioms, trivial_casts, trivial_numeric_casts)]
21 #![feature(crate_visibility_modifier)]
23 #![feature(if_while_or_patterns)]
25 // FIXME: switch to something more ergonomic here, once available.
26 // (currently there is no way to opt into sysroot crates w/o `extern crate`)
27 #[allow(unused_extern_crates)]
28 extern crate fmt_macros;
29 #[allow(unused_extern_crates)]
31 #[allow(unused_extern_crates)]
32 extern crate rustc_data_structures;
33 #[allow(unused_extern_crates)]
34 extern crate rustc_errors;
35 #[allow(unused_extern_crates)]
36 extern crate rustc_plugin;
37 #[allow(unused_extern_crates)]
38 extern crate rustc_target;
39 #[allow(unused_extern_crates)]
40 extern crate rustc_typeck;
41 #[allow(unused_extern_crates)]
43 #[allow(unused_extern_crates)]
44 extern crate syntax_pos;
48 // Currently, categories "style", "correctness", "complexity" and "perf" are enabled by default,
49 // as said in the README.md of this repository. If this changes, please update README.md.
51 macro_rules! declare_clippy_lint {
52 { pub $name:tt, style, $description:tt } => {
53 declare_tool_lint! { pub clippy::$name, Warn, $description, report_in_external_macro: true }
55 { pub $name:tt, correctness, $description:tt } => {
56 declare_tool_lint! { pub clippy::$name, Deny, $description, report_in_external_macro: true }
58 { pub $name:tt, complexity, $description:tt } => {
59 declare_tool_lint! { pub clippy::$name, Warn, $description, report_in_external_macro: true }
61 { pub $name:tt, perf, $description:tt } => {
62 declare_tool_lint! { pub clippy::$name, Warn, $description, report_in_external_macro: true }
64 { pub $name:tt, pedantic, $description:tt } => {
65 declare_tool_lint! { pub clippy::$name, Allow, $description, report_in_external_macro: true }
67 { pub $name:tt, restriction, $description:tt } => {
68 declare_tool_lint! { pub clippy::$name, Allow, $description, report_in_external_macro: true }
70 { pub $name:tt, cargo, $description:tt } => {
71 declare_tool_lint! { pub clippy::$name, Allow, $description, report_in_external_macro: true }
73 { pub $name:tt, nursery, $description:tt } => {
74 declare_tool_lint! { pub clippy::$name, Allow, $description, report_in_external_macro: true }
76 { pub $name:tt, internal, $description:tt } => {
77 declare_tool_lint! { pub clippy::$name, Allow, $description, report_in_external_macro: true }
79 { pub $name:tt, internal_warn, $description:tt } => {
80 declare_tool_lint! { pub clippy::$name, Warn, $description, report_in_external_macro: true }
88 // begin lints modules, do not remove this comment, it’s used in `update_lints`
94 pub mod blacklisted_name;
95 pub mod block_in_if_condition;
98 pub mod cargo_common_metadata;
99 pub mod collapsible_if;
100 pub mod const_static_lifetime;
102 pub mod copy_iterator;
103 pub mod cyclomatic_complexity;
104 pub mod default_trait_access;
107 pub mod double_comparison;
108 pub mod double_parens;
109 pub mod drop_forget_ref;
110 pub mod duration_subsec;
111 pub mod else_if_without_else;
115 pub mod enum_glob_use;
116 pub mod enum_variants;
120 pub mod eta_reduction;
121 pub mod eval_order_dependence;
122 pub mod excessive_precision;
123 pub mod explicit_write;
124 pub mod fallible_impl_from;
128 pub mod identity_conversion;
131 pub mod implicit_return;
132 pub mod indexing_slicing;
133 pub mod infallible_destructuring_match;
134 pub mod infinite_iter;
135 pub mod inherent_impl;
136 pub mod inline_fn_without_body;
137 pub mod int_plus_one;
139 pub mod items_after_statements;
140 pub mod large_enum_variant;
144 pub mod literal_representation;
149 pub mod mem_discriminant;
157 pub mod missing_inline;
158 pub mod multiple_crate_versions;
160 pub mod mut_reference;
161 pub mod mutex_atomic;
162 pub mod needless_bool;
163 pub mod needless_borrow;
164 pub mod needless_borrowed_ref;
165 pub mod needless_continue;
166 pub mod needless_pass_by_value;
167 pub mod needless_update;
168 pub mod neg_cmp_op_on_partial_ord;
169 pub mod neg_multiply;
170 pub mod new_without_default;
172 pub mod non_copy_const;
173 pub mod non_expressive_names;
175 pub mod open_options;
176 pub mod overflow_check_conditional;
177 pub mod panic_unimplemented;
178 pub mod partialeq_ne_impl;
181 pub mod ptr_offset_with_cast;
182 pub mod question_mark;
184 pub mod redundant_clone;
185 pub mod redundant_field_names;
186 pub mod redundant_pattern_matching;
189 pub mod replace_consts;
193 pub mod slow_vector_initialization;
195 pub mod suspicious_trait_impl;
197 pub mod temporary_assignment;
199 pub mod trivially_copy_pass_by_ref;
202 pub mod unsafe_removed_from_name;
203 pub mod unused_io_amount;
204 pub mod unused_label;
208 pub mod wildcard_dependencies;
210 pub mod zero_div_zero;
211 // end lints modules, do not remove this comment, it’s used in `update_lints`
213 pub use crate::utils::conf::Conf;
216 crate use syntax::ast::{Name, NodeId};
219 pub fn register_pre_expansion_lints(
220 session: &rustc::session::Session,
221 store: &mut rustc::lint::LintStore,
224 store.register_pre_expansion_pass(Some(session), box write::Pass);
225 store.register_pre_expansion_pass(Some(session), box redundant_field_names::RedundantFieldNames);
226 store.register_pre_expansion_pass(
228 box non_expressive_names::NonExpressiveNames {
229 single_char_binding_names_threshold: conf.single_char_binding_names_threshold,
232 store.register_pre_expansion_pass(Some(session), box attrs::CfgAttrPass);
235 pub fn read_conf(reg: &rustc_plugin::Registry<'_>) -> Conf {
236 match utils::conf::file_from_args(reg.args()) {
238 // if the user specified a file, it must exist, otherwise default to `clippy.toml` but
239 // do not require the file to exist
240 let file_name = if let Some(file_name) = file_name {
243 match utils::conf::lookup_conf_file() {
247 .struct_err(&format!("error finding Clippy's configuration file: {}", error))
254 let file_name = file_name.map(|file_name| {
255 if file_name.is_relative() {
257 .local_crate_source_file
259 .and_then(|file| std::path::Path::new(&file).parent().map(std::path::Path::to_path_buf))
267 let (conf, errors) = utils::conf::read(file_name.as_ref().map(|p| p.as_ref()));
269 // all conf errors are non-fatal, we just use the default conf in case of error
270 for error in errors {
272 .struct_err(&format!(
273 "error reading Clippy's configuration file `{}`: {}",
274 file_name.as_ref().and_then(|p| p.to_str()).unwrap_or(""),
282 Err((err, span)) => {
284 .struct_span_err(span, err)
285 .span_note(span, "Clippy will use default configuration")
287 toml::from_str("").expect("we never error on empty config files")
293 pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
294 let mut store = reg.sess.lint_store.borrow_mut();
295 // begin deprecated lints, do not remove this comment, it’s used in `update_lints`
296 store.register_removed(
298 "`assert!()` will be more flexible with RFC 2011",
300 store.register_removed(
302 "`.extend_from_slice(_)` is a faster way to extend a Vec by a slice",
304 store.register_removed(
305 "range_step_by_zero",
306 "`iterator.step_by(0)` panics nowadays",
308 store.register_removed(
310 "`Vec::as_slice` has been stabilized in 1.7",
312 store.register_removed(
313 "unstable_as_mut_slice",
314 "`Vec::as_mut_slice` has been stabilized in 1.7",
316 store.register_removed(
318 "using `str::to_string` is common even today and specialization will likely happen soon",
320 store.register_removed(
322 "using `string::to_string` is common even today and specialization will likely happen soon",
324 store.register_removed(
325 "misaligned_transmute",
326 "this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr",
328 store.register_removed(
330 "using compound assignment operators (e.g. `+=`) is harmless",
332 store.register_removed(
333 "if_let_redundant_pattern_matching",
334 "this lint has been changed to redundant_pattern_matching",
336 store.register_removed(
337 "unsafe_vector_initialization",
338 "the replacement suggested by this lint had substantially different behavior",
340 // end deprecated lints, do not remove this comment, it’s used in `update_lints`
342 reg.register_late_lint_pass(box serde_api::Serde);
343 reg.register_early_lint_pass(box utils::internal_lints::Clippy);
344 reg.register_late_lint_pass(box utils::internal_lints::CompilerLintFunctions::new());
345 reg.register_early_lint_pass(box utils::internal_lints::DefaultHashTypes::default());
346 reg.register_late_lint_pass(box utils::internal_lints::LintWithoutLintPass::default());
347 reg.register_late_lint_pass(box utils::inspector::Pass);
348 reg.register_late_lint_pass(box utils::author::Pass);
349 reg.register_late_lint_pass(box types::TypePass);
350 reg.register_late_lint_pass(box booleans::NonminimalBool);
351 reg.register_late_lint_pass(box eq_op::EqOp);
352 reg.register_early_lint_pass(box enum_variants::EnumVariantNames::new(conf.enum_variant_name_threshold));
353 reg.register_late_lint_pass(box enum_glob_use::EnumGlobUse);
354 reg.register_late_lint_pass(box enum_clike::UnportableVariant);
355 reg.register_late_lint_pass(box excessive_precision::ExcessivePrecision);
356 reg.register_late_lint_pass(box bit_mask::BitMask::new(conf.verbose_bit_mask_threshold));
357 reg.register_late_lint_pass(box ptr::PointerPass);
358 reg.register_late_lint_pass(box needless_bool::NeedlessBool);
359 reg.register_late_lint_pass(box needless_bool::BoolComparison);
360 reg.register_late_lint_pass(box approx_const::Pass);
361 reg.register_late_lint_pass(box misc::Pass);
362 reg.register_early_lint_pass(box precedence::Precedence);
363 reg.register_early_lint_pass(box needless_continue::NeedlessContinue);
364 reg.register_late_lint_pass(box eta_reduction::EtaPass);
365 reg.register_late_lint_pass(box identity_op::IdentityOp);
366 reg.register_late_lint_pass(box erasing_op::ErasingOp);
367 reg.register_early_lint_pass(box items_after_statements::ItemsAfterStatements);
368 reg.register_late_lint_pass(box mut_mut::MutMut);
369 reg.register_late_lint_pass(box mut_reference::UnnecessaryMutPassed);
370 reg.register_late_lint_pass(box len_zero::LenZero);
371 reg.register_late_lint_pass(box attrs::AttrPass);
372 reg.register_early_lint_pass(box collapsible_if::CollapsibleIf);
373 reg.register_late_lint_pass(box block_in_if_condition::BlockInIfCondition);
374 reg.register_late_lint_pass(box unicode::Unicode);
375 reg.register_late_lint_pass(box strings::StringAdd);
376 reg.register_early_lint_pass(box returns::ReturnPass);
377 reg.register_late_lint_pass(box implicit_return::Pass);
378 reg.register_late_lint_pass(box methods::Pass);
379 reg.register_late_lint_pass(box map_clone::Pass);
380 reg.register_late_lint_pass(box shadow::Pass);
381 reg.register_late_lint_pass(box types::LetPass);
382 reg.register_late_lint_pass(box types::UnitCmp);
383 reg.register_late_lint_pass(box loops::Pass);
384 reg.register_late_lint_pass(box lifetimes::LifetimePass);
385 reg.register_late_lint_pass(box entry::HashMapLint);
386 reg.register_late_lint_pass(box ranges::Pass);
387 reg.register_late_lint_pass(box types::CastPass);
388 reg.register_late_lint_pass(box types::TypeComplexityPass::new(conf.type_complexity_threshold));
389 reg.register_late_lint_pass(box matches::MatchPass);
390 reg.register_late_lint_pass(box minmax::MinMaxPass);
391 reg.register_late_lint_pass(box open_options::NonSensical);
392 reg.register_late_lint_pass(box zero_div_zero::Pass);
393 reg.register_late_lint_pass(box mutex_atomic::MutexAtomic);
394 reg.register_late_lint_pass(box needless_update::Pass);
395 reg.register_late_lint_pass(box needless_borrow::NeedlessBorrow::default());
396 reg.register_late_lint_pass(box needless_borrowed_ref::NeedlessBorrowedRef);
397 reg.register_late_lint_pass(box no_effect::Pass);
398 reg.register_late_lint_pass(box temporary_assignment::Pass);
399 reg.register_late_lint_pass(box transmute::Transmute);
400 reg.register_late_lint_pass(
401 box cyclomatic_complexity::CyclomaticComplexity::new(conf.cyclomatic_complexity_threshold)
403 reg.register_late_lint_pass(box escape::Pass{too_large_for_stack: conf.too_large_for_stack});
404 reg.register_early_lint_pass(box misc_early::MiscEarly);
405 reg.register_late_lint_pass(box panic_unimplemented::Pass);
406 reg.register_late_lint_pass(box strings::StringLitAsBytes);
407 reg.register_late_lint_pass(box derive::Derive);
408 reg.register_late_lint_pass(box types::CharLitAsU8);
409 reg.register_late_lint_pass(box vec::Pass);
410 reg.register_late_lint_pass(box drop_forget_ref::Pass);
411 reg.register_late_lint_pass(box empty_enum::EmptyEnum);
412 reg.register_late_lint_pass(box types::AbsurdExtremeComparisons);
413 reg.register_late_lint_pass(box types::InvalidUpcastComparisons);
414 reg.register_late_lint_pass(box regex::Pass::default());
415 reg.register_late_lint_pass(box copies::CopyAndPaste);
416 reg.register_late_lint_pass(box copy_iterator::CopyIterator);
417 reg.register_late_lint_pass(box format::Pass);
418 reg.register_early_lint_pass(box formatting::Formatting);
419 reg.register_late_lint_pass(box swap::Swap);
420 reg.register_early_lint_pass(box if_not_else::IfNotElse);
421 reg.register_early_lint_pass(box else_if_without_else::ElseIfWithoutElse);
422 reg.register_early_lint_pass(box int_plus_one::IntPlusOne);
423 reg.register_late_lint_pass(box overflow_check_conditional::OverflowCheckConditional);
424 reg.register_late_lint_pass(box unused_label::UnusedLabel);
425 reg.register_late_lint_pass(box new_without_default::NewWithoutDefault::default());
426 reg.register_late_lint_pass(box blacklisted_name::BlackListedName::new(
427 conf.blacklisted_names.iter().cloned().collect()
429 reg.register_late_lint_pass(box functions::Functions::new(conf.too_many_arguments_threshold));
430 reg.register_early_lint_pass(box doc::Doc::new(conf.doc_valid_idents.iter().cloned().collect()));
431 reg.register_late_lint_pass(box neg_multiply::NegMultiply);
432 reg.register_early_lint_pass(box unsafe_removed_from_name::UnsafeNameRemoval);
433 reg.register_late_lint_pass(box mem_discriminant::MemDiscriminant);
434 reg.register_late_lint_pass(box mem_forget::MemForget);
435 reg.register_late_lint_pass(box mem_replace::MemReplace);
436 reg.register_late_lint_pass(box arithmetic::Arithmetic::default());
437 reg.register_late_lint_pass(box assign_ops::AssignOps);
438 reg.register_late_lint_pass(box let_if_seq::LetIfSeq);
439 reg.register_late_lint_pass(box eval_order_dependence::EvalOrderDependence);
440 reg.register_late_lint_pass(box missing_doc::MissingDoc::new());
441 reg.register_late_lint_pass(box missing_inline::MissingInline);
442 reg.register_late_lint_pass(box ok_if_let::Pass);
443 reg.register_late_lint_pass(box redundant_pattern_matching::Pass);
444 reg.register_late_lint_pass(box partialeq_ne_impl::Pass);
445 reg.register_early_lint_pass(box reference::Pass);
446 reg.register_early_lint_pass(box reference::DerefPass);
447 reg.register_early_lint_pass(box double_parens::DoubleParens);
448 reg.register_late_lint_pass(box unused_io_amount::UnusedIoAmount);
449 reg.register_late_lint_pass(box large_enum_variant::LargeEnumVariant::new(conf.enum_variant_size_threshold));
450 reg.register_late_lint_pass(box explicit_write::Pass);
451 reg.register_late_lint_pass(box needless_pass_by_value::NeedlessPassByValue);
452 reg.register_late_lint_pass(box trivially_copy_pass_by_ref::TriviallyCopyPassByRef::new(
453 conf.trivial_copy_size_limit,
456 reg.register_early_lint_pass(box literal_representation::LiteralDigitGrouping);
457 reg.register_early_lint_pass(box literal_representation::LiteralRepresentation::new(
458 conf.literal_representation_threshold
460 reg.register_late_lint_pass(box use_self::UseSelf);
461 reg.register_late_lint_pass(box bytecount::ByteCount);
462 reg.register_late_lint_pass(box infinite_iter::Pass);
463 reg.register_late_lint_pass(box inline_fn_without_body::Pass);
464 reg.register_late_lint_pass(box invalid_ref::InvalidRef);
465 reg.register_late_lint_pass(box identity_conversion::IdentityConversion::default());
466 reg.register_late_lint_pass(box types::ImplicitHasher);
467 reg.register_early_lint_pass(box const_static_lifetime::StaticConst);
468 reg.register_late_lint_pass(box fallible_impl_from::FallibleImplFrom);
469 reg.register_late_lint_pass(box replace_consts::ReplaceConsts);
470 reg.register_late_lint_pass(box types::UnitArg);
471 reg.register_late_lint_pass(box double_comparison::Pass);
472 reg.register_late_lint_pass(box question_mark::Pass);
473 reg.register_late_lint_pass(box suspicious_trait_impl::SuspiciousImpl);
474 reg.register_early_lint_pass(box cargo_common_metadata::Pass);
475 reg.register_early_lint_pass(box multiple_crate_versions::Pass);
476 reg.register_early_lint_pass(box wildcard_dependencies::Pass);
477 reg.register_late_lint_pass(box map_unit_fn::Pass);
478 reg.register_late_lint_pass(box infallible_destructuring_match::Pass);
479 reg.register_late_lint_pass(box inherent_impl::Pass::default());
480 reg.register_late_lint_pass(box neg_cmp_op_on_partial_ord::NoNegCompOpForPartialOrd);
481 reg.register_late_lint_pass(box unwrap::Pass);
482 reg.register_late_lint_pass(box duration_subsec::DurationSubsec);
483 reg.register_late_lint_pass(box default_trait_access::DefaultTraitAccess);
484 reg.register_late_lint_pass(box indexing_slicing::IndexingSlicing);
485 reg.register_late_lint_pass(box non_copy_const::NonCopyConst);
486 reg.register_late_lint_pass(box ptr_offset_with_cast::Pass);
487 reg.register_late_lint_pass(box redundant_clone::RedundantClone);
488 reg.register_late_lint_pass(box slow_vector_initialization::Pass);
489 reg.register_late_lint_pass(box types::RefToMut);
491 reg.register_lint_group("clippy::restriction", Some("clippy_restriction"), vec![
492 arithmetic::FLOAT_ARITHMETIC,
493 arithmetic::INTEGER_ARITHMETIC,
494 else_if_without_else::ELSE_IF_WITHOUT_ELSE,
495 implicit_return::IMPLICIT_RETURN,
496 indexing_slicing::INDEXING_SLICING,
497 inherent_impl::MULTIPLE_INHERENT_IMPL,
498 literal_representation::DECIMAL_LITERAL_REPRESENTATION,
499 mem_forget::MEM_FORGET,
500 methods::CLONE_ON_REF_PTR,
501 methods::OPTION_UNWRAP_USED,
502 methods::RESULT_UNWRAP_USED,
503 methods::WRONG_PUB_SELF_CONVENTION,
504 misc::FLOAT_CMP_CONST,
505 missing_doc::MISSING_DOCS_IN_PRIVATE_ITEMS,
506 missing_inline::MISSING_INLINE_IN_PUBLIC_ITEMS,
507 panic_unimplemented::UNIMPLEMENTED,
508 shadow::SHADOW_REUSE,
515 reg.register_lint_group("clippy::pedantic", Some("clippy_pedantic"), vec![
516 attrs::INLINE_ALWAYS,
517 copies::MATCH_SAME_ARMS,
518 copy_iterator::COPY_ITERATOR,
519 default_trait_access::DEFAULT_TRAIT_ACCESS,
520 derive::EXPL_IMPL_CLONE_ON_COPY,
522 empty_enum::EMPTY_ENUM,
523 enum_glob_use::ENUM_GLOB_USE,
524 enum_variants::MODULE_NAME_REPETITIONS,
525 enum_variants::PUB_ENUM_VARIANT_NAMES,
526 if_not_else::IF_NOT_ELSE,
527 infinite_iter::MAYBE_INFINITE_ITER,
528 items_after_statements::ITEMS_AFTER_STATEMENTS,
529 literal_representation::LARGE_DIGIT_GROUPS,
530 loops::EXPLICIT_INTO_ITER_LOOP,
531 loops::EXPLICIT_ITER_LOOP,
532 matches::SINGLE_MATCH_ELSE,
534 methods::MAP_FLATTEN,
535 methods::OPTION_MAP_UNWRAP_OR,
536 methods::OPTION_MAP_UNWRAP_OR_ELSE,
537 methods::RESULT_MAP_UNWRAP_OR_ELSE,
538 misc::USED_UNDERSCORE_BINDING,
539 misc_early::UNSEPARATED_LITERAL_SUFFIX,
541 needless_continue::NEEDLESS_CONTINUE,
542 needless_pass_by_value::NEEDLESS_PASS_BY_VALUE,
543 non_expressive_names::SIMILAR_NAMES,
544 replace_consts::REPLACE_CONSTS,
545 shadow::SHADOW_UNRELATED,
546 strings::STRING_ADD_ASSIGN,
547 types::CAST_POSSIBLE_TRUNCATION,
548 types::CAST_POSSIBLE_WRAP,
549 types::CAST_PRECISION_LOSS,
550 types::CAST_SIGN_LOSS,
551 types::INVALID_UPCAST_COMPARISONS,
553 unicode::NON_ASCII_LITERAL,
554 unicode::UNICODE_NOT_NFC,
558 reg.register_lint_group("clippy::internal", Some("clippy_internal"), vec![
559 utils::internal_lints::CLIPPY_LINTS_INTERNAL,
560 utils::internal_lints::COMPILER_LINT_FUNCTIONS,
561 utils::internal_lints::DEFAULT_HASH_TYPES,
562 utils::internal_lints::LINT_WITHOUT_LINT_PASS,
565 reg.register_lint_group("clippy::all", Some("clippy"), vec![
566 approx_const::APPROX_CONSTANT,
567 assign_ops::ASSIGN_OP_PATTERN,
568 assign_ops::MISREFACTORED_ASSIGN_OP,
569 attrs::DEPRECATED_CFG_ATTR,
570 attrs::DEPRECATED_SEMVER,
571 attrs::UNKNOWN_CLIPPY_LINTS,
572 attrs::USELESS_ATTRIBUTE,
573 bit_mask::BAD_BIT_MASK,
574 bit_mask::INEFFECTIVE_BIT_MASK,
575 bit_mask::VERBOSE_BIT_MASK,
576 blacklisted_name::BLACKLISTED_NAME,
577 block_in_if_condition::BLOCK_IN_IF_CONDITION_EXPR,
578 block_in_if_condition::BLOCK_IN_IF_CONDITION_STMT,
580 booleans::NONMINIMAL_BOOL,
581 bytecount::NAIVE_BYTECOUNT,
582 collapsible_if::COLLAPSIBLE_IF,
583 const_static_lifetime::CONST_STATIC_LIFETIME,
584 copies::IFS_SAME_COND,
585 copies::IF_SAME_THEN_ELSE,
586 cyclomatic_complexity::CYCLOMATIC_COMPLEXITY,
587 derive::DERIVE_HASH_XOR_EQ,
588 double_comparison::DOUBLE_COMPARISONS,
589 double_parens::DOUBLE_PARENS,
590 drop_forget_ref::DROP_COPY,
591 drop_forget_ref::DROP_REF,
592 drop_forget_ref::FORGET_COPY,
593 drop_forget_ref::FORGET_REF,
594 duration_subsec::DURATION_SUBSEC,
596 enum_clike::ENUM_CLIKE_UNPORTABLE_VARIANT,
597 enum_variants::ENUM_VARIANT_NAMES,
598 enum_variants::MODULE_INCEPTION,
601 erasing_op::ERASING_OP,
603 eta_reduction::REDUNDANT_CLOSURE,
604 eval_order_dependence::DIVERGING_SUB_EXPRESSION,
605 eval_order_dependence::EVAL_ORDER_DEPENDENCE,
606 excessive_precision::EXCESSIVE_PRECISION,
607 explicit_write::EXPLICIT_WRITE,
608 format::USELESS_FORMAT,
609 formatting::POSSIBLE_MISSING_COMMA,
610 formatting::SUSPICIOUS_ASSIGNMENT_FORMATTING,
611 formatting::SUSPICIOUS_ELSE_FORMATTING,
612 functions::NOT_UNSAFE_PTR_ARG_DEREF,
613 functions::TOO_MANY_ARGUMENTS,
614 identity_conversion::IDENTITY_CONVERSION,
615 identity_op::IDENTITY_OP,
616 indexing_slicing::OUT_OF_BOUNDS_INDEXING,
617 infallible_destructuring_match::INFALLIBLE_DESTRUCTURING_MATCH,
618 infinite_iter::INFINITE_ITER,
619 inline_fn_without_body::INLINE_FN_WITHOUT_BODY,
620 int_plus_one::INT_PLUS_ONE,
621 invalid_ref::INVALID_REF,
622 large_enum_variant::LARGE_ENUM_VARIANT,
623 len_zero::LEN_WITHOUT_IS_EMPTY,
625 let_if_seq::USELESS_LET_IF_SEQ,
626 lifetimes::EXTRA_UNUSED_LIFETIMES,
627 lifetimes::NEEDLESS_LIFETIMES,
628 literal_representation::INCONSISTENT_DIGIT_GROUPING,
629 literal_representation::MISTYPED_LITERAL_SUFFIXES,
630 literal_representation::UNREADABLE_LITERAL,
632 loops::EXPLICIT_COUNTER_LOOP,
634 loops::FOR_LOOP_OVER_OPTION,
635 loops::FOR_LOOP_OVER_RESULT,
636 loops::ITER_NEXT_LOOP,
637 loops::MANUAL_MEMCPY,
638 loops::MUT_RANGE_BOUND,
639 loops::NEEDLESS_COLLECT,
640 loops::NEEDLESS_RANGE_LOOP,
642 loops::REVERSE_RANGE_LOOP,
643 loops::UNUSED_COLLECT,
644 loops::WHILE_IMMUTABLE_CONDITION,
645 loops::WHILE_LET_LOOP,
646 loops::WHILE_LET_ON_ITERATOR,
647 map_clone::MAP_CLONE,
648 map_unit_fn::OPTION_MAP_UNIT_FN,
649 map_unit_fn::RESULT_MAP_UNIT_FN,
650 matches::MATCH_AS_REF,
652 matches::MATCH_OVERLAPPING_ARM,
653 matches::MATCH_REF_PATS,
654 matches::MATCH_WILD_ERR_ARM,
655 matches::SINGLE_MATCH,
656 mem_discriminant::MEM_DISCRIMINANT_NON_ENUM,
657 mem_replace::MEM_REPLACE_OPTION_WITH_NONE,
658 methods::CHARS_LAST_CMP,
659 methods::CHARS_NEXT_CMP,
660 methods::CLONE_DOUBLE_REF,
661 methods::CLONE_ON_COPY,
662 methods::EXPECT_FUN_CALL,
663 methods::FILTER_NEXT,
665 methods::INTO_ITER_ON_ARRAY,
666 methods::INTO_ITER_ON_REF,
667 methods::ITER_CLONED_COLLECT,
669 methods::ITER_SKIP_NEXT,
670 methods::NEW_RET_NO_SELF,
672 methods::OPTION_MAP_OR_NONE,
673 methods::OR_FUN_CALL,
674 methods::SEARCH_IS_SOME,
675 methods::SHOULD_IMPLEMENT_TRAIT,
676 methods::SINGLE_CHAR_PATTERN,
677 methods::STRING_EXTEND_CHARS,
678 methods::TEMPORARY_CSTRING_AS_PTR,
679 methods::UNNECESSARY_FILTER_MAP,
680 methods::UNNECESSARY_FOLD,
681 methods::USELESS_ASREF,
682 methods::WRONG_SELF_CONVENTION,
688 misc::REDUNDANT_PATTERN,
689 misc::SHORT_CIRCUIT_STATEMENT,
690 misc::TOPLEVEL_REF_ARG,
692 misc_early::BUILTIN_TYPE_SHADOW,
693 misc_early::DOUBLE_NEG,
694 misc_early::DUPLICATE_UNDERSCORE_ARGUMENT,
695 misc_early::MIXED_CASE_HEX_LITERALS,
696 misc_early::REDUNDANT_CLOSURE_CALL,
697 misc_early::UNNEEDED_FIELD_PATTERN,
698 misc_early::ZERO_PREFIXED_LITERAL,
699 mut_reference::UNNECESSARY_MUT_PASSED,
700 mutex_atomic::MUTEX_ATOMIC,
701 needless_bool::BOOL_COMPARISON,
702 needless_bool::NEEDLESS_BOOL,
703 needless_borrowed_ref::NEEDLESS_BORROWED_REFERENCE,
704 needless_update::NEEDLESS_UPDATE,
705 neg_cmp_op_on_partial_ord::NEG_CMP_OP_ON_PARTIAL_ORD,
706 neg_multiply::NEG_MULTIPLY,
707 new_without_default::NEW_WITHOUT_DEFAULT,
708 no_effect::NO_EFFECT,
709 no_effect::UNNECESSARY_OPERATION,
710 non_copy_const::BORROW_INTERIOR_MUTABLE_CONST,
711 non_copy_const::DECLARE_INTERIOR_MUTABLE_CONST,
712 non_expressive_names::JUST_UNDERSCORES_AND_DIGITS,
713 non_expressive_names::MANY_SINGLE_CHAR_NAMES,
714 ok_if_let::IF_LET_SOME_RESULT,
715 open_options::NONSENSICAL_OPEN_OPTIONS,
716 overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL,
717 panic_unimplemented::PANIC_PARAMS,
718 partialeq_ne_impl::PARTIALEQ_NE_IMPL,
719 precedence::PRECEDENCE,
723 ptr_offset_with_cast::PTR_OFFSET_WITH_CAST,
724 question_mark::QUESTION_MARK,
725 ranges::ITERATOR_STEP_BY_ZERO,
726 ranges::RANGE_MINUS_ONE,
727 ranges::RANGE_PLUS_ONE,
728 ranges::RANGE_ZIP_WITH_LEN,
729 redundant_field_names::REDUNDANT_FIELD_NAMES,
730 redundant_pattern_matching::REDUNDANT_PATTERN_MATCHING,
731 reference::DEREF_ADDROF,
732 reference::REF_IN_DEREF,
733 regex::INVALID_REGEX,
735 regex::TRIVIAL_REGEX,
736 returns::LET_AND_RETURN,
737 returns::NEEDLESS_RETURN,
738 returns::UNUSED_UNIT,
739 serde_api::SERDE_API_MISUSE,
740 slow_vector_initialization::SLOW_VECTOR_INITIALIZATION,
741 strings::STRING_LIT_AS_BYTES,
742 suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL,
743 suspicious_trait_impl::SUSPICIOUS_OP_ASSIGN_IMPL,
744 swap::ALMOST_SWAPPED,
746 temporary_assignment::TEMPORARY_ASSIGNMENT,
747 transmute::CROSSPOINTER_TRANSMUTE,
748 transmute::TRANSMUTE_BYTES_TO_STR,
749 transmute::TRANSMUTE_INT_TO_BOOL,
750 transmute::TRANSMUTE_INT_TO_CHAR,
751 transmute::TRANSMUTE_INT_TO_FLOAT,
752 transmute::TRANSMUTE_PTR_TO_PTR,
753 transmute::TRANSMUTE_PTR_TO_REF,
754 transmute::USELESS_TRANSMUTE,
755 transmute::WRONG_TRANSMUTE,
756 trivially_copy_pass_by_ref::TRIVIALLY_COPY_PASS_BY_REF,
757 types::ABSURD_EXTREME_COMPARISONS,
760 types::CAST_LOSSLESS,
761 types::CAST_PTR_ALIGNMENT,
762 types::CHAR_LIT_AS_U8,
763 types::FN_TO_NUMERIC_CAST,
764 types::FN_TO_NUMERIC_CAST_WITH_TRUNCATION,
765 types::IMPLICIT_HASHER,
766 types::LET_UNIT_VALUE,
767 types::OPTION_OPTION,
768 types::TYPE_COMPLEXITY,
771 types::UNNECESSARY_CAST,
773 unicode::ZERO_WIDTH_SPACE,
774 unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME,
775 unused_io_amount::UNUSED_IO_AMOUNT,
776 unused_label::UNUSED_LABEL,
778 write::PRINTLN_EMPTY_STRING,
779 write::PRINT_LITERAL,
780 write::PRINT_WITH_NEWLINE,
781 write::WRITELN_EMPTY_STRING,
782 write::WRITE_LITERAL,
783 write::WRITE_WITH_NEWLINE,
784 zero_div_zero::ZERO_DIVIDED_BY_ZERO,
787 reg.register_lint_group("clippy::style", Some("clippy_style"), vec![
788 assign_ops::ASSIGN_OP_PATTERN,
789 attrs::UNKNOWN_CLIPPY_LINTS,
790 bit_mask::VERBOSE_BIT_MASK,
791 blacklisted_name::BLACKLISTED_NAME,
792 block_in_if_condition::BLOCK_IN_IF_CONDITION_EXPR,
793 block_in_if_condition::BLOCK_IN_IF_CONDITION_STMT,
794 collapsible_if::COLLAPSIBLE_IF,
795 const_static_lifetime::CONST_STATIC_LIFETIME,
796 enum_variants::ENUM_VARIANT_NAMES,
797 enum_variants::MODULE_INCEPTION,
799 eta_reduction::REDUNDANT_CLOSURE,
800 excessive_precision::EXCESSIVE_PRECISION,
801 formatting::SUSPICIOUS_ASSIGNMENT_FORMATTING,
802 formatting::SUSPICIOUS_ELSE_FORMATTING,
803 infallible_destructuring_match::INFALLIBLE_DESTRUCTURING_MATCH,
804 len_zero::LEN_WITHOUT_IS_EMPTY,
806 let_if_seq::USELESS_LET_IF_SEQ,
807 literal_representation::INCONSISTENT_DIGIT_GROUPING,
808 literal_representation::UNREADABLE_LITERAL,
811 loops::NEEDLESS_RANGE_LOOP,
812 loops::WHILE_LET_ON_ITERATOR,
813 map_clone::MAP_CLONE,
815 matches::MATCH_OVERLAPPING_ARM,
816 matches::MATCH_REF_PATS,
817 matches::MATCH_WILD_ERR_ARM,
818 matches::SINGLE_MATCH,
819 mem_replace::MEM_REPLACE_OPTION_WITH_NONE,
820 methods::CHARS_LAST_CMP,
822 methods::INTO_ITER_ON_REF,
823 methods::ITER_CLONED_COLLECT,
824 methods::ITER_SKIP_NEXT,
825 methods::NEW_RET_NO_SELF,
827 methods::OPTION_MAP_OR_NONE,
828 methods::SHOULD_IMPLEMENT_TRAIT,
829 methods::STRING_EXTEND_CHARS,
830 methods::UNNECESSARY_FOLD,
831 methods::WRONG_SELF_CONVENTION,
832 misc::REDUNDANT_PATTERN,
833 misc::TOPLEVEL_REF_ARG,
835 misc_early::BUILTIN_TYPE_SHADOW,
836 misc_early::DOUBLE_NEG,
837 misc_early::DUPLICATE_UNDERSCORE_ARGUMENT,
838 misc_early::MIXED_CASE_HEX_LITERALS,
839 misc_early::UNNEEDED_FIELD_PATTERN,
840 mut_reference::UNNECESSARY_MUT_PASSED,
841 neg_multiply::NEG_MULTIPLY,
842 new_without_default::NEW_WITHOUT_DEFAULT,
843 non_expressive_names::JUST_UNDERSCORES_AND_DIGITS,
844 non_expressive_names::MANY_SINGLE_CHAR_NAMES,
845 ok_if_let::IF_LET_SOME_RESULT,
846 panic_unimplemented::PANIC_PARAMS,
849 question_mark::QUESTION_MARK,
850 redundant_field_names::REDUNDANT_FIELD_NAMES,
851 redundant_pattern_matching::REDUNDANT_PATTERN_MATCHING,
853 regex::TRIVIAL_REGEX,
854 returns::LET_AND_RETURN,
855 returns::NEEDLESS_RETURN,
856 returns::UNUSED_UNIT,
857 strings::STRING_LIT_AS_BYTES,
858 types::FN_TO_NUMERIC_CAST,
859 types::FN_TO_NUMERIC_CAST_WITH_TRUNCATION,
860 types::IMPLICIT_HASHER,
861 types::LET_UNIT_VALUE,
862 unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME,
863 write::PRINTLN_EMPTY_STRING,
864 write::PRINT_LITERAL,
865 write::PRINT_WITH_NEWLINE,
866 write::WRITELN_EMPTY_STRING,
867 write::WRITE_LITERAL,
868 write::WRITE_WITH_NEWLINE,
871 reg.register_lint_group("clippy::complexity", Some("clippy_complexity"), vec![
872 assign_ops::MISREFACTORED_ASSIGN_OP,
873 attrs::DEPRECATED_CFG_ATTR,
874 booleans::NONMINIMAL_BOOL,
875 cyclomatic_complexity::CYCLOMATIC_COMPLEXITY,
876 double_comparison::DOUBLE_COMPARISONS,
877 double_parens::DOUBLE_PARENS,
878 duration_subsec::DURATION_SUBSEC,
879 eval_order_dependence::DIVERGING_SUB_EXPRESSION,
880 eval_order_dependence::EVAL_ORDER_DEPENDENCE,
881 explicit_write::EXPLICIT_WRITE,
882 format::USELESS_FORMAT,
883 functions::TOO_MANY_ARGUMENTS,
884 identity_conversion::IDENTITY_CONVERSION,
885 identity_op::IDENTITY_OP,
886 int_plus_one::INT_PLUS_ONE,
887 lifetimes::EXTRA_UNUSED_LIFETIMES,
888 lifetimes::NEEDLESS_LIFETIMES,
889 loops::EXPLICIT_COUNTER_LOOP,
890 loops::MUT_RANGE_BOUND,
891 loops::WHILE_LET_LOOP,
892 map_unit_fn::OPTION_MAP_UNIT_FN,
893 map_unit_fn::RESULT_MAP_UNIT_FN,
894 matches::MATCH_AS_REF,
895 methods::CHARS_NEXT_CMP,
896 methods::CLONE_ON_COPY,
897 methods::FILTER_NEXT,
898 methods::SEARCH_IS_SOME,
899 methods::UNNECESSARY_FILTER_MAP,
900 methods::USELESS_ASREF,
901 misc::SHORT_CIRCUIT_STATEMENT,
902 misc_early::REDUNDANT_CLOSURE_CALL,
903 misc_early::ZERO_PREFIXED_LITERAL,
904 needless_bool::BOOL_COMPARISON,
905 needless_bool::NEEDLESS_BOOL,
906 needless_borrowed_ref::NEEDLESS_BORROWED_REFERENCE,
907 needless_update::NEEDLESS_UPDATE,
908 neg_cmp_op_on_partial_ord::NEG_CMP_OP_ON_PARTIAL_ORD,
909 no_effect::NO_EFFECT,
910 no_effect::UNNECESSARY_OPERATION,
911 overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL,
912 partialeq_ne_impl::PARTIALEQ_NE_IMPL,
913 precedence::PRECEDENCE,
914 ptr_offset_with_cast::PTR_OFFSET_WITH_CAST,
915 ranges::RANGE_MINUS_ONE,
916 ranges::RANGE_PLUS_ONE,
917 ranges::RANGE_ZIP_WITH_LEN,
918 reference::DEREF_ADDROF,
919 reference::REF_IN_DEREF,
921 temporary_assignment::TEMPORARY_ASSIGNMENT,
922 transmute::CROSSPOINTER_TRANSMUTE,
923 transmute::TRANSMUTE_BYTES_TO_STR,
924 transmute::TRANSMUTE_INT_TO_BOOL,
925 transmute::TRANSMUTE_INT_TO_CHAR,
926 transmute::TRANSMUTE_INT_TO_FLOAT,
927 transmute::TRANSMUTE_PTR_TO_PTR,
928 transmute::TRANSMUTE_PTR_TO_REF,
929 transmute::USELESS_TRANSMUTE,
931 types::CAST_LOSSLESS,
932 types::CHAR_LIT_AS_U8,
933 types::OPTION_OPTION,
934 types::TYPE_COMPLEXITY,
936 types::UNNECESSARY_CAST,
938 unused_label::UNUSED_LABEL,
939 zero_div_zero::ZERO_DIVIDED_BY_ZERO,
942 reg.register_lint_group("clippy::correctness", Some("clippy_correctness"), vec![
943 approx_const::APPROX_CONSTANT,
944 attrs::DEPRECATED_SEMVER,
945 attrs::USELESS_ATTRIBUTE,
946 bit_mask::BAD_BIT_MASK,
947 bit_mask::INEFFECTIVE_BIT_MASK,
949 copies::IFS_SAME_COND,
950 copies::IF_SAME_THEN_ELSE,
951 derive::DERIVE_HASH_XOR_EQ,
952 drop_forget_ref::DROP_COPY,
953 drop_forget_ref::DROP_REF,
954 drop_forget_ref::FORGET_COPY,
955 drop_forget_ref::FORGET_REF,
956 enum_clike::ENUM_CLIKE_UNPORTABLE_VARIANT,
958 erasing_op::ERASING_OP,
959 formatting::POSSIBLE_MISSING_COMMA,
960 functions::NOT_UNSAFE_PTR_ARG_DEREF,
961 indexing_slicing::OUT_OF_BOUNDS_INDEXING,
962 infinite_iter::INFINITE_ITER,
963 inline_fn_without_body::INLINE_FN_WITHOUT_BODY,
964 invalid_ref::INVALID_REF,
965 literal_representation::MISTYPED_LITERAL_SUFFIXES,
966 loops::FOR_LOOP_OVER_OPTION,
967 loops::FOR_LOOP_OVER_RESULT,
968 loops::ITER_NEXT_LOOP,
970 loops::REVERSE_RANGE_LOOP,
971 loops::WHILE_IMMUTABLE_CONDITION,
972 mem_discriminant::MEM_DISCRIMINANT_NON_ENUM,
973 methods::CLONE_DOUBLE_REF,
974 methods::INTO_ITER_ON_ARRAY,
975 methods::TEMPORARY_CSTRING_AS_PTR,
980 non_copy_const::BORROW_INTERIOR_MUTABLE_CONST,
981 non_copy_const::DECLARE_INTERIOR_MUTABLE_CONST,
982 open_options::NONSENSICAL_OPEN_OPTIONS,
984 ranges::ITERATOR_STEP_BY_ZERO,
985 regex::INVALID_REGEX,
986 serde_api::SERDE_API_MISUSE,
987 suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL,
988 suspicious_trait_impl::SUSPICIOUS_OP_ASSIGN_IMPL,
989 swap::ALMOST_SWAPPED,
990 transmute::WRONG_TRANSMUTE,
991 types::ABSURD_EXTREME_COMPARISONS,
992 types::CAST_PTR_ALIGNMENT,
994 unicode::ZERO_WIDTH_SPACE,
995 unused_io_amount::UNUSED_IO_AMOUNT,
998 reg.register_lint_group("clippy::perf", Some("clippy_perf"), vec![
999 bytecount::NAIVE_BYTECOUNT,
1001 escape::BOXED_LOCAL,
1002 large_enum_variant::LARGE_ENUM_VARIANT,
1003 loops::MANUAL_MEMCPY,
1004 loops::NEEDLESS_COLLECT,
1005 loops::UNUSED_COLLECT,
1006 methods::EXPECT_FUN_CALL,
1008 methods::OR_FUN_CALL,
1009 methods::SINGLE_CHAR_PATTERN,
1011 mutex_atomic::MUTEX_ATOMIC,
1012 slow_vector_initialization::SLOW_VECTOR_INITIALIZATION,
1013 trivially_copy_pass_by_ref::TRIVIALLY_COPY_PASS_BY_REF,
1018 reg.register_lint_group("clippy::cargo", Some("clippy_cargo"), vec![
1019 cargo_common_metadata::CARGO_COMMON_METADATA,
1020 multiple_crate_versions::MULTIPLE_CRATE_VERSIONS,
1021 wildcard_dependencies::WILDCARD_DEPENDENCIES,
1024 reg.register_lint_group("clippy::nursery", Some("clippy_nursery"), vec![
1025 attrs::EMPTY_LINE_AFTER_OUTER_ATTR,
1026 fallible_impl_from::FALLIBLE_IMPL_FROM,
1027 mutex_atomic::MUTEX_INTEGER,
1028 needless_borrow::NEEDLESS_BORROW,
1029 redundant_clone::REDUNDANT_CLONE,
1030 types::CAST_REF_TO_MUT,
1031 unwrap::PANICKING_UNWRAP,
1032 unwrap::UNNECESSARY_UNWRAP,
1036 pub fn register_renamed(ls: &mut rustc::lint::LintStore) {
1037 ls.register_renamed("clippy::stutter", "clippy::module_name_repetitions");
1038 ls.register_renamed("clippy::new_without_default_derive", "clippy::new_without_default");
1041 // only exists to let the dogfood integration test works.
1042 // Don't run clippy as an executable directly
1045 panic!("Please use the cargo-clippy executable");