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)]
8 #![feature(lint_reasons)]
9 #![feature(never_type)]
10 #![feature(once_cell)]
11 #![feature(rustc_private)]
12 #![feature(stmt_expr_attributes)]
13 #![recursion_limit = "512"]
14 #![cfg_attr(feature = "deny-warnings", deny(warnings))]
15 #![allow(clippy::missing_docs_in_private_items, clippy::must_use_candidate)]
16 #![warn(trivial_casts, trivial_numeric_casts)]
17 // warn on lints, that are included in `rust-lang/rust`s bootstrap
18 #![warn(rust_2018_idioms, unused_lifetimes)]
19 // warn on rustc internal lints
20 #![warn(rustc::internal)]
21 // Disable this rustc lint for now, as it was also done in rustc
22 #![allow(rustc::potential_query_instability)]
24 // FIXME: switch to something more ergonomic here, once available.
25 // (Currently there is no way to opt into sysroot crates without `extern crate`.)
26 extern crate rustc_arena;
27 extern crate rustc_ast;
28 extern crate rustc_ast_pretty;
29 extern crate rustc_attr;
30 extern crate rustc_data_structures;
31 extern crate rustc_driver;
32 extern crate rustc_errors;
33 extern crate rustc_hir;
34 extern crate rustc_hir_analysis;
35 extern crate rustc_hir_typeck;
36 extern crate rustc_hir_pretty;
37 extern crate rustc_index;
38 extern crate rustc_infer;
39 extern crate rustc_lexer;
40 extern crate rustc_lint;
41 extern crate rustc_middle;
42 extern crate rustc_parse;
43 extern crate rustc_session;
44 extern crate rustc_span;
45 extern crate rustc_target;
46 extern crate rustc_trait_selection;
49 extern crate clippy_utils;
51 use clippy_utils::parse_msrv;
52 use rustc_data_structures::fx::FxHashSet;
53 use rustc_lint::LintId;
54 use rustc_semver::RustcVersion;
55 use rustc_session::Session;
57 /// Macro used to declare a Clippy lint.
59 /// Every lint declaration consists of 4 parts:
61 /// 1. The documentation, which is used for the website
62 /// 2. The `LINT_NAME`. See [lint naming][lint_naming] on lint naming conventions.
63 /// 3. The `lint_level`, which is a mapping from *one* of our lint groups to `Allow`, `Warn` or
64 /// `Deny`. The lint level here has nothing to do with what lint groups the lint is a part of.
65 /// 4. The `description` that contains a short explanation on what's wrong with code where the
66 /// lint is triggered.
68 /// Currently the categories `style`, `correctness`, `suspicious`, `complexity` and `perf` are
69 /// enabled by default. As said in the README.md of this repository, if the lint level mapping
70 /// changes, please update README.md.
75 /// #![feature(rustc_private)]
76 /// extern crate rustc_session;
77 /// use rustc_session::declare_tool_lint;
78 /// use clippy_lints::declare_clippy_lint;
80 /// declare_clippy_lint! {
81 /// /// ### What it does
82 /// /// Checks for ... (describe what the lint matches).
84 /// /// ### Why is this bad?
85 /// /// Supply the reason for linting the code.
89 /// /// Insert a short example of code that triggers the lint
94 /// /// Insert a short example of improved code that doesn't trigger the lint
101 /// [lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints
103 macro_rules! declare_clippy_lint {
104 { $(#[$attr:meta])* pub $name:tt, style, $description:tt } => {
106 $(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
109 { $(#[$attr:meta])* pub $name:tt, correctness, $description:tt } => {
111 $(#[$attr])* pub clippy::$name, Deny, $description, report_in_external_macro: true
114 { $(#[$attr:meta])* pub $name:tt, suspicious, $description:tt } => {
116 $(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
119 { $(#[$attr:meta])* pub $name:tt, complexity, $description:tt } => {
121 $(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
124 { $(#[$attr:meta])* pub $name:tt, perf, $description:tt } => {
126 $(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
129 { $(#[$attr:meta])* pub $name:tt, pedantic, $description:tt } => {
131 $(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
134 { $(#[$attr:meta])* pub $name:tt, restriction, $description:tt } => {
136 $(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
139 { $(#[$attr:meta])* pub $name:tt, cargo, $description:tt } => {
141 $(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
144 { $(#[$attr:meta])* pub $name:tt, nursery, $description:tt } => {
146 $(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
149 { $(#[$attr:meta])* pub $name:tt, internal, $description:tt } => {
151 $(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
154 { $(#[$attr:meta])* pub $name:tt, internal_warn, $description:tt } => {
156 $(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
161 #[cfg(feature = "internal")]
162 pub mod deprecated_lints;
163 #[cfg_attr(feature = "internal", allow(clippy::missing_clippy_version_attribute))]
168 // begin lints modules, do not remove this comment, it’s used in `update_lints`
169 mod almost_complete_letter_range;
173 mod assertions_on_constants;
174 mod assertions_on_result_states;
175 mod async_yields_async;
177 mod await_holding_invalid;
178 mod blocks_in_if_conditions;
179 mod bool_assert_comparison;
180 mod bool_to_int_with_if;
182 mod borrow_deref_ref;
186 mod checked_conversions;
187 mod cognitive_complexity;
189 mod comparison_chain;
192 mod crate_in_macro_def;
196 mod default_instead_of_iter_empty;
197 mod default_numeric_fallback;
198 mod default_union_representation;
202 mod disallowed_macros;
203 mod disallowed_methods;
204 mod disallowed_names;
205 mod disallowed_script_idents;
206 mod disallowed_types;
211 mod else_if_without_else;
214 mod empty_structs_with_brackets;
218 mod equatable_if_let;
222 mod exhaustive_items;
225 mod fallible_impl_from;
227 mod floating_point_arithmetic;
231 mod format_push_string;
234 mod from_str_radix_10;
239 mod if_then_some_else_none;
242 mod implicit_saturating_add;
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;
273 mod manual_instant_elapsed;
274 mod manual_non_exhaustive;
275 mod manual_rem_euclid;
277 mod manual_string_new;
288 mod mismatching_type_param_order;
289 mod missing_const_for_fn;
291 mod missing_enforced_import_rename;
293 mod missing_trait_methods;
294 mod mixed_read_write_in_expression;
296 mod multi_assignments;
300 mod mutable_debug_assertion;
302 mod needless_arbitrary_self_type;
304 mod needless_borrowed_ref;
305 mod needless_continue;
306 mod needless_for_each;
307 mod needless_late_init;
308 mod needless_parens_on_range_literals;
309 mod needless_pass_by_value;
310 mod needless_question_mark;
312 mod neg_cmp_op_on_partial_ord;
314 mod new_without_default;
317 mod non_expressive_names;
318 mod non_octal_unix_permissions;
319 mod non_send_fields_in_send_ty;
320 mod nonstandard_macro_braces;
322 mod only_used_in_recursion;
324 mod option_env_unwrap;
325 mod option_if_let_else;
326 mod overflow_check_conditional;
327 mod panic_in_result_fn;
328 mod panic_unimplemented;
329 mod partial_pub_fields;
330 mod partialeq_ne_impl;
331 mod partialeq_to_none;
332 mod pass_by_ref_or_value;
333 mod pattern_type_mismatch;
336 mod ptr_offset_with_cast;
340 mod rc_clone_in_vec_init;
341 mod read_zero_byte_vec;
343 mod redundant_closure_call;
345 mod redundant_field_names;
346 mod redundant_pub_crate;
347 mod redundant_slicing;
348 mod redundant_static_lifetimes;
352 mod return_self_not_must_use;
354 mod same_name_method;
355 mod self_named_constructors;
356 mod semicolon_if_nothing_returned;
359 mod single_char_lifetime_names;
360 mod single_component_path_imports;
361 mod size_of_in_element_count;
362 mod slow_vector_initialization;
363 mod std_instead_of_core;
365 mod strlen_on_c_strings;
366 mod suspicious_operation_groupings;
367 mod suspicious_trait_impl;
370 mod tabs_in_doc_comments;
371 mod temporary_assignment;
372 mod to_digit_is_some;
373 mod trailing_empty_array;
377 mod undocumented_unsafe_blocks;
380 mod unit_return_expecting_ord;
383 mod unnecessary_owned_empty_strings;
384 mod unnecessary_self_imports;
385 mod unnecessary_wraps;
386 mod unnested_or_patterns;
387 mod unsafe_removed_from_name;
389 mod unused_io_amount;
395 mod unwrap_in_result;
396 mod upper_case_acronyms;
398 mod useless_conversion;
400 mod vec_init_then_push;
401 mod wildcard_imports;
404 mod zero_sized_map_values;
405 // end lints modules, do not remove this comment, it’s used in `update_lints`
407 pub use crate::utils::conf::Conf;
408 use crate::utils::conf::{format_error, TryConf};
410 /// Register all pre expansion lints
412 /// Pre-expansion lints run before any macro expansion has happened.
414 /// Note that due to the architecture of the compiler, currently `cfg_attr` attributes on crate
415 /// level (i.e `#![cfg_attr(...)]`) will still be expanded even when using a pre-expansion pass.
417 /// Used in `./src/driver.rs`.
418 pub fn register_pre_expansion_lints(store: &mut rustc_lint::LintStore, sess: &Session, conf: &Conf) {
419 // NOTE: Do not add any more pre-expansion passes. These should be removed eventually.
421 let msrv = conf.msrv.as_ref().and_then(|s| {
422 parse_msrv(s, None, None).or_else(|| {
424 "error reading Clippy's configuration file. `{s}` is not a valid Rust version"
430 store.register_pre_expansion_pass(move || Box::new(attrs::EarlyAttributes { msrv }));
433 fn read_msrv(conf: &Conf, sess: &Session) -> Option<RustcVersion> {
434 let cargo_msrv = std::env::var("CARGO_PKG_RUST_VERSION")
436 .and_then(|v| parse_msrv(&v, None, None));
437 let clippy_msrv = conf.msrv.as_ref().and_then(|s| {
438 parse_msrv(s, None, None).or_else(|| {
440 "error reading Clippy's configuration file. `{s}` 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 `{clippy_msrv}` from `clippy.toml`"
465 pub fn read_conf(sess: &Session) -> Conf {
466 let file_name = match utils::conf::lookup_conf_file() {
467 Ok(Some(path)) => path,
468 Ok(None) => return Conf::default(),
470 sess.struct_err(&format!("error finding Clippy's configuration file: {error}"))
472 return Conf::default();
476 let TryConf { conf, errors, warnings } = utils::conf::read(&file_name);
477 // all conf errors are non-fatal, we just use the default conf in case of error
478 for error in errors {
480 "error reading Clippy's configuration file `{}`: {}",
486 for warning in warnings {
487 sess.struct_warn(format!(
488 "error reading Clippy's configuration file `{}`: {}",
490 format_error(warning)
498 /// Register all lints and lint groups with the rustc plugin registry
500 /// Used in `./src/driver.rs`.
501 #[expect(clippy::too_many_lines)]
502 pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: &Conf) {
503 register_removed_non_tool_lints(store);
505 include!("lib.deprecated.rs");
507 include!("lib.register_lints.rs");
508 include!("lib.register_restriction.rs");
509 include!("lib.register_pedantic.rs");
511 #[cfg(feature = "internal")]
512 include!("lib.register_internal.rs");
514 include!("lib.register_all.rs");
515 include!("lib.register_style.rs");
516 include!("lib.register_complexity.rs");
517 include!("lib.register_correctness.rs");
518 include!("lib.register_suspicious.rs");
519 include!("lib.register_perf.rs");
520 include!("lib.register_cargo.rs");
521 include!("lib.register_nursery.rs");
523 #[cfg(feature = "internal")]
525 if std::env::var("ENABLE_METADATA_COLLECTION").eq(&Ok("1".to_string())) {
526 store.register_late_pass(|_| Box::new(utils::internal_lints::metadata_collector::MetadataCollector::new()));
531 // all the internal lints
532 #[cfg(feature = "internal")]
534 store.register_early_pass(|| Box::new(utils::internal_lints::clippy_lints_internal::ClippyLintsInternal));
535 store.register_early_pass(|| Box::new(utils::internal_lints::produce_ice::ProduceIce));
536 store.register_late_pass(|_| Box::new(utils::internal_lints::collapsible_calls::CollapsibleCalls));
537 store.register_late_pass(|_| {
538 Box::new(utils::internal_lints::compiler_lint_functions::CompilerLintFunctions::new())
540 store.register_late_pass(|_| Box::new(utils::internal_lints::if_chain_style::IfChainStyle));
541 store.register_late_pass(|_| Box::new(utils::internal_lints::invalid_paths::InvalidPaths));
542 store.register_late_pass(|_| {
543 Box::<utils::internal_lints::interning_defined_symbol::InterningDefinedSymbol>::default()
545 store.register_late_pass(|_| {
546 Box::<utils::internal_lints::lint_without_lint_pass::LintWithoutLintPass>::default()
548 store.register_late_pass(|_| Box::<utils::internal_lints::unnecessary_def_path::UnnecessaryDefPath>::default());
549 store.register_late_pass(|_| Box::new(utils::internal_lints::outer_expn_data_pass::OuterExpnDataPass));
550 store.register_late_pass(|_| Box::new(utils::internal_lints::msrv_attr_impl::MsrvAttrImpl));
553 let arithmetic_side_effects_allowed = conf.arithmetic_side_effects_allowed.clone();
554 store.register_late_pass(move |_| {
555 Box::new(operators::arithmetic_side_effects::ArithmeticSideEffects::new(
556 arithmetic_side_effects_allowed.clone(),
559 store.register_late_pass(|_| Box::new(utils::dump_hir::DumpHir));
560 store.register_late_pass(|_| Box::new(utils::author::Author));
561 let await_holding_invalid_types = conf.await_holding_invalid_types.clone();
562 store.register_late_pass(move |_| {
563 Box::new(await_holding_invalid::AwaitHolding::new(
564 await_holding_invalid_types.clone(),
567 store.register_late_pass(|_| Box::new(serde_api::SerdeApi));
568 let vec_box_size_threshold = conf.vec_box_size_threshold;
569 let type_complexity_threshold = conf.type_complexity_threshold;
570 let avoid_breaking_exported_api = conf.avoid_breaking_exported_api;
571 store.register_late_pass(move |_| {
572 Box::new(types::Types::new(
573 vec_box_size_threshold,
574 type_complexity_threshold,
575 avoid_breaking_exported_api,
578 store.register_late_pass(|_| Box::new(booleans::NonminimalBool));
579 store.register_late_pass(|_| Box::new(enum_clike::UnportableVariant));
580 store.register_late_pass(|_| Box::new(float_literal::FloatLiteral));
581 store.register_late_pass(|_| Box::new(ptr::Ptr));
582 store.register_late_pass(|_| Box::new(needless_bool::NeedlessBool));
583 store.register_late_pass(|_| Box::new(needless_bool::BoolComparison));
584 store.register_late_pass(|_| Box::new(needless_for_each::NeedlessForEach));
585 store.register_late_pass(|_| Box::new(misc::MiscLints));
586 store.register_late_pass(|_| Box::new(eta_reduction::EtaReduction));
587 store.register_late_pass(|_| Box::new(mut_mut::MutMut));
588 store.register_late_pass(|_| Box::new(mut_reference::UnnecessaryMutPassed));
589 store.register_late_pass(|_| Box::new(len_zero::LenZero));
590 store.register_late_pass(|_| Box::new(attrs::Attributes));
591 store.register_late_pass(|_| Box::new(blocks_in_if_conditions::BlocksInIfConditions));
592 store.register_late_pass(|_| Box::new(unicode::Unicode));
593 store.register_late_pass(|_| Box::new(uninit_vec::UninitVec));
594 store.register_late_pass(|_| Box::new(unit_return_expecting_ord::UnitReturnExpectingOrd));
595 store.register_late_pass(|_| Box::new(strings::StringAdd));
596 store.register_late_pass(|_| Box::new(implicit_return::ImplicitReturn));
597 store.register_late_pass(|_| Box::new(implicit_saturating_sub::ImplicitSaturatingSub));
598 store.register_late_pass(|_| Box::new(default_numeric_fallback::DefaultNumericFallback));
599 store.register_late_pass(|_| Box::new(inconsistent_struct_constructor::InconsistentStructConstructor));
600 store.register_late_pass(|_| Box::new(non_octal_unix_permissions::NonOctalUnixPermissions));
601 store.register_early_pass(|| Box::new(unnecessary_self_imports::UnnecessarySelfImports));
603 let msrv = read_msrv(conf, sess);
604 let avoid_breaking_exported_api = conf.avoid_breaking_exported_api;
605 let allow_expect_in_tests = conf.allow_expect_in_tests;
606 let allow_unwrap_in_tests = conf.allow_unwrap_in_tests;
607 store.register_late_pass(move |_| Box::new(approx_const::ApproxConstant::new(msrv)));
608 store.register_late_pass(move |_| {
609 Box::new(methods::Methods::new(
610 avoid_breaking_exported_api,
612 allow_expect_in_tests,
613 allow_unwrap_in_tests,
616 store.register_late_pass(move |_| Box::new(matches::Matches::new(msrv)));
617 store.register_early_pass(move || Box::new(manual_non_exhaustive::ManualNonExhaustiveStruct::new(msrv)));
618 store.register_late_pass(move |_| Box::new(manual_non_exhaustive::ManualNonExhaustiveEnum::new(msrv)));
619 store.register_late_pass(move |_| Box::new(manual_strip::ManualStrip::new(msrv)));
620 store.register_early_pass(move || Box::new(redundant_static_lifetimes::RedundantStaticLifetimes::new(msrv)));
621 store.register_early_pass(move || Box::new(redundant_field_names::RedundantFieldNames::new(msrv)));
622 store.register_late_pass(move |_| Box::new(checked_conversions::CheckedConversions::new(msrv)));
623 store.register_late_pass(move |_| Box::new(mem_replace::MemReplace::new(msrv)));
624 store.register_late_pass(move |_| Box::new(ranges::Ranges::new(msrv)));
625 store.register_late_pass(move |_| Box::new(from_over_into::FromOverInto::new(msrv)));
626 store.register_late_pass(move |_| Box::new(use_self::UseSelf::new(msrv)));
627 store.register_late_pass(move |_| Box::new(missing_const_for_fn::MissingConstForFn::new(msrv)));
628 store.register_late_pass(move |_| Box::new(needless_question_mark::NeedlessQuestionMark));
629 store.register_late_pass(move |_| Box::new(casts::Casts::new(msrv)));
630 store.register_early_pass(move || Box::new(unnested_or_patterns::UnnestedOrPatterns::new(msrv)));
631 store.register_late_pass(|_| Box::new(size_of_in_element_count::SizeOfInElementCount));
632 store.register_late_pass(|_| Box::new(same_name_method::SameNameMethod));
633 let max_suggested_slice_pattern_length = conf.max_suggested_slice_pattern_length;
634 store.register_late_pass(move |_| {
635 Box::new(index_refutable_slice::IndexRefutableSlice::new(
636 max_suggested_slice_pattern_length,
640 store.register_late_pass(|_| Box::<shadow::Shadow>::default());
641 store.register_late_pass(|_| Box::new(unit_types::UnitTypes));
642 store.register_late_pass(|_| Box::new(loops::Loops));
643 store.register_late_pass(|_| Box::<main_recursion::MainRecursion>::default());
644 store.register_late_pass(|_| Box::new(lifetimes::Lifetimes));
645 store.register_late_pass(|_| Box::new(entry::HashMapPass));
646 store.register_late_pass(|_| Box::new(minmax::MinMaxPass));
647 store.register_late_pass(|_| Box::new(zero_div_zero::ZeroDiv));
648 store.register_late_pass(|_| Box::new(mutex_atomic::Mutex));
649 store.register_late_pass(|_| Box::new(needless_update::NeedlessUpdate));
650 store.register_late_pass(|_| Box::new(needless_borrowed_ref::NeedlessBorrowedRef));
651 store.register_late_pass(|_| Box::new(borrow_deref_ref::BorrowDerefRef));
652 store.register_late_pass(|_| Box::new(no_effect::NoEffect));
653 store.register_late_pass(|_| Box::new(temporary_assignment::TemporaryAssignment));
654 store.register_late_pass(move |_| Box::new(transmute::Transmute::new(msrv)));
655 let cognitive_complexity_threshold = conf.cognitive_complexity_threshold;
656 store.register_late_pass(move |_| {
657 Box::new(cognitive_complexity::CognitiveComplexity::new(
658 cognitive_complexity_threshold,
661 let too_large_for_stack = conf.too_large_for_stack;
662 store.register_late_pass(move |_| Box::new(escape::BoxedLocal { too_large_for_stack }));
663 store.register_late_pass(move |_| Box::new(vec::UselessVec { too_large_for_stack }));
664 store.register_late_pass(|_| Box::new(panic_unimplemented::PanicUnimplemented));
665 store.register_late_pass(|_| Box::new(strings::StringLitAsBytes));
666 store.register_late_pass(|_| Box::new(derive::Derive));
667 store.register_late_pass(|_| Box::new(derivable_impls::DerivableImpls));
668 store.register_late_pass(|_| Box::new(drop_forget_ref::DropForgetRef));
669 store.register_late_pass(|_| Box::new(empty_enum::EmptyEnum));
670 store.register_late_pass(|_| Box::new(invalid_upcast_comparisons::InvalidUpcastComparisons));
671 store.register_late_pass(|_| Box::new(regex::Regex));
672 store.register_late_pass(|_| Box::new(copies::CopyAndPaste));
673 store.register_late_pass(|_| Box::new(copy_iterator::CopyIterator));
674 store.register_late_pass(|_| Box::new(format::UselessFormat));
675 store.register_late_pass(|_| Box::new(swap::Swap));
676 store.register_late_pass(|_| Box::new(overflow_check_conditional::OverflowCheckConditional));
677 store.register_late_pass(|_| Box::<new_without_default::NewWithoutDefault>::default());
678 let disallowed_names = conf.disallowed_names.iter().cloned().collect::<FxHashSet<_>>();
679 store.register_late_pass(move |_| Box::new(disallowed_names::DisallowedNames::new(disallowed_names.clone())));
680 let too_many_arguments_threshold = conf.too_many_arguments_threshold;
681 let too_many_lines_threshold = conf.too_many_lines_threshold;
682 let large_error_threshold = conf.large_error_threshold;
683 store.register_late_pass(move |_| {
684 Box::new(functions::Functions::new(
685 too_many_arguments_threshold,
686 too_many_lines_threshold,
687 large_error_threshold,
690 let doc_valid_idents = conf.doc_valid_idents.iter().cloned().collect::<FxHashSet<_>>();
691 store.register_late_pass(move |_| Box::new(doc::DocMarkdown::new(doc_valid_idents.clone())));
692 store.register_late_pass(|_| Box::new(neg_multiply::NegMultiply));
693 store.register_late_pass(|_| Box::new(mem_forget::MemForget));
694 store.register_late_pass(|_| Box::new(let_if_seq::LetIfSeq));
695 store.register_late_pass(|_| Box::new(mixed_read_write_in_expression::EvalOrderDependence));
696 store.register_late_pass(|_| Box::new(missing_doc::MissingDoc::new()));
697 store.register_late_pass(|_| Box::new(missing_inline::MissingInline));
698 store.register_late_pass(move |_| Box::new(exhaustive_items::ExhaustiveItems));
699 store.register_late_pass(|_| Box::new(match_result_ok::MatchResultOk));
700 store.register_late_pass(|_| Box::new(partialeq_ne_impl::PartialEqNeImpl));
701 store.register_late_pass(|_| Box::new(unused_io_amount::UnusedIoAmount));
702 let enum_variant_size_threshold = conf.enum_variant_size_threshold;
703 store.register_late_pass(move |_| Box::new(large_enum_variant::LargeEnumVariant::new(enum_variant_size_threshold)));
704 store.register_late_pass(|_| Box::new(explicit_write::ExplicitWrite));
705 store.register_late_pass(|_| Box::new(needless_pass_by_value::NeedlessPassByValue));
706 let pass_by_ref_or_value = pass_by_ref_or_value::PassByRefOrValue::new(
707 conf.trivial_copy_size_limit,
708 conf.pass_by_value_size_limit,
709 conf.avoid_breaking_exported_api,
712 store.register_late_pass(move |_| Box::new(pass_by_ref_or_value));
713 store.register_late_pass(|_| Box::new(ref_option_ref::RefOptionRef));
714 store.register_late_pass(|_| Box::new(infinite_iter::InfiniteIter));
715 store.register_late_pass(|_| Box::new(inline_fn_without_body::InlineFnWithoutBody));
716 store.register_late_pass(|_| Box::<useless_conversion::UselessConversion>::default());
717 store.register_late_pass(|_| Box::new(implicit_hasher::ImplicitHasher));
718 store.register_late_pass(|_| Box::new(fallible_impl_from::FallibleImplFrom));
719 store.register_late_pass(|_| Box::new(question_mark::QuestionMark));
720 store.register_early_pass(|| Box::new(suspicious_operation_groupings::SuspiciousOperationGroupings));
721 store.register_late_pass(|_| Box::new(suspicious_trait_impl::SuspiciousImpl));
722 store.register_late_pass(|_| Box::new(map_unit_fn::MapUnit));
723 store.register_late_pass(|_| Box::new(inherent_impl::MultipleInherentImpl));
724 store.register_late_pass(|_| Box::new(neg_cmp_op_on_partial_ord::NoNegCompOpForPartialOrd));
725 store.register_late_pass(|_| Box::new(unwrap::Unwrap));
726 store.register_late_pass(|_| Box::new(indexing_slicing::IndexingSlicing));
727 store.register_late_pass(|_| Box::new(non_copy_const::NonCopyConst));
728 store.register_late_pass(|_| Box::new(ptr_offset_with_cast::PtrOffsetWithCast));
729 store.register_late_pass(|_| Box::new(redundant_clone::RedundantClone));
730 store.register_late_pass(|_| Box::new(slow_vector_initialization::SlowVectorInit));
731 store.register_late_pass(move |_| Box::new(unnecessary_wraps::UnnecessaryWraps::new(avoid_breaking_exported_api)));
732 store.register_late_pass(|_| Box::new(assertions_on_constants::AssertionsOnConstants));
733 store.register_late_pass(|_| Box::new(assertions_on_result_states::AssertionsOnResultStates));
734 store.register_late_pass(|_| Box::new(inherent_to_string::InherentToString));
735 let max_trait_bounds = conf.max_trait_bounds;
736 store.register_late_pass(move |_| Box::new(trait_bounds::TraitBounds::new(max_trait_bounds)));
737 store.register_late_pass(|_| Box::new(comparison_chain::ComparisonChain));
738 store.register_late_pass(|_| Box::new(mut_key::MutableKeyType));
739 store.register_early_pass(|| Box::new(reference::DerefAddrOf));
740 store.register_early_pass(|| Box::new(double_parens::DoubleParens));
741 store.register_late_pass(|_| Box::new(format_impl::FormatImpl::new()));
742 store.register_early_pass(|| Box::new(unsafe_removed_from_name::UnsafeNameRemoval));
743 store.register_early_pass(|| Box::new(else_if_without_else::ElseIfWithoutElse));
744 store.register_early_pass(|| Box::new(int_plus_one::IntPlusOne));
745 store.register_early_pass(|| Box::new(formatting::Formatting));
746 store.register_early_pass(|| Box::new(misc_early::MiscEarlyLints));
747 store.register_early_pass(|| Box::new(redundant_closure_call::RedundantClosureCall));
748 store.register_late_pass(|_| Box::new(redundant_closure_call::RedundantClosureCall));
749 store.register_early_pass(|| Box::new(unused_unit::UnusedUnit));
750 store.register_late_pass(|_| Box::new(returns::Return));
751 store.register_early_pass(|| Box::new(collapsible_if::CollapsibleIf));
752 store.register_early_pass(|| Box::new(items_after_statements::ItemsAfterStatements));
753 store.register_early_pass(|| Box::new(precedence::Precedence));
754 store.register_late_pass(|_| Box::new(needless_parens_on_range_literals::NeedlessParensOnRangeLiterals));
755 store.register_early_pass(|| Box::new(needless_continue::NeedlessContinue));
756 store.register_early_pass(|| Box::new(redundant_else::RedundantElse));
757 store.register_late_pass(|_| Box::new(create_dir::CreateDir));
758 store.register_early_pass(|| Box::new(needless_arbitrary_self_type::NeedlessArbitrarySelfType));
759 let literal_representation_lint_fraction_readability = conf.unreadable_literal_lint_fractions;
760 store.register_early_pass(move || {
761 Box::new(literal_representation::LiteralDigitGrouping::new(
762 literal_representation_lint_fraction_readability,
765 let literal_representation_threshold = conf.literal_representation_threshold;
766 store.register_early_pass(move || {
767 Box::new(literal_representation::DecimalLiteralRepresentation::new(
768 literal_representation_threshold,
771 let enum_variant_name_threshold = conf.enum_variant_name_threshold;
772 store.register_late_pass(move |_| {
773 Box::new(enum_variants::EnumVariantNames::new(
774 enum_variant_name_threshold,
775 avoid_breaking_exported_api,
778 store.register_early_pass(|| Box::new(tabs_in_doc_comments::TabsInDocComments));
779 let upper_case_acronyms_aggressive = conf.upper_case_acronyms_aggressive;
780 store.register_late_pass(move |_| {
781 Box::new(upper_case_acronyms::UpperCaseAcronyms::new(
782 avoid_breaking_exported_api,
783 upper_case_acronyms_aggressive,
786 store.register_late_pass(|_| Box::<default::Default>::default());
787 store.register_late_pass(move |_| Box::new(unused_self::UnusedSelf::new(avoid_breaking_exported_api)));
788 store.register_late_pass(|_| Box::new(mutable_debug_assertion::DebugAssertWithMutCall));
789 store.register_late_pass(|_| Box::new(exit::Exit));
790 store.register_late_pass(|_| Box::new(to_digit_is_some::ToDigitIsSome));
791 let array_size_threshold = conf.array_size_threshold;
792 store.register_late_pass(move |_| Box::new(large_stack_arrays::LargeStackArrays::new(array_size_threshold)));
793 store.register_late_pass(move |_| Box::new(large_const_arrays::LargeConstArrays::new(array_size_threshold)));
794 store.register_late_pass(|_| Box::new(floating_point_arithmetic::FloatingPointArithmetic));
795 store.register_early_pass(|| Box::new(as_conversions::AsConversions));
796 store.register_late_pass(|_| Box::new(let_underscore::LetUnderscore));
797 store.register_early_pass(|| Box::new(single_component_path_imports::SingleComponentPathImports));
798 let max_fn_params_bools = conf.max_fn_params_bools;
799 let max_struct_bools = conf.max_struct_bools;
800 store.register_early_pass(move || {
801 Box::new(excessive_bools::ExcessiveBools::new(
806 store.register_early_pass(|| Box::new(option_env_unwrap::OptionEnvUnwrap));
807 let warn_on_all_wildcard_imports = conf.warn_on_all_wildcard_imports;
808 store.register_late_pass(move |_| Box::new(wildcard_imports::WildcardImports::new(warn_on_all_wildcard_imports)));
809 store.register_late_pass(|_| Box::<redundant_pub_crate::RedundantPubCrate>::default());
810 store.register_late_pass(|_| Box::new(unnamed_address::UnnamedAddress));
811 store.register_late_pass(move |_| Box::new(dereference::Dereferencing::new(msrv)));
812 store.register_late_pass(|_| Box::new(option_if_let_else::OptionIfLetElse));
813 store.register_late_pass(|_| Box::new(future_not_send::FutureNotSend));
814 store.register_late_pass(|_| Box::new(if_let_mutex::IfLetMutex));
815 store.register_late_pass(|_| Box::new(if_not_else::IfNotElse));
816 store.register_late_pass(|_| Box::new(equatable_if_let::PatternEquality));
817 store.register_late_pass(|_| Box::new(manual_async_fn::ManualAsyncFn));
818 store.register_late_pass(|_| Box::new(panic_in_result_fn::PanicInResultFn));
819 let single_char_binding_names_threshold = conf.single_char_binding_names_threshold;
820 store.register_early_pass(move || {
821 Box::new(non_expressive_names::NonExpressiveNames {
822 single_char_binding_names_threshold,
825 let macro_matcher = conf.standard_macro_braces.iter().cloned().collect::<FxHashSet<_>>();
826 store.register_early_pass(move || Box::new(nonstandard_macro_braces::MacroBraces::new(¯o_matcher)));
827 store.register_late_pass(|_| Box::<macro_use::MacroUseImports>::default());
828 store.register_late_pass(|_| Box::new(pattern_type_mismatch::PatternTypeMismatch));
829 store.register_late_pass(|_| Box::new(unwrap_in_result::UnwrapInResult));
830 store.register_late_pass(|_| Box::new(semicolon_if_nothing_returned::SemicolonIfNothingReturned));
831 store.register_late_pass(|_| Box::new(async_yields_async::AsyncYieldsAsync));
832 let disallowed_macros = conf.disallowed_macros.clone();
833 store.register_late_pass(move |_| Box::new(disallowed_macros::DisallowedMacros::new(disallowed_macros.clone())));
834 let disallowed_methods = conf.disallowed_methods.clone();
835 store.register_late_pass(move |_| Box::new(disallowed_methods::DisallowedMethods::new(disallowed_methods.clone())));
836 store.register_early_pass(|| Box::new(asm_syntax::InlineAsmX86AttSyntax));
837 store.register_early_pass(|| Box::new(asm_syntax::InlineAsmX86IntelSyntax));
838 store.register_late_pass(|_| Box::new(empty_drop::EmptyDrop));
839 store.register_late_pass(|_| Box::new(strings::StrToString));
840 store.register_late_pass(|_| Box::new(strings::StringToString));
841 store.register_late_pass(|_| Box::new(zero_sized_map_values::ZeroSizedMapValues));
842 store.register_late_pass(|_| Box::<vec_init_then_push::VecInitThenPush>::default());
843 store.register_late_pass(|_| Box::new(redundant_slicing::RedundantSlicing));
844 store.register_late_pass(|_| Box::new(from_str_radix_10::FromStrRadix10));
845 store.register_late_pass(move |_| Box::new(if_then_some_else_none::IfThenSomeElseNone::new(msrv)));
846 store.register_late_pass(|_| Box::new(bool_assert_comparison::BoolAssertComparison));
847 store.register_early_pass(move || Box::new(module_style::ModStyle));
848 store.register_late_pass(|_| Box::new(unused_async::UnusedAsync));
849 let disallowed_types = conf.disallowed_types.clone();
850 store.register_late_pass(move |_| Box::new(disallowed_types::DisallowedTypes::new(disallowed_types.clone())));
851 let import_renames = conf.enforced_import_renames.clone();
852 store.register_late_pass(move |_| {
853 Box::new(missing_enforced_import_rename::ImportRename::new(
854 import_renames.clone(),
857 let scripts = conf.allowed_scripts.clone();
858 store.register_early_pass(move || Box::new(disallowed_script_idents::DisallowedScriptIdents::new(&scripts)));
859 store.register_late_pass(|_| Box::new(strlen_on_c_strings::StrlenOnCStrings));
860 store.register_late_pass(move |_| Box::new(self_named_constructors::SelfNamedConstructors));
861 store.register_late_pass(move |_| Box::new(iter_not_returning_iterator::IterNotReturningIterator));
862 store.register_late_pass(move |_| Box::new(manual_assert::ManualAssert));
863 let enable_raw_pointer_heuristic_for_send = conf.enable_raw_pointer_heuristic_for_send;
864 store.register_late_pass(move |_| {
865 Box::new(non_send_fields_in_send_ty::NonSendFieldInSendTy::new(
866 enable_raw_pointer_heuristic_for_send,
869 store.register_late_pass(move |_| Box::new(undocumented_unsafe_blocks::UndocumentedUnsafeBlocks));
870 store.register_late_pass(move |_| Box::new(format_args::FormatArgs::new(msrv)));
871 store.register_late_pass(|_| Box::new(trailing_empty_array::TrailingEmptyArray));
872 store.register_early_pass(|| Box::new(octal_escapes::OctalEscapes));
873 store.register_late_pass(|_| Box::new(needless_late_init::NeedlessLateInit));
874 store.register_late_pass(|_| Box::new(return_self_not_must_use::ReturnSelfNotMustUse));
875 store.register_late_pass(|_| Box::new(init_numbered_fields::NumberedFields));
876 store.register_early_pass(|| Box::new(single_char_lifetime_names::SingleCharLifetimeNames));
877 store.register_late_pass(move |_| Box::new(manual_bits::ManualBits::new(msrv)));
878 store.register_late_pass(|_| Box::new(default_union_representation::DefaultUnionRepresentation));
879 store.register_late_pass(|_| Box::<only_used_in_recursion::OnlyUsedInRecursion>::default());
880 let allow_dbg_in_tests = conf.allow_dbg_in_tests;
881 store.register_late_pass(move |_| Box::new(dbg_macro::DbgMacro::new(allow_dbg_in_tests)));
882 let cargo_ignore_publish = conf.cargo_ignore_publish;
883 store.register_late_pass(move |_| {
884 Box::new(cargo::Cargo {
885 ignore_publish: cargo_ignore_publish,
888 store.register_late_pass(|_| Box::<write::Write>::default());
889 store.register_early_pass(|| Box::new(crate_in_macro_def::CrateInMacroDef));
890 store.register_early_pass(|| Box::new(empty_structs_with_brackets::EmptyStructsWithBrackets));
891 store.register_late_pass(|_| Box::new(unnecessary_owned_empty_strings::UnnecessaryOwnedEmptyStrings));
892 store.register_early_pass(|| Box::new(pub_use::PubUse));
893 store.register_late_pass(|_| Box::new(format_push_string::FormatPushString));
894 let max_include_file_size = conf.max_include_file_size;
895 store.register_late_pass(move |_| Box::new(large_include_file::LargeIncludeFile::new(max_include_file_size)));
896 store.register_late_pass(|_| Box::new(strings::TrimSplitWhitespace));
897 store.register_late_pass(|_| Box::new(rc_clone_in_vec_init::RcCloneInVecInit));
898 store.register_early_pass(|| Box::<duplicate_mod::DuplicateMod>::default());
899 store.register_early_pass(|| Box::new(unused_rounding::UnusedRounding));
900 store.register_early_pass(move || Box::new(almost_complete_letter_range::AlmostCompleteLetterRange::new(msrv)));
901 store.register_late_pass(|_| Box::new(swap_ptr_to_ref::SwapPtrToRef));
902 store.register_late_pass(|_| Box::new(mismatching_type_param_order::TypeParamMismatch));
903 store.register_late_pass(|_| Box::new(read_zero_byte_vec::ReadZeroByteVec));
904 store.register_late_pass(|_| Box::new(default_instead_of_iter_empty::DefaultIterEmpty));
905 store.register_late_pass(move |_| Box::new(manual_rem_euclid::ManualRemEuclid::new(msrv)));
906 store.register_late_pass(move |_| Box::new(manual_retain::ManualRetain::new(msrv)));
907 let verbose_bit_mask_threshold = conf.verbose_bit_mask_threshold;
908 store.register_late_pass(move |_| Box::new(operators::Operators::new(verbose_bit_mask_threshold)));
909 store.register_late_pass(|_| Box::new(invalid_utf8_in_unchecked::InvalidUtf8InUnchecked));
910 store.register_late_pass(|_| Box::<std_instead_of_core::StdReexports>::default());
911 store.register_late_pass(|_| Box::new(manual_instant_elapsed::ManualInstantElapsed));
912 store.register_late_pass(|_| Box::new(partialeq_to_none::PartialeqToNone));
913 store.register_late_pass(move |_| Box::new(manual_clamp::ManualClamp::new(msrv)));
914 store.register_late_pass(|_| Box::new(manual_string_new::ManualStringNew));
915 store.register_late_pass(|_| Box::new(unused_peekable::UnusedPeekable));
916 store.register_early_pass(|| Box::new(multi_assignments::MultiAssignments));
917 store.register_late_pass(|_| Box::new(bool_to_int_with_if::BoolToIntWithIf));
918 store.register_late_pass(|_| Box::new(box_default::BoxDefault));
919 store.register_late_pass(|_| Box::new(implicit_saturating_add::ImplicitSaturatingAdd));
920 store.register_early_pass(|| Box::new(partial_pub_fields::PartialPubFields));
921 store.register_late_pass(|_| Box::new(missing_trait_methods::MissingTraitMethods));
922 // add lints here, do not remove this comment, it's used in `new_lint`
926 fn register_removed_non_tool_lints(store: &mut rustc_lint::LintStore) {
927 store.register_removed(
929 "`assert!()` will be more flexible with RFC 2011",
931 store.register_removed(
933 "`.extend_from_slice(_)` is a faster way to extend a Vec by a slice",
935 store.register_removed(
936 "range_step_by_zero",
937 "`iterator.step_by(0)` panics nowadays",
939 store.register_removed(
941 "`Vec::as_slice` has been stabilized in 1.7",
943 store.register_removed(
944 "unstable_as_mut_slice",
945 "`Vec::as_mut_slice` has been stabilized in 1.7",
947 store.register_removed(
948 "misaligned_transmute",
949 "this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr",
951 store.register_removed(
953 "using compound assignment operators (e.g., `+=`) is harmless",
955 store.register_removed(
956 "if_let_redundant_pattern_matching",
957 "this lint has been changed to redundant_pattern_matching",
959 store.register_removed(
960 "unsafe_vector_initialization",
961 "the replacement suggested by this lint had substantially different behavior",
963 store.register_removed(
964 "reverse_range_loop",
965 "this lint is now included in reversed_empty_ranges",
969 /// Register renamed lints.
971 /// Used in `./src/driver.rs`.
972 pub fn register_renamed(ls: &mut rustc_lint::LintStore) {
973 for (old_name, new_name) in renamed_lints::RENAMED_LINTS {
974 ls.register_renamed(old_name, new_name);
978 // only exists to let the dogfood integration test works.
979 // Don't run clippy as an executable directly
982 panic!("Please use the cargo-clippy executable");