1 #![feature(array_windows)]
2 #![feature(binary_heap_into_iter_sorted)]
3 #![feature(box_patterns)]
4 #![feature(control_flow_enum)]
5 #![feature(drain_filter)]
6 #![feature(iter_intersperse)]
7 #![feature(let_chains)]
9 #![feature(lint_reasons)]
10 #![feature(never_type)]
11 #![feature(once_cell)]
12 #![feature(rustc_private)]
13 #![feature(stmt_expr_attributes)]
14 #![recursion_limit = "512"]
15 #![cfg_attr(feature = "deny-warnings", deny(warnings))]
16 #![allow(clippy::missing_docs_in_private_items, clippy::must_use_candidate)]
17 #![warn(trivial_casts, trivial_numeric_casts)]
18 // warn on lints, that are included in `rust-lang/rust`s bootstrap
19 #![warn(rust_2018_idioms, unused_lifetimes)]
20 // warn on rustc internal lints
21 #![warn(rustc::internal)]
22 // Disable this rustc lint for now, as it was also done in rustc
23 #![allow(rustc::potential_query_instability)]
25 // FIXME: switch to something more ergonomic here, once available.
26 // (Currently there is no way to opt into sysroot crates without `extern crate`.)
27 extern crate rustc_arena;
28 extern crate rustc_ast;
29 extern crate rustc_ast_pretty;
30 extern crate rustc_attr;
31 extern crate rustc_data_structures;
32 extern crate rustc_driver;
33 extern crate rustc_errors;
34 extern crate rustc_hir;
35 extern crate rustc_hir_pretty;
36 extern crate rustc_index;
37 extern crate rustc_infer;
38 extern crate rustc_lexer;
39 extern crate rustc_lint;
40 extern crate rustc_middle;
41 extern crate rustc_mir_dataflow;
42 extern crate rustc_parse;
43 extern crate rustc_parse_format;
44 extern crate rustc_session;
45 extern crate rustc_span;
46 extern crate rustc_target;
47 extern crate rustc_trait_selection;
48 extern crate rustc_typeck;
51 extern crate clippy_utils;
53 use clippy_utils::parse_msrv;
54 use rustc_data_structures::fx::FxHashSet;
55 use rustc_lint::LintId;
56 use rustc_semver::RustcVersion;
57 use rustc_session::Session;
59 /// Macro used to declare a Clippy lint.
61 /// Every lint declaration consists of 4 parts:
63 /// 1. The documentation, which is used for the website
64 /// 2. The `LINT_NAME`. See [lint naming][lint_naming] on lint naming conventions.
65 /// 3. The `lint_level`, which is a mapping from *one* of our lint groups to `Allow`, `Warn` or
66 /// `Deny`. The lint level here has nothing to do with what lint groups the lint is a part of.
67 /// 4. The `description` that contains a short explanation on what's wrong with code where the
68 /// lint is triggered.
70 /// Currently the categories `style`, `correctness`, `suspicious`, `complexity` and `perf` are
71 /// enabled by default. As said in the README.md of this repository, if the lint level mapping
72 /// changes, please update README.md.
77 /// #![feature(rustc_private)]
78 /// extern crate rustc_session;
79 /// use rustc_session::declare_tool_lint;
80 /// use clippy_lints::declare_clippy_lint;
82 /// declare_clippy_lint! {
83 /// /// ### What it does
84 /// /// Checks for ... (describe what the lint matches).
86 /// /// ### Why is this bad?
87 /// /// Supply the reason for linting the code.
91 /// /// Insert a short example of code that triggers the lint
96 /// /// Insert a short example of improved code that doesn't trigger the lint
103 /// [lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints
105 macro_rules! declare_clippy_lint {
106 { $(#[$attr:meta])* pub $name:tt, style, $description:tt } => {
108 $(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
111 { $(#[$attr:meta])* pub $name:tt, correctness, $description:tt } => {
113 $(#[$attr])* pub clippy::$name, Deny, $description, report_in_external_macro: true
116 { $(#[$attr:meta])* pub $name:tt, suspicious, $description:tt } => {
118 $(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
121 { $(#[$attr:meta])* pub $name:tt, complexity, $description:tt } => {
123 $(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
126 { $(#[$attr:meta])* pub $name:tt, perf, $description:tt } => {
128 $(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
131 { $(#[$attr:meta])* pub $name:tt, pedantic, $description:tt } => {
133 $(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
136 { $(#[$attr:meta])* pub $name:tt, restriction, $description:tt } => {
138 $(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
141 { $(#[$attr:meta])* pub $name:tt, cargo, $description:tt } => {
143 $(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
146 { $(#[$attr:meta])* pub $name:tt, nursery, $description:tt } => {
148 $(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
151 { $(#[$attr:meta])* pub $name:tt, internal, $description:tt } => {
153 $(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
156 { $(#[$attr:meta])* pub $name:tt, internal_warn, $description:tt } => {
158 $(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
163 #[cfg(feature = "internal")]
164 pub mod deprecated_lints;
165 #[cfg_attr(feature = "internal", allow(clippy::missing_clippy_version_attribute))]
170 // begin lints modules, do not remove this comment, it’s used in `update_lints`
171 mod almost_complete_letter_range;
175 mod assertions_on_constants;
176 mod assertions_on_result_states;
177 mod async_yields_async;
179 mod await_holding_invalid;
180 mod blocks_in_if_conditions;
181 mod bool_assert_comparison;
182 mod bool_to_int_with_if;
184 mod borrow_deref_ref;
187 mod checked_conversions;
188 mod cognitive_complexity;
190 mod comparison_chain;
193 mod crate_in_macro_def;
197 mod default_instead_of_iter_empty;
198 mod default_numeric_fallback;
199 mod default_union_representation;
203 mod disallowed_methods;
204 mod disallowed_names;
205 mod disallowed_script_idents;
206 mod disallowed_types;
208 mod doc_link_with_quotes;
212 mod else_if_without_else;
215 mod empty_structs_with_brackets;
219 mod equatable_if_let;
223 mod exhaustive_items;
226 mod fallible_impl_from;
228 mod floating_point_arithmetic;
232 mod format_push_string;
235 mod from_str_radix_10;
240 mod if_then_some_else_none;
243 mod implicit_saturating_sub;
244 mod inconsistent_struct_constructor;
245 mod index_refutable_slice;
246 mod indexing_slicing;
249 mod inherent_to_string;
250 mod init_numbered_fields;
251 mod inline_fn_without_body;
253 mod invalid_upcast_comparisons;
254 mod invalid_utf8_in_unchecked;
255 mod items_after_statements;
256 mod iter_not_returning_iterator;
257 mod large_const_arrays;
258 mod large_enum_variant;
259 mod large_include_file;
260 mod large_stack_arrays;
265 mod literal_representation;
272 mod manual_instant_elapsed;
273 mod manual_non_exhaustive;
274 mod manual_rem_euclid;
276 mod manual_string_new;
287 mod mismatching_type_param_order;
288 mod missing_const_for_fn;
290 mod missing_enforced_import_rename;
292 mod mixed_read_write_in_expression;
294 mod multi_assignments;
298 mod mutable_debug_assertion;
300 mod needless_arbitrary_self_type;
302 mod needless_borrowed_ref;
303 mod needless_continue;
304 mod needless_for_each;
305 mod needless_late_init;
306 mod needless_parens_on_range_literals;
307 mod needless_pass_by_value;
308 mod needless_question_mark;
310 mod neg_cmp_op_on_partial_ord;
312 mod new_without_default;
315 mod non_expressive_names;
316 mod non_octal_unix_permissions;
317 mod non_send_fields_in_send_ty;
318 mod nonstandard_macro_braces;
320 mod only_used_in_recursion;
322 mod option_env_unwrap;
323 mod option_if_let_else;
324 mod overflow_check_conditional;
325 mod panic_in_result_fn;
326 mod panic_unimplemented;
327 mod partialeq_ne_impl;
328 mod partialeq_to_none;
329 mod pass_by_ref_or_value;
330 mod pattern_type_mismatch;
333 mod ptr_offset_with_cast;
337 mod rc_clone_in_vec_init;
338 mod read_zero_byte_vec;
340 mod redundant_closure_call;
342 mod redundant_field_names;
343 mod redundant_pub_crate;
344 mod redundant_slicing;
345 mod redundant_static_lifetimes;
349 mod return_self_not_must_use;
351 mod same_name_method;
352 mod self_named_constructors;
353 mod semicolon_if_nothing_returned;
356 mod single_char_lifetime_names;
357 mod single_component_path_imports;
358 mod size_of_in_element_count;
359 mod slow_vector_initialization;
360 mod std_instead_of_core;
362 mod strlen_on_c_strings;
363 mod suspicious_operation_groupings;
364 mod suspicious_trait_impl;
367 mod tabs_in_doc_comments;
368 mod temporary_assignment;
369 mod to_digit_is_some;
370 mod trailing_empty_array;
374 mod undocumented_unsafe_blocks;
377 mod unit_return_expecting_ord;
380 mod unnecessary_owned_empty_strings;
381 mod unnecessary_self_imports;
382 mod unnecessary_wraps;
383 mod unnested_or_patterns;
384 mod unsafe_removed_from_name;
386 mod unused_io_amount;
392 mod unwrap_in_result;
393 mod upper_case_acronyms;
395 mod useless_conversion;
397 mod vec_init_then_push;
398 mod wildcard_imports;
401 mod zero_sized_map_values;
402 // end lints modules, do not remove this comment, it’s used in `update_lints`
404 pub use crate::utils::conf::Conf;
405 use crate::utils::conf::{format_error, TryConf};
407 /// Register all pre expansion lints
409 /// Pre-expansion lints run before any macro expansion has happened.
411 /// Note that due to the architecture of the compiler, currently `cfg_attr` attributes on crate
412 /// level (i.e `#![cfg_attr(...)]`) will still be expanded even when using a pre-expansion pass.
414 /// Used in `./src/driver.rs`.
415 pub fn register_pre_expansion_lints(store: &mut rustc_lint::LintStore, sess: &Session, conf: &Conf) {
416 // NOTE: Do not add any more pre-expansion passes. These should be removed eventually.
418 let msrv = conf.msrv.as_ref().and_then(|s| {
419 parse_msrv(s, None, None).or_else(|| {
421 "error reading Clippy's configuration file. `{}` is not a valid Rust version",
428 store.register_pre_expansion_pass(|| Box::new(write::Write::default()));
429 store.register_pre_expansion_pass(move || Box::new(attrs::EarlyAttributes { msrv }));
432 fn read_msrv(conf: &Conf, sess: &Session) -> Option<RustcVersion> {
433 let cargo_msrv = std::env::var("CARGO_PKG_RUST_VERSION")
435 .and_then(|v| parse_msrv(&v, None, None));
436 let clippy_msrv = conf.msrv.as_ref().and_then(|s| {
437 parse_msrv(s, None, None).or_else(|| {
439 "error reading Clippy's configuration file. `{}` is not a valid Rust version",
446 if let Some(cargo_msrv) = cargo_msrv {
447 if let Some(clippy_msrv) = clippy_msrv {
448 // if both files have an msrv, let's compare them and emit a warning if they differ
449 if clippy_msrv != cargo_msrv {
451 "the MSRV in `clippy.toml` and `Cargo.toml` differ; using `{}` from `clippy.toml`",
466 pub fn read_conf(sess: &Session) -> Conf {
467 let file_name = match utils::conf::lookup_conf_file() {
468 Ok(Some(path)) => path,
469 Ok(None) => return Conf::default(),
471 sess.struct_err(&format!("error finding Clippy's configuration file: {}", error))
473 return Conf::default();
477 let TryConf { conf, errors, warnings } = utils::conf::read(&file_name);
478 // all conf errors are non-fatal, we just use the default conf in case of error
479 for error in errors {
481 "error reading Clippy's configuration file `{}`: {}",
487 for warning in warnings {
488 sess.struct_warn(&format!(
489 "error reading Clippy's configuration file `{}`: {}",
491 format_error(warning)
499 /// Register all lints and lint groups with the rustc plugin registry
501 /// Used in `./src/driver.rs`.
502 #[expect(clippy::too_many_lines)]
503 pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: &Conf) {
504 register_removed_non_tool_lints(store);
506 include!("lib.deprecated.rs");
508 include!("lib.register_lints.rs");
509 include!("lib.register_restriction.rs");
510 include!("lib.register_pedantic.rs");
512 #[cfg(feature = "internal")]
513 include!("lib.register_internal.rs");
515 include!("lib.register_all.rs");
516 include!("lib.register_style.rs");
517 include!("lib.register_complexity.rs");
518 include!("lib.register_correctness.rs");
519 include!("lib.register_suspicious.rs");
520 include!("lib.register_perf.rs");
521 include!("lib.register_cargo.rs");
522 include!("lib.register_nursery.rs");
524 #[cfg(feature = "internal")]
526 if std::env::var("ENABLE_METADATA_COLLECTION").eq(&Ok("1".to_string())) {
527 store.register_late_pass(|| Box::new(utils::internal_lints::metadata_collector::MetadataCollector::new()));
532 // all the internal lints
533 #[cfg(feature = "internal")]
535 store.register_early_pass(|| Box::new(utils::internal_lints::ClippyLintsInternal));
536 store.register_early_pass(|| Box::new(utils::internal_lints::ProduceIce));
537 store.register_late_pass(|_| Box::new(utils::internal_lints::CollapsibleCalls));
538 store.register_late_pass(|_| Box::new(utils::internal_lints::CompilerLintFunctions::new()));
539 store.register_late_pass(|_| Box::new(utils::internal_lints::IfChainStyle));
540 store.register_late_pass(|_| Box::new(utils::internal_lints::InvalidPaths));
541 store.register_late_pass(|_| Box::new(utils::internal_lints::InterningDefinedSymbol::default()));
542 store.register_late_pass(|_| Box::new(utils::internal_lints::LintWithoutLintPass::default()));
543 store.register_late_pass(|_| Box::new(utils::internal_lints::MatchTypeOnDiagItem));
544 store.register_late_pass(|_| Box::new(utils::internal_lints::OuterExpnDataPass));
545 store.register_late_pass(|_| Box::new(utils::internal_lints::MsrvAttrImpl));
548 let arithmetic_side_effects_allowed = conf.arithmetic_side_effects_allowed.clone();
549 store.register_late_pass(move |_| {
550 Box::new(operators::arithmetic_side_effects::ArithmeticSideEffects::new(
551 arithmetic_side_effects_allowed.clone(),
554 store.register_late_pass(|_| Box::new(utils::dump_hir::DumpHir));
555 store.register_late_pass(|_| Box::new(utils::author::Author));
556 let await_holding_invalid_types = conf.await_holding_invalid_types.clone();
557 store.register_late_pass(move |_| {
558 Box::new(await_holding_invalid::AwaitHolding::new(
559 await_holding_invalid_types.clone(),
562 store.register_late_pass(|_| Box::new(serde_api::SerdeApi));
563 let vec_box_size_threshold = conf.vec_box_size_threshold;
564 let type_complexity_threshold = conf.type_complexity_threshold;
565 let avoid_breaking_exported_api = conf.avoid_breaking_exported_api;
566 store.register_late_pass(move |_| {
567 Box::new(types::Types::new(
568 vec_box_size_threshold,
569 type_complexity_threshold,
570 avoid_breaking_exported_api,
573 store.register_late_pass(|_| Box::new(booleans::NonminimalBool));
574 store.register_late_pass(|_| Box::new(enum_clike::UnportableVariant));
575 store.register_late_pass(|_| Box::new(float_literal::FloatLiteral));
576 store.register_late_pass(|_| Box::new(ptr::Ptr));
577 store.register_late_pass(|_| Box::new(needless_bool::NeedlessBool));
578 store.register_late_pass(|_| Box::new(needless_bool::BoolComparison));
579 store.register_late_pass(|_| Box::new(needless_for_each::NeedlessForEach));
580 store.register_late_pass(|_| Box::new(misc::MiscLints));
581 store.register_late_pass(|_| Box::new(eta_reduction::EtaReduction));
582 store.register_late_pass(|_| Box::new(mut_mut::MutMut));
583 store.register_late_pass(|_| Box::new(mut_reference::UnnecessaryMutPassed));
584 store.register_late_pass(|_| Box::new(len_zero::LenZero));
585 store.register_late_pass(|_| Box::new(attrs::Attributes));
586 store.register_late_pass(|_| Box::new(blocks_in_if_conditions::BlocksInIfConditions));
587 store.register_late_pass(|_| Box::new(unicode::Unicode));
588 store.register_late_pass(|_| Box::new(uninit_vec::UninitVec));
589 store.register_late_pass(|_| Box::new(unit_return_expecting_ord::UnitReturnExpectingOrd));
590 store.register_late_pass(|_| Box::new(strings::StringAdd));
591 store.register_late_pass(|_| Box::new(implicit_return::ImplicitReturn));
592 store.register_late_pass(|_| Box::new(implicit_saturating_sub::ImplicitSaturatingSub));
593 store.register_late_pass(|_| Box::new(default_numeric_fallback::DefaultNumericFallback));
594 store.register_late_pass(|_| Box::new(inconsistent_struct_constructor::InconsistentStructConstructor));
595 store.register_late_pass(|_| Box::new(non_octal_unix_permissions::NonOctalUnixPermissions));
596 store.register_early_pass(|| Box::new(unnecessary_self_imports::UnnecessarySelfImports));
598 let msrv = read_msrv(conf, sess);
599 let avoid_breaking_exported_api = conf.avoid_breaking_exported_api;
600 let allow_expect_in_tests = conf.allow_expect_in_tests;
601 let allow_unwrap_in_tests = conf.allow_unwrap_in_tests;
602 store.register_late_pass(move |_| Box::new(approx_const::ApproxConstant::new(msrv)));
603 store.register_late_pass(move |_| {
604 Box::new(methods::Methods::new(
605 avoid_breaking_exported_api,
607 allow_expect_in_tests,
608 allow_unwrap_in_tests,
611 store.register_late_pass(move |_| Box::new(matches::Matches::new(msrv)));
612 store.register_early_pass(move || Box::new(manual_non_exhaustive::ManualNonExhaustiveStruct::new(msrv)));
613 store.register_late_pass(move |_| Box::new(manual_non_exhaustive::ManualNonExhaustiveEnum::new(msrv)));
614 store.register_late_pass(move |_| Box::new(manual_strip::ManualStrip::new(msrv)));
615 store.register_early_pass(move || Box::new(redundant_static_lifetimes::RedundantStaticLifetimes::new(msrv)));
616 store.register_early_pass(move || Box::new(redundant_field_names::RedundantFieldNames::new(msrv)));
617 store.register_late_pass(move |_| Box::new(checked_conversions::CheckedConversions::new(msrv)));
618 store.register_late_pass(move |_| Box::new(mem_replace::MemReplace::new(msrv)));
619 store.register_late_pass(move |_| Box::new(ranges::Ranges::new(msrv)));
620 store.register_late_pass(move |_| Box::new(from_over_into::FromOverInto::new(msrv)));
621 store.register_late_pass(move |_| Box::new(use_self::UseSelf::new(msrv)));
622 store.register_late_pass(move |_| Box::new(missing_const_for_fn::MissingConstForFn::new(msrv)));
623 store.register_late_pass(move |_| Box::new(needless_question_mark::NeedlessQuestionMark));
624 store.register_late_pass(move |_| Box::new(casts::Casts::new(msrv)));
625 store.register_early_pass(move || Box::new(unnested_or_patterns::UnnestedOrPatterns::new(msrv)));
626 store.register_late_pass(|_| Box::new(size_of_in_element_count::SizeOfInElementCount));
627 store.register_late_pass(|_| Box::new(same_name_method::SameNameMethod));
628 let max_suggested_slice_pattern_length = conf.max_suggested_slice_pattern_length;
629 store.register_late_pass(move |_| {
630 Box::new(index_refutable_slice::IndexRefutableSlice::new(
631 max_suggested_slice_pattern_length,
635 store.register_late_pass(|_| Box::new(shadow::Shadow::default()));
636 store.register_late_pass(|_| Box::new(unit_types::UnitTypes));
637 store.register_late_pass(|_| Box::new(loops::Loops));
638 store.register_late_pass(|_| Box::new(main_recursion::MainRecursion::default()));
639 store.register_late_pass(|_| Box::new(lifetimes::Lifetimes));
640 store.register_late_pass(|_| Box::new(entry::HashMapPass));
641 store.register_late_pass(|_| Box::new(minmax::MinMaxPass));
642 store.register_late_pass(|_| Box::new(zero_div_zero::ZeroDiv));
643 store.register_late_pass(|_| Box::new(mutex_atomic::Mutex));
644 store.register_late_pass(|_| Box::new(needless_update::NeedlessUpdate));
645 store.register_late_pass(|_| Box::new(needless_borrowed_ref::NeedlessBorrowedRef));
646 store.register_late_pass(|_| Box::new(borrow_deref_ref::BorrowDerefRef));
647 store.register_late_pass(|_| Box::new(no_effect::NoEffect));
648 store.register_late_pass(|_| Box::new(temporary_assignment::TemporaryAssignment));
649 store.register_late_pass(move |_| Box::new(transmute::Transmute::new(msrv)));
650 let cognitive_complexity_threshold = conf.cognitive_complexity_threshold;
651 store.register_late_pass(move |_| {
652 Box::new(cognitive_complexity::CognitiveComplexity::new(
653 cognitive_complexity_threshold,
656 let too_large_for_stack = conf.too_large_for_stack;
657 store.register_late_pass(move |_| Box::new(escape::BoxedLocal { too_large_for_stack }));
658 store.register_late_pass(move |_| Box::new(vec::UselessVec { too_large_for_stack }));
659 store.register_late_pass(|_| Box::new(panic_unimplemented::PanicUnimplemented));
660 store.register_late_pass(|_| Box::new(strings::StringLitAsBytes));
661 store.register_late_pass(|_| Box::new(derive::Derive));
662 store.register_late_pass(|_| Box::new(derivable_impls::DerivableImpls));
663 store.register_late_pass(|_| Box::new(drop_forget_ref::DropForgetRef));
664 store.register_late_pass(|_| Box::new(empty_enum::EmptyEnum));
665 store.register_late_pass(|_| Box::new(invalid_upcast_comparisons::InvalidUpcastComparisons));
666 store.register_late_pass(|_| Box::new(regex::Regex));
667 store.register_late_pass(|_| Box::new(copies::CopyAndPaste));
668 store.register_late_pass(|_| Box::new(copy_iterator::CopyIterator));
669 store.register_late_pass(|_| Box::new(format::UselessFormat));
670 store.register_late_pass(|_| Box::new(swap::Swap));
671 store.register_late_pass(|_| Box::new(overflow_check_conditional::OverflowCheckConditional));
672 store.register_late_pass(|_| Box::new(new_without_default::NewWithoutDefault::default()));
673 let disallowed_names = conf.disallowed_names.iter().cloned().collect::<FxHashSet<_>>();
674 store.register_late_pass(move |_| Box::new(disallowed_names::DisallowedNames::new(disallowed_names.clone())));
675 let too_many_arguments_threshold = conf.too_many_arguments_threshold;
676 let too_many_lines_threshold = conf.too_many_lines_threshold;
677 let large_error_threshold = conf.large_error_threshold;
678 store.register_late_pass(move |_| {
679 Box::new(functions::Functions::new(
680 too_many_arguments_threshold,
681 too_many_lines_threshold,
682 large_error_threshold,
685 let doc_valid_idents = conf.doc_valid_idents.iter().cloned().collect::<FxHashSet<_>>();
686 store.register_late_pass(move |_| Box::new(doc::DocMarkdown::new(doc_valid_idents.clone())));
687 store.register_late_pass(|_| Box::new(neg_multiply::NegMultiply));
688 store.register_late_pass(|_| Box::new(mem_forget::MemForget));
689 store.register_late_pass(|_| Box::new(let_if_seq::LetIfSeq));
690 store.register_late_pass(|_| Box::new(mixed_read_write_in_expression::EvalOrderDependence));
691 store.register_late_pass(|_| Box::new(missing_doc::MissingDoc::new()));
692 store.register_late_pass(|_| Box::new(missing_inline::MissingInline));
693 store.register_late_pass(move |_| Box::new(exhaustive_items::ExhaustiveItems));
694 store.register_late_pass(|_| Box::new(match_result_ok::MatchResultOk));
695 store.register_late_pass(|_| Box::new(partialeq_ne_impl::PartialEqNeImpl));
696 store.register_late_pass(|_| Box::new(unused_io_amount::UnusedIoAmount));
697 let enum_variant_size_threshold = conf.enum_variant_size_threshold;
698 store.register_late_pass(move |_| Box::new(large_enum_variant::LargeEnumVariant::new(enum_variant_size_threshold)));
699 store.register_late_pass(|_| Box::new(explicit_write::ExplicitWrite));
700 store.register_late_pass(|_| Box::new(needless_pass_by_value::NeedlessPassByValue));
701 let pass_by_ref_or_value = pass_by_ref_or_value::PassByRefOrValue::new(
702 conf.trivial_copy_size_limit,
703 conf.pass_by_value_size_limit,
704 conf.avoid_breaking_exported_api,
707 store.register_late_pass(move |_| Box::new(pass_by_ref_or_value));
708 store.register_late_pass(|_| Box::new(ref_option_ref::RefOptionRef));
709 store.register_late_pass(|_| Box::new(infinite_iter::InfiniteIter));
710 store.register_late_pass(|_| Box::new(inline_fn_without_body::InlineFnWithoutBody));
711 store.register_late_pass(|_| Box::new(useless_conversion::UselessConversion::default()));
712 store.register_late_pass(|_| Box::new(implicit_hasher::ImplicitHasher));
713 store.register_late_pass(|_| Box::new(fallible_impl_from::FallibleImplFrom));
714 store.register_late_pass(|_| Box::new(question_mark::QuestionMark));
715 store.register_early_pass(|| Box::new(suspicious_operation_groupings::SuspiciousOperationGroupings));
716 store.register_late_pass(|_| Box::new(suspicious_trait_impl::SuspiciousImpl));
717 store.register_late_pass(|_| Box::new(map_unit_fn::MapUnit));
718 store.register_late_pass(|_| Box::new(inherent_impl::MultipleInherentImpl));
719 store.register_late_pass(|_| Box::new(neg_cmp_op_on_partial_ord::NoNegCompOpForPartialOrd));
720 store.register_late_pass(|_| Box::new(unwrap::Unwrap));
721 store.register_late_pass(|_| Box::new(indexing_slicing::IndexingSlicing));
722 store.register_late_pass(|_| Box::new(non_copy_const::NonCopyConst));
723 store.register_late_pass(|_| Box::new(ptr_offset_with_cast::PtrOffsetWithCast));
724 store.register_late_pass(|_| Box::new(redundant_clone::RedundantClone));
725 store.register_late_pass(|_| Box::new(slow_vector_initialization::SlowVectorInit));
726 store.register_late_pass(move |_| Box::new(unnecessary_wraps::UnnecessaryWraps::new(avoid_breaking_exported_api)));
727 store.register_late_pass(|_| Box::new(assertions_on_constants::AssertionsOnConstants));
728 store.register_late_pass(|_| Box::new(assertions_on_result_states::AssertionsOnResultStates));
729 store.register_late_pass(|_| Box::new(inherent_to_string::InherentToString));
730 let max_trait_bounds = conf.max_trait_bounds;
731 store.register_late_pass(move |_| Box::new(trait_bounds::TraitBounds::new(max_trait_bounds)));
732 store.register_late_pass(|_| Box::new(comparison_chain::ComparisonChain));
733 store.register_late_pass(|_| Box::new(mut_key::MutableKeyType));
734 store.register_early_pass(|| Box::new(reference::DerefAddrOf));
735 store.register_early_pass(|| Box::new(double_parens::DoubleParens));
736 store.register_late_pass(|_| Box::new(format_impl::FormatImpl::new()));
737 store.register_early_pass(|| Box::new(unsafe_removed_from_name::UnsafeNameRemoval));
738 store.register_early_pass(|| Box::new(else_if_without_else::ElseIfWithoutElse));
739 store.register_early_pass(|| Box::new(int_plus_one::IntPlusOne));
740 store.register_early_pass(|| Box::new(formatting::Formatting));
741 store.register_early_pass(|| Box::new(misc_early::MiscEarlyLints));
742 store.register_early_pass(|| Box::new(redundant_closure_call::RedundantClosureCall));
743 store.register_late_pass(|_| Box::new(redundant_closure_call::RedundantClosureCall));
744 store.register_early_pass(|| Box::new(unused_unit::UnusedUnit));
745 store.register_late_pass(|_| Box::new(returns::Return));
746 store.register_early_pass(|| Box::new(collapsible_if::CollapsibleIf));
747 store.register_early_pass(|| Box::new(items_after_statements::ItemsAfterStatements));
748 store.register_early_pass(|| Box::new(precedence::Precedence));
749 store.register_late_pass(|_| Box::new(needless_parens_on_range_literals::NeedlessParensOnRangeLiterals));
750 store.register_early_pass(|| Box::new(needless_continue::NeedlessContinue));
751 store.register_early_pass(|| Box::new(redundant_else::RedundantElse));
752 store.register_late_pass(|_| Box::new(create_dir::CreateDir));
753 store.register_early_pass(|| Box::new(needless_arbitrary_self_type::NeedlessArbitrarySelfType));
754 let literal_representation_lint_fraction_readability = conf.unreadable_literal_lint_fractions;
755 store.register_early_pass(move || {
756 Box::new(literal_representation::LiteralDigitGrouping::new(
757 literal_representation_lint_fraction_readability,
760 let literal_representation_threshold = conf.literal_representation_threshold;
761 store.register_early_pass(move || {
762 Box::new(literal_representation::DecimalLiteralRepresentation::new(
763 literal_representation_threshold,
766 let enum_variant_name_threshold = conf.enum_variant_name_threshold;
767 store.register_late_pass(move |_| {
768 Box::new(enum_variants::EnumVariantNames::new(
769 enum_variant_name_threshold,
770 avoid_breaking_exported_api,
773 store.register_early_pass(|| Box::new(tabs_in_doc_comments::TabsInDocComments));
774 let upper_case_acronyms_aggressive = conf.upper_case_acronyms_aggressive;
775 store.register_late_pass(move |_| {
776 Box::new(upper_case_acronyms::UpperCaseAcronyms::new(
777 avoid_breaking_exported_api,
778 upper_case_acronyms_aggressive,
781 store.register_late_pass(|_| Box::new(default::Default::default()));
782 store.register_late_pass(move |_| Box::new(unused_self::UnusedSelf::new(avoid_breaking_exported_api)));
783 store.register_late_pass(|_| Box::new(mutable_debug_assertion::DebugAssertWithMutCall));
784 store.register_late_pass(|_| Box::new(exit::Exit));
785 store.register_late_pass(|_| Box::new(to_digit_is_some::ToDigitIsSome));
786 let array_size_threshold = conf.array_size_threshold;
787 store.register_late_pass(move |_| Box::new(large_stack_arrays::LargeStackArrays::new(array_size_threshold)));
788 store.register_late_pass(move |_| Box::new(large_const_arrays::LargeConstArrays::new(array_size_threshold)));
789 store.register_late_pass(|_| Box::new(floating_point_arithmetic::FloatingPointArithmetic));
790 store.register_early_pass(|| Box::new(as_conversions::AsConversions));
791 store.register_late_pass(|_| Box::new(let_underscore::LetUnderscore));
792 store.register_early_pass(|| Box::new(single_component_path_imports::SingleComponentPathImports));
793 let max_fn_params_bools = conf.max_fn_params_bools;
794 let max_struct_bools = conf.max_struct_bools;
795 store.register_early_pass(move || {
796 Box::new(excessive_bools::ExcessiveBools::new(
801 store.register_early_pass(|| Box::new(option_env_unwrap::OptionEnvUnwrap));
802 let warn_on_all_wildcard_imports = conf.warn_on_all_wildcard_imports;
803 store.register_late_pass(move |_| Box::new(wildcard_imports::WildcardImports::new(warn_on_all_wildcard_imports)));
804 store.register_late_pass(|_| Box::new(redundant_pub_crate::RedundantPubCrate::default()));
805 store.register_late_pass(|_| Box::new(unnamed_address::UnnamedAddress));
806 store.register_late_pass(move |_| Box::new(dereference::Dereferencing::new(msrv)));
807 store.register_late_pass(|_| Box::new(option_if_let_else::OptionIfLetElse));
808 store.register_late_pass(|_| Box::new(future_not_send::FutureNotSend));
809 store.register_late_pass(|_| Box::new(if_let_mutex::IfLetMutex));
810 store.register_late_pass(|_| Box::new(if_not_else::IfNotElse));
811 store.register_late_pass(|_| Box::new(equatable_if_let::PatternEquality));
812 store.register_late_pass(|_| Box::new(manual_async_fn::ManualAsyncFn));
813 store.register_late_pass(|_| Box::new(panic_in_result_fn::PanicInResultFn));
814 let single_char_binding_names_threshold = conf.single_char_binding_names_threshold;
815 store.register_early_pass(move || {
816 Box::new(non_expressive_names::NonExpressiveNames {
817 single_char_binding_names_threshold,
820 let macro_matcher = conf.standard_macro_braces.iter().cloned().collect::<FxHashSet<_>>();
821 store.register_early_pass(move || Box::new(nonstandard_macro_braces::MacroBraces::new(¯o_matcher)));
822 store.register_late_pass(|_| Box::new(macro_use::MacroUseImports::default()));
823 store.register_late_pass(|_| Box::new(pattern_type_mismatch::PatternTypeMismatch));
824 store.register_late_pass(|_| Box::new(unwrap_in_result::UnwrapInResult));
825 store.register_late_pass(|_| Box::new(semicolon_if_nothing_returned::SemicolonIfNothingReturned));
826 store.register_late_pass(|_| Box::new(async_yields_async::AsyncYieldsAsync));
827 let disallowed_methods = conf.disallowed_methods.clone();
828 store.register_late_pass(move |_| Box::new(disallowed_methods::DisallowedMethods::new(disallowed_methods.clone())));
829 store.register_early_pass(|| Box::new(asm_syntax::InlineAsmX86AttSyntax));
830 store.register_early_pass(|| Box::new(asm_syntax::InlineAsmX86IntelSyntax));
831 store.register_late_pass(|_| Box::new(empty_drop::EmptyDrop));
832 store.register_late_pass(|_| Box::new(strings::StrToString));
833 store.register_late_pass(|_| Box::new(strings::StringToString));
834 store.register_late_pass(|_| Box::new(zero_sized_map_values::ZeroSizedMapValues));
835 store.register_late_pass(|_| Box::new(vec_init_then_push::VecInitThenPush::default()));
836 store.register_late_pass(|_| Box::new(redundant_slicing::RedundantSlicing));
837 store.register_late_pass(|_| Box::new(from_str_radix_10::FromStrRadix10));
838 store.register_late_pass(move |_| Box::new(if_then_some_else_none::IfThenSomeElseNone::new(msrv)));
839 store.register_late_pass(|_| Box::new(bool_assert_comparison::BoolAssertComparison));
840 store.register_early_pass(move || Box::new(module_style::ModStyle));
841 store.register_late_pass(|_| Box::new(unused_async::UnusedAsync));
842 let disallowed_types = conf.disallowed_types.clone();
843 store.register_late_pass(move |_| Box::new(disallowed_types::DisallowedTypes::new(disallowed_types.clone())));
844 let import_renames = conf.enforced_import_renames.clone();
845 store.register_late_pass(move |_| {
846 Box::new(missing_enforced_import_rename::ImportRename::new(
847 import_renames.clone(),
850 let scripts = conf.allowed_scripts.clone();
851 store.register_early_pass(move || Box::new(disallowed_script_idents::DisallowedScriptIdents::new(&scripts)));
852 store.register_late_pass(|_| Box::new(strlen_on_c_strings::StrlenOnCStrings));
853 store.register_late_pass(move |_| Box::new(self_named_constructors::SelfNamedConstructors));
854 store.register_late_pass(move |_| Box::new(iter_not_returning_iterator::IterNotReturningIterator));
855 store.register_late_pass(move |_| Box::new(manual_assert::ManualAssert));
856 let enable_raw_pointer_heuristic_for_send = conf.enable_raw_pointer_heuristic_for_send;
857 store.register_late_pass(move |_| {
858 Box::new(non_send_fields_in_send_ty::NonSendFieldInSendTy::new(
859 enable_raw_pointer_heuristic_for_send,
862 store.register_late_pass(move |_| Box::new(undocumented_unsafe_blocks::UndocumentedUnsafeBlocks));
863 store.register_late_pass(move |_| Box::new(format_args::FormatArgs));
864 store.register_late_pass(|_| Box::new(trailing_empty_array::TrailingEmptyArray));
865 store.register_early_pass(|| Box::new(octal_escapes::OctalEscapes));
866 store.register_late_pass(|_| Box::new(needless_late_init::NeedlessLateInit));
867 store.register_late_pass(|_| Box::new(return_self_not_must_use::ReturnSelfNotMustUse));
868 store.register_late_pass(|_| Box::new(init_numbered_fields::NumberedFields));
869 store.register_early_pass(|| Box::new(single_char_lifetime_names::SingleCharLifetimeNames));
870 store.register_late_pass(move |_| Box::new(manual_bits::ManualBits::new(msrv)));
871 store.register_late_pass(|_| Box::new(default_union_representation::DefaultUnionRepresentation));
872 store.register_early_pass(|| Box::new(doc_link_with_quotes::DocLinkWithQuotes));
873 store.register_late_pass(|_| Box::new(only_used_in_recursion::OnlyUsedInRecursion::default()));
874 let allow_dbg_in_tests = conf.allow_dbg_in_tests;
875 store.register_late_pass(move |_| Box::new(dbg_macro::DbgMacro::new(allow_dbg_in_tests)));
876 let cargo_ignore_publish = conf.cargo_ignore_publish;
877 store.register_late_pass(move |_| {
878 Box::new(cargo::Cargo {
879 ignore_publish: cargo_ignore_publish,
882 store.register_early_pass(|| Box::new(crate_in_macro_def::CrateInMacroDef));
883 store.register_early_pass(|| Box::new(empty_structs_with_brackets::EmptyStructsWithBrackets));
884 store.register_late_pass(|_| Box::new(unnecessary_owned_empty_strings::UnnecessaryOwnedEmptyStrings));
885 store.register_early_pass(|| Box::new(pub_use::PubUse));
886 store.register_late_pass(|_| Box::new(format_push_string::FormatPushString));
887 let max_include_file_size = conf.max_include_file_size;
888 store.register_late_pass(move |_| Box::new(large_include_file::LargeIncludeFile::new(max_include_file_size)));
889 store.register_late_pass(|_| Box::new(strings::TrimSplitWhitespace));
890 store.register_late_pass(|_| Box::new(rc_clone_in_vec_init::RcCloneInVecInit));
891 store.register_early_pass(|| Box::new(duplicate_mod::DuplicateMod::default()));
892 store.register_early_pass(|| Box::new(unused_rounding::UnusedRounding));
893 store.register_early_pass(move || Box::new(almost_complete_letter_range::AlmostCompleteLetterRange::new(msrv)));
894 store.register_late_pass(|_| Box::new(swap_ptr_to_ref::SwapPtrToRef));
895 store.register_late_pass(|_| Box::new(mismatching_type_param_order::TypeParamMismatch));
896 store.register_late_pass(|_| Box::new(read_zero_byte_vec::ReadZeroByteVec));
897 store.register_late_pass(|_| Box::new(default_instead_of_iter_empty::DefaultIterEmpty));
898 store.register_late_pass(move |_| Box::new(manual_rem_euclid::ManualRemEuclid::new(msrv)));
899 store.register_late_pass(move |_| Box::new(manual_retain::ManualRetain::new(msrv)));
900 let verbose_bit_mask_threshold = conf.verbose_bit_mask_threshold;
901 store.register_late_pass(move |_| Box::new(operators::Operators::new(verbose_bit_mask_threshold)));
902 store.register_late_pass(|_| Box::new(invalid_utf8_in_unchecked::InvalidUtf8InUnchecked));
903 store.register_late_pass(|_| Box::new(std_instead_of_core::StdReexports::default()));
904 store.register_late_pass(|_| Box::new(manual_instant_elapsed::ManualInstantElapsed));
905 store.register_late_pass(|_| Box::new(partialeq_to_none::PartialeqToNone));
906 store.register_late_pass(|_| Box::new(manual_string_new::ManualStringNew));
907 store.register_late_pass(|_| Box::new(unused_peekable::UnusedPeekable));
908 store.register_early_pass(|| Box::new(multi_assignments::MultiAssignments));
909 store.register_late_pass(|_| Box::new(bool_to_int_with_if::BoolToIntWithIf));
910 // add lints here, do not remove this comment, it's used in `new_lint`
914 fn register_removed_non_tool_lints(store: &mut rustc_lint::LintStore) {
915 store.register_removed(
917 "`assert!()` will be more flexible with RFC 2011",
919 store.register_removed(
921 "`.extend_from_slice(_)` is a faster way to extend a Vec by a slice",
923 store.register_removed(
924 "range_step_by_zero",
925 "`iterator.step_by(0)` panics nowadays",
927 store.register_removed(
929 "`Vec::as_slice` has been stabilized in 1.7",
931 store.register_removed(
932 "unstable_as_mut_slice",
933 "`Vec::as_mut_slice` has been stabilized in 1.7",
935 store.register_removed(
936 "misaligned_transmute",
937 "this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr",
939 store.register_removed(
941 "using compound assignment operators (e.g., `+=`) is harmless",
943 store.register_removed(
944 "if_let_redundant_pattern_matching",
945 "this lint has been changed to redundant_pattern_matching",
947 store.register_removed(
948 "unsafe_vector_initialization",
949 "the replacement suggested by this lint had substantially different behavior",
951 store.register_removed(
952 "reverse_range_loop",
953 "this lint is now included in reversed_empty_ranges",
957 /// Register renamed lints.
959 /// Used in `./src/driver.rs`.
960 pub fn register_renamed(ls: &mut rustc_lint::LintStore) {
961 for (old_name, new_name) in renamed_lints::RENAMED_LINTS {
962 ls.register_renamed(old_name, new_name);
966 // only exists to let the dogfood integration test works.
967 // Don't run clippy as an executable directly
970 panic!("Please use the cargo-clippy executable");