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;
183 pub mod random_state;
185 pub mod redundant_clone;
186 pub mod redundant_field_names;
187 pub mod redundant_pattern_matching;
190 pub mod replace_consts;
194 pub mod slow_vector_initialization;
196 pub mod suspicious_trait_impl;
198 pub mod temporary_assignment;
200 pub mod trivially_copy_pass_by_ref;
203 pub mod unsafe_removed_from_name;
204 pub mod unused_io_amount;
205 pub mod unused_label;
209 pub mod wildcard_dependencies;
211 pub mod zero_div_zero;
212 // end lints modules, do not remove this comment, it’s used in `update_lints`
214 pub use crate::utils::conf::Conf;
217 crate use syntax::ast::{Name, NodeId};
220 pub fn register_pre_expansion_lints(
221 session: &rustc::session::Session,
222 store: &mut rustc::lint::LintStore,
225 store.register_pre_expansion_pass(Some(session), box write::Pass);
226 store.register_pre_expansion_pass(Some(session), box redundant_field_names::RedundantFieldNames);
227 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), 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 random_state::Pass);
492 reg.register_lint_group("clippy::restriction", Some("clippy_restriction"), vec![
493 arithmetic::FLOAT_ARITHMETIC,
494 arithmetic::INTEGER_ARITHMETIC,
495 else_if_without_else::ELSE_IF_WITHOUT_ELSE,
496 implicit_return::IMPLICIT_RETURN,
497 indexing_slicing::INDEXING_SLICING,
498 inherent_impl::MULTIPLE_INHERENT_IMPL,
499 literal_representation::DECIMAL_LITERAL_REPRESENTATION,
500 mem_forget::MEM_FORGET,
501 methods::CLONE_ON_REF_PTR,
502 methods::OPTION_UNWRAP_USED,
503 methods::RESULT_UNWRAP_USED,
504 methods::WRONG_PUB_SELF_CONVENTION,
505 misc::FLOAT_CMP_CONST,
506 missing_doc::MISSING_DOCS_IN_PRIVATE_ITEMS,
507 missing_inline::MISSING_INLINE_IN_PUBLIC_ITEMS,
508 panic_unimplemented::UNIMPLEMENTED,
509 shadow::SHADOW_REUSE,
516 reg.register_lint_group("clippy::pedantic", Some("clippy_pedantic"), vec![
517 attrs::INLINE_ALWAYS,
518 copies::MATCH_SAME_ARMS,
519 copy_iterator::COPY_ITERATOR,
520 default_trait_access::DEFAULT_TRAIT_ACCESS,
521 derive::EXPL_IMPL_CLONE_ON_COPY,
523 empty_enum::EMPTY_ENUM,
524 enum_glob_use::ENUM_GLOB_USE,
525 enum_variants::MODULE_NAME_REPETITIONS,
526 enum_variants::PUB_ENUM_VARIANT_NAMES,
527 if_not_else::IF_NOT_ELSE,
528 infinite_iter::MAYBE_INFINITE_ITER,
529 items_after_statements::ITEMS_AFTER_STATEMENTS,
530 literal_representation::LARGE_DIGIT_GROUPS,
531 loops::EXPLICIT_INTO_ITER_LOOP,
532 loops::EXPLICIT_ITER_LOOP,
533 matches::SINGLE_MATCH_ELSE,
535 methods::MAP_FLATTEN,
536 methods::OPTION_MAP_UNWRAP_OR,
537 methods::OPTION_MAP_UNWRAP_OR_ELSE,
538 methods::RESULT_MAP_UNWRAP_OR_ELSE,
539 misc::USED_UNDERSCORE_BINDING,
540 misc_early::UNSEPARATED_LITERAL_SUFFIX,
542 needless_continue::NEEDLESS_CONTINUE,
543 needless_pass_by_value::NEEDLESS_PASS_BY_VALUE,
544 non_expressive_names::SIMILAR_NAMES,
545 replace_consts::REPLACE_CONSTS,
546 shadow::SHADOW_UNRELATED,
547 strings::STRING_ADD_ASSIGN,
548 types::CAST_POSSIBLE_TRUNCATION,
549 types::CAST_POSSIBLE_WRAP,
550 types::CAST_PRECISION_LOSS,
551 types::CAST_SIGN_LOSS,
552 types::INVALID_UPCAST_COMPARISONS,
554 unicode::NON_ASCII_LITERAL,
555 unicode::UNICODE_NOT_NFC,
559 reg.register_lint_group("clippy::internal", Some("clippy_internal"), vec![
560 utils::internal_lints::CLIPPY_LINTS_INTERNAL,
561 utils::internal_lints::COMPILER_LINT_FUNCTIONS,
562 utils::internal_lints::DEFAULT_HASH_TYPES,
563 utils::internal_lints::LINT_WITHOUT_LINT_PASS,
566 reg.register_lint_group("clippy::all", Some("clippy"), vec![
567 approx_const::APPROX_CONSTANT,
568 assign_ops::ASSIGN_OP_PATTERN,
569 assign_ops::MISREFACTORED_ASSIGN_OP,
570 attrs::DEPRECATED_CFG_ATTR,
571 attrs::DEPRECATED_SEMVER,
572 attrs::UNKNOWN_CLIPPY_LINTS,
573 attrs::USELESS_ATTRIBUTE,
574 bit_mask::BAD_BIT_MASK,
575 bit_mask::INEFFECTIVE_BIT_MASK,
576 bit_mask::VERBOSE_BIT_MASK,
577 blacklisted_name::BLACKLISTED_NAME,
578 block_in_if_condition::BLOCK_IN_IF_CONDITION_EXPR,
579 block_in_if_condition::BLOCK_IN_IF_CONDITION_STMT,
581 booleans::NONMINIMAL_BOOL,
582 bytecount::NAIVE_BYTECOUNT,
583 collapsible_if::COLLAPSIBLE_IF,
584 const_static_lifetime::CONST_STATIC_LIFETIME,
585 copies::IFS_SAME_COND,
586 copies::IF_SAME_THEN_ELSE,
587 cyclomatic_complexity::CYCLOMATIC_COMPLEXITY,
588 derive::DERIVE_HASH_XOR_EQ,
589 double_comparison::DOUBLE_COMPARISONS,
590 double_parens::DOUBLE_PARENS,
591 drop_forget_ref::DROP_COPY,
592 drop_forget_ref::DROP_REF,
593 drop_forget_ref::FORGET_COPY,
594 drop_forget_ref::FORGET_REF,
595 duration_subsec::DURATION_SUBSEC,
597 enum_clike::ENUM_CLIKE_UNPORTABLE_VARIANT,
598 enum_variants::ENUM_VARIANT_NAMES,
599 enum_variants::MODULE_INCEPTION,
602 erasing_op::ERASING_OP,
604 eta_reduction::REDUNDANT_CLOSURE,
605 eval_order_dependence::DIVERGING_SUB_EXPRESSION,
606 eval_order_dependence::EVAL_ORDER_DEPENDENCE,
607 excessive_precision::EXCESSIVE_PRECISION,
608 explicit_write::EXPLICIT_WRITE,
609 format::USELESS_FORMAT,
610 formatting::POSSIBLE_MISSING_COMMA,
611 formatting::SUSPICIOUS_ASSIGNMENT_FORMATTING,
612 formatting::SUSPICIOUS_ELSE_FORMATTING,
613 functions::NOT_UNSAFE_PTR_ARG_DEREF,
614 functions::TOO_MANY_ARGUMENTS,
615 identity_conversion::IDENTITY_CONVERSION,
616 identity_op::IDENTITY_OP,
617 indexing_slicing::OUT_OF_BOUNDS_INDEXING,
618 infallible_destructuring_match::INFALLIBLE_DESTRUCTURING_MATCH,
619 infinite_iter::INFINITE_ITER,
620 inline_fn_without_body::INLINE_FN_WITHOUT_BODY,
621 int_plus_one::INT_PLUS_ONE,
622 invalid_ref::INVALID_REF,
623 large_enum_variant::LARGE_ENUM_VARIANT,
624 len_zero::LEN_WITHOUT_IS_EMPTY,
626 let_if_seq::USELESS_LET_IF_SEQ,
627 lifetimes::EXTRA_UNUSED_LIFETIMES,
628 lifetimes::NEEDLESS_LIFETIMES,
629 literal_representation::INCONSISTENT_DIGIT_GROUPING,
630 literal_representation::MISTYPED_LITERAL_SUFFIXES,
631 literal_representation::UNREADABLE_LITERAL,
633 loops::EXPLICIT_COUNTER_LOOP,
635 loops::FOR_LOOP_OVER_OPTION,
636 loops::FOR_LOOP_OVER_RESULT,
637 loops::ITER_NEXT_LOOP,
638 loops::MANUAL_MEMCPY,
639 loops::MUT_RANGE_BOUND,
640 loops::NEEDLESS_COLLECT,
641 loops::NEEDLESS_RANGE_LOOP,
643 loops::REVERSE_RANGE_LOOP,
644 loops::UNUSED_COLLECT,
645 loops::WHILE_IMMUTABLE_CONDITION,
646 loops::WHILE_LET_LOOP,
647 loops::WHILE_LET_ON_ITERATOR,
648 map_clone::MAP_CLONE,
649 map_unit_fn::OPTION_MAP_UNIT_FN,
650 map_unit_fn::RESULT_MAP_UNIT_FN,
651 matches::MATCH_AS_REF,
653 matches::MATCH_OVERLAPPING_ARM,
654 matches::MATCH_REF_PATS,
655 matches::MATCH_WILD_ERR_ARM,
656 matches::SINGLE_MATCH,
657 mem_discriminant::MEM_DISCRIMINANT_NON_ENUM,
658 mem_replace::MEM_REPLACE_OPTION_WITH_NONE,
659 methods::CHARS_LAST_CMP,
660 methods::CHARS_NEXT_CMP,
661 methods::CLONE_DOUBLE_REF,
662 methods::CLONE_ON_COPY,
663 methods::EXPECT_FUN_CALL,
664 methods::FILTER_NEXT,
666 methods::INTO_ITER_ON_ARRAY,
667 methods::INTO_ITER_ON_REF,
668 methods::ITER_CLONED_COLLECT,
670 methods::ITER_SKIP_NEXT,
671 methods::NEW_RET_NO_SELF,
673 methods::OPTION_MAP_OR_NONE,
674 methods::OR_FUN_CALL,
675 methods::SEARCH_IS_SOME,
676 methods::SHOULD_IMPLEMENT_TRAIT,
677 methods::SINGLE_CHAR_PATTERN,
678 methods::STRING_EXTEND_CHARS,
679 methods::TEMPORARY_CSTRING_AS_PTR,
680 methods::UNNECESSARY_FILTER_MAP,
681 methods::UNNECESSARY_FOLD,
682 methods::USELESS_ASREF,
683 methods::WRONG_SELF_CONVENTION,
689 misc::REDUNDANT_PATTERN,
690 misc::SHORT_CIRCUIT_STATEMENT,
691 misc::TOPLEVEL_REF_ARG,
693 misc_early::BUILTIN_TYPE_SHADOW,
694 misc_early::DOUBLE_NEG,
695 misc_early::DUPLICATE_UNDERSCORE_ARGUMENT,
696 misc_early::MIXED_CASE_HEX_LITERALS,
697 misc_early::REDUNDANT_CLOSURE_CALL,
698 misc_early::UNNEEDED_FIELD_PATTERN,
699 misc_early::ZERO_PREFIXED_LITERAL,
700 mut_reference::UNNECESSARY_MUT_PASSED,
701 mutex_atomic::MUTEX_ATOMIC,
702 needless_bool::BOOL_COMPARISON,
703 needless_bool::NEEDLESS_BOOL,
704 needless_borrowed_ref::NEEDLESS_BORROWED_REFERENCE,
705 needless_update::NEEDLESS_UPDATE,
706 neg_cmp_op_on_partial_ord::NEG_CMP_OP_ON_PARTIAL_ORD,
707 neg_multiply::NEG_MULTIPLY,
708 new_without_default::NEW_WITHOUT_DEFAULT,
709 no_effect::NO_EFFECT,
710 no_effect::UNNECESSARY_OPERATION,
711 non_copy_const::BORROW_INTERIOR_MUTABLE_CONST,
712 non_copy_const::DECLARE_INTERIOR_MUTABLE_CONST,
713 non_expressive_names::JUST_UNDERSCORES_AND_DIGITS,
714 non_expressive_names::MANY_SINGLE_CHAR_NAMES,
715 ok_if_let::IF_LET_SOME_RESULT,
716 open_options::NONSENSICAL_OPEN_OPTIONS,
717 overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL,
718 panic_unimplemented::PANIC_PARAMS,
719 partialeq_ne_impl::PARTIALEQ_NE_IMPL,
720 precedence::PRECEDENCE,
724 ptr_offset_with_cast::PTR_OFFSET_WITH_CAST,
725 question_mark::QUESTION_MARK,
726 ranges::ITERATOR_STEP_BY_ZERO,
727 ranges::RANGE_MINUS_ONE,
728 ranges::RANGE_PLUS_ONE,
729 ranges::RANGE_ZIP_WITH_LEN,
730 redundant_field_names::REDUNDANT_FIELD_NAMES,
731 redundant_pattern_matching::REDUNDANT_PATTERN_MATCHING,
732 reference::DEREF_ADDROF,
733 reference::REF_IN_DEREF,
734 regex::INVALID_REGEX,
736 regex::TRIVIAL_REGEX,
737 returns::LET_AND_RETURN,
738 returns::NEEDLESS_RETURN,
739 returns::UNUSED_UNIT,
740 serde_api::SERDE_API_MISUSE,
741 slow_vector_initialization::SLOW_VECTOR_INITIALIZATION,
742 strings::STRING_LIT_AS_BYTES,
743 suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL,
744 suspicious_trait_impl::SUSPICIOUS_OP_ASSIGN_IMPL,
745 swap::ALMOST_SWAPPED,
747 temporary_assignment::TEMPORARY_ASSIGNMENT,
748 transmute::CROSSPOINTER_TRANSMUTE,
749 transmute::TRANSMUTE_BYTES_TO_STR,
750 transmute::TRANSMUTE_INT_TO_BOOL,
751 transmute::TRANSMUTE_INT_TO_CHAR,
752 transmute::TRANSMUTE_INT_TO_FLOAT,
753 transmute::TRANSMUTE_PTR_TO_PTR,
754 transmute::TRANSMUTE_PTR_TO_REF,
755 transmute::USELESS_TRANSMUTE,
756 transmute::WRONG_TRANSMUTE,
757 trivially_copy_pass_by_ref::TRIVIALLY_COPY_PASS_BY_REF,
758 types::ABSURD_EXTREME_COMPARISONS,
761 types::CAST_LOSSLESS,
762 types::CAST_PTR_ALIGNMENT,
763 types::CHAR_LIT_AS_U8,
764 types::FN_TO_NUMERIC_CAST,
765 types::FN_TO_NUMERIC_CAST_WITH_TRUNCATION,
766 types::IMPLICIT_HASHER,
767 types::LET_UNIT_VALUE,
768 types::OPTION_OPTION,
769 types::TYPE_COMPLEXITY,
772 types::UNNECESSARY_CAST,
774 unicode::ZERO_WIDTH_SPACE,
775 unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME,
776 unused_io_amount::UNUSED_IO_AMOUNT,
777 unused_label::UNUSED_LABEL,
779 write::PRINTLN_EMPTY_STRING,
780 write::PRINT_LITERAL,
781 write::PRINT_WITH_NEWLINE,
782 write::WRITELN_EMPTY_STRING,
783 write::WRITE_LITERAL,
784 write::WRITE_WITH_NEWLINE,
785 zero_div_zero::ZERO_DIVIDED_BY_ZERO,
788 reg.register_lint_group("clippy::style", Some("clippy_style"), vec![
789 assign_ops::ASSIGN_OP_PATTERN,
790 attrs::UNKNOWN_CLIPPY_LINTS,
791 bit_mask::VERBOSE_BIT_MASK,
792 blacklisted_name::BLACKLISTED_NAME,
793 block_in_if_condition::BLOCK_IN_IF_CONDITION_EXPR,
794 block_in_if_condition::BLOCK_IN_IF_CONDITION_STMT,
795 collapsible_if::COLLAPSIBLE_IF,
796 const_static_lifetime::CONST_STATIC_LIFETIME,
797 enum_variants::ENUM_VARIANT_NAMES,
798 enum_variants::MODULE_INCEPTION,
800 eta_reduction::REDUNDANT_CLOSURE,
801 excessive_precision::EXCESSIVE_PRECISION,
802 formatting::SUSPICIOUS_ASSIGNMENT_FORMATTING,
803 formatting::SUSPICIOUS_ELSE_FORMATTING,
804 infallible_destructuring_match::INFALLIBLE_DESTRUCTURING_MATCH,
805 len_zero::LEN_WITHOUT_IS_EMPTY,
807 let_if_seq::USELESS_LET_IF_SEQ,
808 literal_representation::INCONSISTENT_DIGIT_GROUPING,
809 literal_representation::UNREADABLE_LITERAL,
812 loops::NEEDLESS_RANGE_LOOP,
813 loops::WHILE_LET_ON_ITERATOR,
814 map_clone::MAP_CLONE,
816 matches::MATCH_OVERLAPPING_ARM,
817 matches::MATCH_REF_PATS,
818 matches::MATCH_WILD_ERR_ARM,
819 matches::SINGLE_MATCH,
820 mem_replace::MEM_REPLACE_OPTION_WITH_NONE,
821 methods::CHARS_LAST_CMP,
823 methods::INTO_ITER_ON_REF,
824 methods::ITER_CLONED_COLLECT,
825 methods::ITER_SKIP_NEXT,
826 methods::NEW_RET_NO_SELF,
828 methods::OPTION_MAP_OR_NONE,
829 methods::SHOULD_IMPLEMENT_TRAIT,
830 methods::STRING_EXTEND_CHARS,
831 methods::UNNECESSARY_FOLD,
832 methods::WRONG_SELF_CONVENTION,
833 misc::REDUNDANT_PATTERN,
834 misc::TOPLEVEL_REF_ARG,
836 misc_early::BUILTIN_TYPE_SHADOW,
837 misc_early::DOUBLE_NEG,
838 misc_early::DUPLICATE_UNDERSCORE_ARGUMENT,
839 misc_early::MIXED_CASE_HEX_LITERALS,
840 misc_early::UNNEEDED_FIELD_PATTERN,
841 mut_reference::UNNECESSARY_MUT_PASSED,
842 neg_multiply::NEG_MULTIPLY,
843 new_without_default::NEW_WITHOUT_DEFAULT,
844 non_expressive_names::JUST_UNDERSCORES_AND_DIGITS,
845 non_expressive_names::MANY_SINGLE_CHAR_NAMES,
846 ok_if_let::IF_LET_SOME_RESULT,
847 panic_unimplemented::PANIC_PARAMS,
850 question_mark::QUESTION_MARK,
851 redundant_field_names::REDUNDANT_FIELD_NAMES,
852 redundant_pattern_matching::REDUNDANT_PATTERN_MATCHING,
854 regex::TRIVIAL_REGEX,
855 returns::LET_AND_RETURN,
856 returns::NEEDLESS_RETURN,
857 returns::UNUSED_UNIT,
858 strings::STRING_LIT_AS_BYTES,
859 types::FN_TO_NUMERIC_CAST,
860 types::FN_TO_NUMERIC_CAST_WITH_TRUNCATION,
861 types::IMPLICIT_HASHER,
862 types::LET_UNIT_VALUE,
863 unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME,
864 write::PRINTLN_EMPTY_STRING,
865 write::PRINT_LITERAL,
866 write::PRINT_WITH_NEWLINE,
867 write::WRITELN_EMPTY_STRING,
868 write::WRITE_LITERAL,
869 write::WRITE_WITH_NEWLINE,
872 reg.register_lint_group("clippy::complexity", Some("clippy_complexity"), vec![
873 assign_ops::MISREFACTORED_ASSIGN_OP,
874 attrs::DEPRECATED_CFG_ATTR,
875 booleans::NONMINIMAL_BOOL,
876 cyclomatic_complexity::CYCLOMATIC_COMPLEXITY,
877 double_comparison::DOUBLE_COMPARISONS,
878 double_parens::DOUBLE_PARENS,
879 duration_subsec::DURATION_SUBSEC,
880 eval_order_dependence::DIVERGING_SUB_EXPRESSION,
881 eval_order_dependence::EVAL_ORDER_DEPENDENCE,
882 explicit_write::EXPLICIT_WRITE,
883 format::USELESS_FORMAT,
884 functions::TOO_MANY_ARGUMENTS,
885 identity_conversion::IDENTITY_CONVERSION,
886 identity_op::IDENTITY_OP,
887 int_plus_one::INT_PLUS_ONE,
888 lifetimes::EXTRA_UNUSED_LIFETIMES,
889 lifetimes::NEEDLESS_LIFETIMES,
890 loops::EXPLICIT_COUNTER_LOOP,
891 loops::MUT_RANGE_BOUND,
892 loops::WHILE_LET_LOOP,
893 map_unit_fn::OPTION_MAP_UNIT_FN,
894 map_unit_fn::RESULT_MAP_UNIT_FN,
895 matches::MATCH_AS_REF,
896 methods::CHARS_NEXT_CMP,
897 methods::CLONE_ON_COPY,
898 methods::FILTER_NEXT,
899 methods::SEARCH_IS_SOME,
900 methods::UNNECESSARY_FILTER_MAP,
901 methods::USELESS_ASREF,
902 misc::SHORT_CIRCUIT_STATEMENT,
903 misc_early::REDUNDANT_CLOSURE_CALL,
904 misc_early::ZERO_PREFIXED_LITERAL,
905 needless_bool::BOOL_COMPARISON,
906 needless_bool::NEEDLESS_BOOL,
907 needless_borrowed_ref::NEEDLESS_BORROWED_REFERENCE,
908 needless_update::NEEDLESS_UPDATE,
909 neg_cmp_op_on_partial_ord::NEG_CMP_OP_ON_PARTIAL_ORD,
910 no_effect::NO_EFFECT,
911 no_effect::UNNECESSARY_OPERATION,
912 overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL,
913 partialeq_ne_impl::PARTIALEQ_NE_IMPL,
914 precedence::PRECEDENCE,
915 ptr_offset_with_cast::PTR_OFFSET_WITH_CAST,
916 ranges::RANGE_MINUS_ONE,
917 ranges::RANGE_PLUS_ONE,
918 ranges::RANGE_ZIP_WITH_LEN,
919 reference::DEREF_ADDROF,
920 reference::REF_IN_DEREF,
922 temporary_assignment::TEMPORARY_ASSIGNMENT,
923 transmute::CROSSPOINTER_TRANSMUTE,
924 transmute::TRANSMUTE_BYTES_TO_STR,
925 transmute::TRANSMUTE_INT_TO_BOOL,
926 transmute::TRANSMUTE_INT_TO_CHAR,
927 transmute::TRANSMUTE_INT_TO_FLOAT,
928 transmute::TRANSMUTE_PTR_TO_PTR,
929 transmute::TRANSMUTE_PTR_TO_REF,
930 transmute::USELESS_TRANSMUTE,
932 types::CAST_LOSSLESS,
933 types::CHAR_LIT_AS_U8,
934 types::OPTION_OPTION,
935 types::TYPE_COMPLEXITY,
937 types::UNNECESSARY_CAST,
939 unused_label::UNUSED_LABEL,
940 zero_div_zero::ZERO_DIVIDED_BY_ZERO,
943 reg.register_lint_group("clippy::correctness", Some("clippy_correctness"), vec![
944 approx_const::APPROX_CONSTANT,
945 attrs::DEPRECATED_SEMVER,
946 attrs::USELESS_ATTRIBUTE,
947 bit_mask::BAD_BIT_MASK,
948 bit_mask::INEFFECTIVE_BIT_MASK,
950 copies::IFS_SAME_COND,
951 copies::IF_SAME_THEN_ELSE,
952 derive::DERIVE_HASH_XOR_EQ,
953 drop_forget_ref::DROP_COPY,
954 drop_forget_ref::DROP_REF,
955 drop_forget_ref::FORGET_COPY,
956 drop_forget_ref::FORGET_REF,
957 enum_clike::ENUM_CLIKE_UNPORTABLE_VARIANT,
959 erasing_op::ERASING_OP,
960 formatting::POSSIBLE_MISSING_COMMA,
961 functions::NOT_UNSAFE_PTR_ARG_DEREF,
962 indexing_slicing::OUT_OF_BOUNDS_INDEXING,
963 infinite_iter::INFINITE_ITER,
964 inline_fn_without_body::INLINE_FN_WITHOUT_BODY,
965 invalid_ref::INVALID_REF,
966 literal_representation::MISTYPED_LITERAL_SUFFIXES,
967 loops::FOR_LOOP_OVER_OPTION,
968 loops::FOR_LOOP_OVER_RESULT,
969 loops::ITER_NEXT_LOOP,
971 loops::REVERSE_RANGE_LOOP,
972 loops::WHILE_IMMUTABLE_CONDITION,
973 mem_discriminant::MEM_DISCRIMINANT_NON_ENUM,
974 methods::CLONE_DOUBLE_REF,
975 methods::INTO_ITER_ON_ARRAY,
976 methods::TEMPORARY_CSTRING_AS_PTR,
981 non_copy_const::BORROW_INTERIOR_MUTABLE_CONST,
982 non_copy_const::DECLARE_INTERIOR_MUTABLE_CONST,
983 open_options::NONSENSICAL_OPEN_OPTIONS,
985 ranges::ITERATOR_STEP_BY_ZERO,
986 regex::INVALID_REGEX,
987 serde_api::SERDE_API_MISUSE,
988 suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL,
989 suspicious_trait_impl::SUSPICIOUS_OP_ASSIGN_IMPL,
990 swap::ALMOST_SWAPPED,
991 transmute::WRONG_TRANSMUTE,
992 types::ABSURD_EXTREME_COMPARISONS,
993 types::CAST_PTR_ALIGNMENT,
995 unicode::ZERO_WIDTH_SPACE,
996 unused_io_amount::UNUSED_IO_AMOUNT,
999 reg.register_lint_group("clippy::perf", Some("clippy_perf"), vec![
1000 bytecount::NAIVE_BYTECOUNT,
1002 escape::BOXED_LOCAL,
1003 large_enum_variant::LARGE_ENUM_VARIANT,
1004 loops::MANUAL_MEMCPY,
1005 loops::NEEDLESS_COLLECT,
1006 loops::UNUSED_COLLECT,
1007 methods::EXPECT_FUN_CALL,
1009 methods::OR_FUN_CALL,
1010 methods::SINGLE_CHAR_PATTERN,
1012 mutex_atomic::MUTEX_ATOMIC,
1013 slow_vector_initialization::SLOW_VECTOR_INITIALIZATION,
1014 trivially_copy_pass_by_ref::TRIVIALLY_COPY_PASS_BY_REF,
1019 reg.register_lint_group("clippy::cargo", Some("clippy_cargo"), vec![
1020 cargo_common_metadata::CARGO_COMMON_METADATA,
1021 multiple_crate_versions::MULTIPLE_CRATE_VERSIONS,
1022 wildcard_dependencies::WILDCARD_DEPENDENCIES,
1025 reg.register_lint_group("clippy::nursery", Some("clippy_nursery"), vec![
1026 attrs::EMPTY_LINE_AFTER_OUTER_ATTR,
1027 fallible_impl_from::FALLIBLE_IMPL_FROM,
1028 mutex_atomic::MUTEX_INTEGER,
1029 needless_borrow::NEEDLESS_BORROW,
1030 random_state::RANDOM_STATE,
1031 redundant_clone::REDUNDANT_CLONE,
1032 unwrap::PANICKING_UNWRAP,
1033 unwrap::UNNECESSARY_UNWRAP,
1037 pub fn register_renamed(ls: &mut rustc::lint::LintStore) {
1038 ls.register_renamed("clippy::stutter", "clippy::module_name_repetitions");
1039 ls.register_renamed("clippy::new_without_default_derive", "clippy::new_without_default");
1042 // only exists to let the dogfood integration test works.
1043 // Don't run clippy as an executable directly
1046 panic!("Please use the cargo-clippy executable");