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 #![cfg_attr(bootstrap, 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;
176 mod assertions_on_constants;
177 mod assertions_on_result_states;
178 mod async_yields_async;
180 mod await_holding_invalid;
181 mod blocks_in_if_conditions;
182 mod bool_assert_comparison;
185 mod borrow_deref_ref;
187 mod bytes_count_to_len;
189 mod case_sensitive_file_extension_comparisons;
191 mod checked_conversions;
192 mod cognitive_complexity;
194 mod comparison_chain;
197 mod crate_in_macro_def;
201 mod default_instead_of_iter_empty;
202 mod default_numeric_fallback;
203 mod default_union_representation;
207 mod disallowed_methods;
208 mod disallowed_names;
209 mod disallowed_script_idents;
210 mod disallowed_types;
212 mod doc_link_with_quotes;
216 mod else_if_without_else;
219 mod empty_structs_with_brackets;
223 mod equatable_if_let;
227 mod exhaustive_items;
230 mod fallible_impl_from;
232 mod floating_point_arithmetic;
236 mod format_push_string;
239 mod from_str_radix_10;
245 mod if_then_some_else_none;
248 mod implicit_saturating_sub;
249 mod inconsistent_struct_constructor;
250 mod index_refutable_slice;
251 mod indexing_slicing;
254 mod inherent_to_string;
255 mod init_numbered_fields;
256 mod inline_fn_without_body;
258 mod invalid_upcast_comparisons;
259 mod invalid_utf8_in_unchecked;
260 mod items_after_statements;
261 mod iter_not_returning_iterator;
262 mod large_const_arrays;
263 mod large_enum_variant;
264 mod large_include_file;
265 mod large_stack_arrays;
270 mod literal_representation;
277 mod manual_instant_elapsed;
278 mod manual_non_exhaustive;
280 mod manual_rem_euclid;
294 mod mismatching_type_param_order;
295 mod missing_const_for_fn;
297 mod missing_enforced_import_rename;
299 mod mixed_read_write_in_expression;
305 mod mutable_debug_assertion;
307 mod needless_arbitrary_self_type;
309 mod needless_borrowed_ref;
310 mod needless_continue;
311 mod needless_for_each;
312 mod needless_late_init;
313 mod needless_parens_on_range_literals;
314 mod needless_pass_by_value;
315 mod needless_question_mark;
317 mod neg_cmp_op_on_partial_ord;
319 mod new_without_default;
322 mod non_expressive_names;
323 mod non_octal_unix_permissions;
324 mod non_send_fields_in_send_ty;
325 mod nonstandard_macro_braces;
327 mod only_used_in_recursion;
330 mod option_env_unwrap;
331 mod option_if_let_else;
332 mod overflow_check_conditional;
333 mod panic_in_result_fn;
334 mod panic_unimplemented;
335 mod partialeq_ne_impl;
336 mod partialeq_to_none;
337 mod pass_by_ref_or_value;
338 mod path_buf_push_overwrite;
339 mod pattern_type_mismatch;
342 mod ptr_offset_with_cast;
346 mod rc_clone_in_vec_init;
347 mod read_zero_byte_vec;
349 mod redundant_closure_call;
351 mod redundant_field_names;
352 mod redundant_pub_crate;
353 mod redundant_slicing;
354 mod redundant_static_lifetimes;
359 mod return_self_not_must_use;
361 mod same_name_method;
362 mod self_named_constructors;
363 mod semicolon_if_nothing_returned;
366 mod single_char_lifetime_names;
367 mod single_component_path_imports;
368 mod size_of_in_element_count;
369 mod slow_vector_initialization;
370 mod stable_sort_primitive;
371 mod std_instead_of_core;
373 mod strlen_on_c_strings;
374 mod suspicious_operation_groupings;
375 mod suspicious_trait_impl;
378 mod tabs_in_doc_comments;
379 mod temporary_assignment;
380 mod to_digit_is_some;
381 mod trailing_empty_array;
384 mod transmuting_null;
386 mod undocumented_unsafe_blocks;
390 mod unit_return_expecting_ord;
393 mod unnecessary_owned_empty_strings;
394 mod unnecessary_self_imports;
395 mod unnecessary_sort_by;
396 mod unnecessary_wraps;
397 mod unnested_or_patterns;
398 mod unsafe_removed_from_name;
400 mod unused_io_amount;
405 mod unwrap_in_result;
406 mod upper_case_acronyms;
408 mod useless_conversion;
410 mod vec_init_then_push;
411 mod vec_resize_to_zero;
412 mod verbose_file_reads;
413 mod wildcard_imports;
416 mod zero_sized_map_values;
417 // end lints modules, do not remove this comment, it’s used in `update_lints`
419 pub use crate::utils::conf::Conf;
420 use crate::utils::conf::{format_error, TryConf};
422 /// Register all pre expansion lints
424 /// Pre-expansion lints run before any macro expansion has happened.
426 /// Note that due to the architecture of the compiler, currently `cfg_attr` attributes on crate
427 /// level (i.e `#![cfg_attr(...)]`) will still be expanded even when using a pre-expansion pass.
429 /// Used in `./src/driver.rs`.
430 pub fn register_pre_expansion_lints(store: &mut rustc_lint::LintStore, sess: &Session, conf: &Conf) {
431 // NOTE: Do not add any more pre-expansion passes. These should be removed eventually.
433 let msrv = conf.msrv.as_ref().and_then(|s| {
434 parse_msrv(s, None, None).or_else(|| {
436 "error reading Clippy's configuration file. `{}` is not a valid Rust version",
443 store.register_pre_expansion_pass(|| Box::new(write::Write::default()));
444 store.register_pre_expansion_pass(move || Box::new(attrs::EarlyAttributes { msrv }));
447 fn read_msrv(conf: &Conf, sess: &Session) -> Option<RustcVersion> {
448 let cargo_msrv = std::env::var("CARGO_PKG_RUST_VERSION")
450 .and_then(|v| parse_msrv(&v, None, None));
451 let clippy_msrv = conf.msrv.as_ref().and_then(|s| {
452 parse_msrv(s, None, None).or_else(|| {
454 "error reading Clippy's configuration file. `{}` is not a valid Rust version",
461 if let Some(cargo_msrv) = cargo_msrv {
462 if let Some(clippy_msrv) = clippy_msrv {
463 // if both files have an msrv, let's compare them and emit a warning if they differ
464 if clippy_msrv != cargo_msrv {
466 "the MSRV in `clippy.toml` and `Cargo.toml` differ; using `{}` from `clippy.toml`",
481 pub fn read_conf(sess: &Session) -> Conf {
482 let file_name = match utils::conf::lookup_conf_file() {
483 Ok(Some(path)) => path,
484 Ok(None) => return Conf::default(),
486 sess.struct_err(&format!("error finding Clippy's configuration file: {}", error))
488 return Conf::default();
492 let TryConf { conf, errors, warnings } = utils::conf::read(&file_name);
493 // all conf errors are non-fatal, we just use the default conf in case of error
494 for error in errors {
496 "error reading Clippy's configuration file `{}`: {}",
502 for warning in warnings {
503 sess.struct_warn(&format!(
504 "error reading Clippy's configuration file `{}`: {}",
506 format_error(warning)
514 /// Register all lints and lint groups with the rustc plugin registry
516 /// Used in `./src/driver.rs`.
517 #[expect(clippy::too_many_lines)]
518 pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: &Conf) {
519 register_removed_non_tool_lints(store);
521 include!("lib.deprecated.rs");
523 include!("lib.register_lints.rs");
524 include!("lib.register_restriction.rs");
525 include!("lib.register_pedantic.rs");
527 #[cfg(feature = "internal")]
528 include!("lib.register_internal.rs");
530 include!("lib.register_all.rs");
531 include!("lib.register_style.rs");
532 include!("lib.register_complexity.rs");
533 include!("lib.register_correctness.rs");
534 include!("lib.register_suspicious.rs");
535 include!("lib.register_perf.rs");
536 include!("lib.register_cargo.rs");
537 include!("lib.register_nursery.rs");
539 #[cfg(feature = "internal")]
541 if std::env::var("ENABLE_METADATA_COLLECTION").eq(&Ok("1".to_string())) {
542 store.register_late_pass(|| Box::new(utils::internal_lints::metadata_collector::MetadataCollector::new()));
547 // all the internal lints
548 #[cfg(feature = "internal")]
550 store.register_early_pass(|| Box::new(utils::internal_lints::ClippyLintsInternal));
551 store.register_early_pass(|| Box::new(utils::internal_lints::ProduceIce));
552 store.register_late_pass(|| Box::new(utils::internal_lints::CollapsibleCalls));
553 store.register_late_pass(|| Box::new(utils::internal_lints::CompilerLintFunctions::new()));
554 store.register_late_pass(|| Box::new(utils::internal_lints::IfChainStyle));
555 store.register_late_pass(|| Box::new(utils::internal_lints::InvalidPaths));
556 store.register_late_pass(|| Box::new(utils::internal_lints::InterningDefinedSymbol::default()));
557 store.register_late_pass(|| Box::new(utils::internal_lints::LintWithoutLintPass::default()));
558 store.register_late_pass(|| Box::new(utils::internal_lints::MatchTypeOnDiagItem));
559 store.register_late_pass(|| Box::new(utils::internal_lints::OuterExpnDataPass));
560 store.register_late_pass(|| Box::new(utils::internal_lints::MsrvAttrImpl));
563 let arithmetic_allowed = conf.arithmetic_allowed.clone();
564 store.register_late_pass(move || Box::new(operators::arithmetic::Arithmetic::new(arithmetic_allowed.clone())));
565 store.register_late_pass(|| Box::new(utils::dump_hir::DumpHir));
566 store.register_late_pass(|| Box::new(utils::author::Author));
567 let await_holding_invalid_types = conf.await_holding_invalid_types.clone();
568 store.register_late_pass(move || {
569 Box::new(await_holding_invalid::AwaitHolding::new(
570 await_holding_invalid_types.clone(),
573 store.register_late_pass(|| Box::new(serde_api::SerdeApi));
574 let vec_box_size_threshold = conf.vec_box_size_threshold;
575 let type_complexity_threshold = conf.type_complexity_threshold;
576 let avoid_breaking_exported_api = conf.avoid_breaking_exported_api;
577 store.register_late_pass(move || {
578 Box::new(types::Types::new(
579 vec_box_size_threshold,
580 type_complexity_threshold,
581 avoid_breaking_exported_api,
584 store.register_late_pass(|| Box::new(booleans::NonminimalBool));
585 store.register_late_pass(|| Box::new(enum_clike::UnportableVariant));
586 store.register_late_pass(|| Box::new(float_literal::FloatLiteral));
587 store.register_late_pass(|| Box::new(ptr::Ptr));
588 store.register_late_pass(|| Box::new(needless_bool::NeedlessBool));
589 store.register_late_pass(|| Box::new(needless_bool::BoolComparison));
590 store.register_late_pass(|| Box::new(needless_for_each::NeedlessForEach));
591 store.register_late_pass(|| Box::new(misc::MiscLints));
592 store.register_late_pass(|| Box::new(eta_reduction::EtaReduction));
593 store.register_late_pass(|| Box::new(mut_mut::MutMut));
594 store.register_late_pass(|| Box::new(mut_reference::UnnecessaryMutPassed));
595 store.register_late_pass(|| Box::new(len_zero::LenZero));
596 store.register_late_pass(|| Box::new(attrs::Attributes));
597 store.register_late_pass(|| Box::new(blocks_in_if_conditions::BlocksInIfConditions));
598 store.register_late_pass(|| Box::new(unicode::Unicode));
599 store.register_late_pass(|| Box::new(uninit_vec::UninitVec));
600 store.register_late_pass(|| Box::new(unit_hash::UnitHash));
601 store.register_late_pass(|| Box::new(unit_return_expecting_ord::UnitReturnExpectingOrd));
602 store.register_late_pass(|| Box::new(strings::StringAdd));
603 store.register_late_pass(|| Box::new(implicit_return::ImplicitReturn));
604 store.register_late_pass(|| Box::new(implicit_saturating_sub::ImplicitSaturatingSub));
605 store.register_late_pass(|| Box::new(default_numeric_fallback::DefaultNumericFallback));
606 store.register_late_pass(|| Box::new(inconsistent_struct_constructor::InconsistentStructConstructor));
607 store.register_late_pass(|| Box::new(non_octal_unix_permissions::NonOctalUnixPermissions));
608 store.register_early_pass(|| Box::new(unnecessary_self_imports::UnnecessarySelfImports));
610 let msrv = read_msrv(conf, sess);
611 let avoid_breaking_exported_api = conf.avoid_breaking_exported_api;
612 let allow_expect_in_tests = conf.allow_expect_in_tests;
613 let allow_unwrap_in_tests = conf.allow_unwrap_in_tests;
614 store.register_late_pass(move || Box::new(approx_const::ApproxConstant::new(msrv)));
615 store.register_late_pass(move || {
616 Box::new(methods::Methods::new(
617 avoid_breaking_exported_api,
619 allow_expect_in_tests,
620 allow_unwrap_in_tests,
623 store.register_late_pass(move || Box::new(matches::Matches::new(msrv)));
624 store.register_early_pass(move || Box::new(manual_non_exhaustive::ManualNonExhaustiveStruct::new(msrv)));
625 store.register_late_pass(move || Box::new(manual_non_exhaustive::ManualNonExhaustiveEnum::new(msrv)));
626 store.register_late_pass(move || Box::new(manual_strip::ManualStrip::new(msrv)));
627 store.register_early_pass(move || Box::new(redundant_static_lifetimes::RedundantStaticLifetimes::new(msrv)));
628 store.register_early_pass(move || Box::new(redundant_field_names::RedundantFieldNames::new(msrv)));
629 store.register_late_pass(move || Box::new(checked_conversions::CheckedConversions::new(msrv)));
630 store.register_late_pass(move || Box::new(mem_replace::MemReplace::new(msrv)));
631 store.register_late_pass(move || Box::new(ranges::Ranges::new(msrv)));
632 store.register_late_pass(move || Box::new(from_over_into::FromOverInto::new(msrv)));
633 store.register_late_pass(move || Box::new(use_self::UseSelf::new(msrv)));
634 store.register_late_pass(move || Box::new(missing_const_for_fn::MissingConstForFn::new(msrv)));
635 store.register_late_pass(move || Box::new(needless_question_mark::NeedlessQuestionMark));
636 store.register_late_pass(move || Box::new(casts::Casts::new(msrv)));
637 store.register_early_pass(move || Box::new(unnested_or_patterns::UnnestedOrPatterns::new(msrv)));
638 store.register_late_pass(move || Box::new(map_clone::MapClone::new(msrv)));
640 store.register_late_pass(|| Box::new(size_of_in_element_count::SizeOfInElementCount));
641 store.register_late_pass(|| Box::new(same_name_method::SameNameMethod));
642 let max_suggested_slice_pattern_length = conf.max_suggested_slice_pattern_length;
643 store.register_late_pass(move || {
644 Box::new(index_refutable_slice::IndexRefutableSlice::new(
645 max_suggested_slice_pattern_length,
649 store.register_late_pass(|| Box::new(map_err_ignore::MapErrIgnore));
650 store.register_late_pass(|| Box::new(shadow::Shadow::default()));
651 store.register_late_pass(|| Box::new(unit_types::UnitTypes));
652 store.register_late_pass(|| Box::new(loops::Loops));
653 store.register_late_pass(|| Box::new(main_recursion::MainRecursion::default()));
654 store.register_late_pass(|| Box::new(lifetimes::Lifetimes));
655 store.register_late_pass(|| Box::new(entry::HashMapPass));
656 store.register_late_pass(|| Box::new(minmax::MinMaxPass));
657 store.register_late_pass(|| Box::new(open_options::OpenOptions));
658 store.register_late_pass(|| Box::new(zero_div_zero::ZeroDiv));
659 store.register_late_pass(|| Box::new(mutex_atomic::Mutex));
660 store.register_late_pass(|| Box::new(needless_update::NeedlessUpdate));
661 store.register_late_pass(|| Box::new(needless_borrowed_ref::NeedlessBorrowedRef));
662 store.register_late_pass(|| Box::new(borrow_deref_ref::BorrowDerefRef));
663 store.register_late_pass(|| Box::new(no_effect::NoEffect));
664 store.register_late_pass(|| Box::new(temporary_assignment::TemporaryAssignment));
665 store.register_late_pass(move || Box::new(transmute::Transmute::new(msrv)));
666 let cognitive_complexity_threshold = conf.cognitive_complexity_threshold;
667 store.register_late_pass(move || {
668 Box::new(cognitive_complexity::CognitiveComplexity::new(
669 cognitive_complexity_threshold,
672 let too_large_for_stack = conf.too_large_for_stack;
673 store.register_late_pass(move || Box::new(escape::BoxedLocal { too_large_for_stack }));
674 store.register_late_pass(move || Box::new(vec::UselessVec { too_large_for_stack }));
675 store.register_late_pass(|| Box::new(panic_unimplemented::PanicUnimplemented));
676 store.register_late_pass(|| Box::new(strings::StringLitAsBytes));
677 store.register_late_pass(|| Box::new(derive::Derive));
678 store.register_late_pass(|| Box::new(derivable_impls::DerivableImpls));
679 store.register_late_pass(|| Box::new(drop_forget_ref::DropForgetRef));
680 store.register_late_pass(|| Box::new(empty_enum::EmptyEnum));
681 store.register_late_pass(|| Box::new(invalid_upcast_comparisons::InvalidUpcastComparisons));
682 store.register_late_pass(|| Box::new(regex::Regex));
683 store.register_late_pass(|| Box::new(copies::CopyAndPaste));
684 store.register_late_pass(|| Box::new(copy_iterator::CopyIterator));
685 store.register_late_pass(|| Box::new(format::UselessFormat));
686 store.register_late_pass(|| Box::new(swap::Swap));
687 store.register_late_pass(|| Box::new(overflow_check_conditional::OverflowCheckConditional));
688 store.register_late_pass(|| Box::new(new_without_default::NewWithoutDefault::default()));
689 let disallowed_names = conf.disallowed_names.iter().cloned().collect::<FxHashSet<_>>();
690 store.register_late_pass(move || Box::new(disallowed_names::DisallowedNames::new(disallowed_names.clone())));
691 let too_many_arguments_threshold = conf.too_many_arguments_threshold;
692 let too_many_lines_threshold = conf.too_many_lines_threshold;
693 store.register_late_pass(move || {
694 Box::new(functions::Functions::new(
695 too_many_arguments_threshold,
696 too_many_lines_threshold,
699 let doc_valid_idents = conf.doc_valid_idents.iter().cloned().collect::<FxHashSet<_>>();
700 store.register_late_pass(move || Box::new(doc::DocMarkdown::new(doc_valid_idents.clone())));
701 store.register_late_pass(|| Box::new(neg_multiply::NegMultiply));
702 store.register_late_pass(|| Box::new(mem_forget::MemForget));
703 store.register_late_pass(|| Box::new(let_if_seq::LetIfSeq));
704 store.register_late_pass(|| Box::new(mixed_read_write_in_expression::EvalOrderDependence));
705 store.register_late_pass(|| Box::new(missing_doc::MissingDoc::new()));
706 store.register_late_pass(|| Box::new(missing_inline::MissingInline));
707 store.register_late_pass(move || Box::new(exhaustive_items::ExhaustiveItems));
708 store.register_late_pass(|| Box::new(match_result_ok::MatchResultOk));
709 store.register_late_pass(|| Box::new(partialeq_ne_impl::PartialEqNeImpl));
710 store.register_late_pass(|| Box::new(unused_io_amount::UnusedIoAmount));
711 let enum_variant_size_threshold = conf.enum_variant_size_threshold;
712 store.register_late_pass(move || Box::new(large_enum_variant::LargeEnumVariant::new(enum_variant_size_threshold)));
713 store.register_late_pass(|| Box::new(explicit_write::ExplicitWrite));
714 store.register_late_pass(|| Box::new(needless_pass_by_value::NeedlessPassByValue));
715 let pass_by_ref_or_value = pass_by_ref_or_value::PassByRefOrValue::new(
716 conf.trivial_copy_size_limit,
717 conf.pass_by_value_size_limit,
718 conf.avoid_breaking_exported_api,
721 store.register_late_pass(move || Box::new(pass_by_ref_or_value));
722 store.register_late_pass(|| Box::new(ref_option_ref::RefOptionRef));
723 store.register_late_pass(|| Box::new(bytecount::ByteCount));
724 store.register_late_pass(|| Box::new(infinite_iter::InfiniteIter));
725 store.register_late_pass(|| Box::new(inline_fn_without_body::InlineFnWithoutBody));
726 store.register_late_pass(|| Box::new(useless_conversion::UselessConversion::default()));
727 store.register_late_pass(|| Box::new(implicit_hasher::ImplicitHasher));
728 store.register_late_pass(|| Box::new(fallible_impl_from::FallibleImplFrom));
729 store.register_late_pass(|| Box::new(question_mark::QuestionMark));
730 store.register_early_pass(|| Box::new(suspicious_operation_groupings::SuspiciousOperationGroupings));
731 store.register_late_pass(|| Box::new(suspicious_trait_impl::SuspiciousImpl));
732 store.register_late_pass(|| Box::new(map_unit_fn::MapUnit));
733 store.register_late_pass(|| Box::new(inherent_impl::MultipleInherentImpl));
734 store.register_late_pass(|| Box::new(neg_cmp_op_on_partial_ord::NoNegCompOpForPartialOrd));
735 store.register_late_pass(|| Box::new(unwrap::Unwrap));
736 store.register_late_pass(|| Box::new(indexing_slicing::IndexingSlicing));
737 store.register_late_pass(|| Box::new(non_copy_const::NonCopyConst));
738 store.register_late_pass(|| Box::new(ptr_offset_with_cast::PtrOffsetWithCast));
739 store.register_late_pass(|| Box::new(redundant_clone::RedundantClone));
740 store.register_late_pass(|| Box::new(slow_vector_initialization::SlowVectorInit));
741 store.register_late_pass(|| Box::new(unnecessary_sort_by::UnnecessarySortBy));
742 store.register_late_pass(move || Box::new(unnecessary_wraps::UnnecessaryWraps::new(avoid_breaking_exported_api)));
743 store.register_late_pass(|| Box::new(assertions_on_constants::AssertionsOnConstants));
744 store.register_late_pass(|| Box::new(assertions_on_result_states::AssertionsOnResultStates));
745 store.register_late_pass(|| Box::new(transmuting_null::TransmutingNull));
746 store.register_late_pass(|| Box::new(path_buf_push_overwrite::PathBufPushOverwrite));
747 store.register_late_pass(|| Box::new(inherent_to_string::InherentToString));
748 let max_trait_bounds = conf.max_trait_bounds;
749 store.register_late_pass(move || Box::new(trait_bounds::TraitBounds::new(max_trait_bounds)));
750 store.register_late_pass(|| Box::new(comparison_chain::ComparisonChain));
751 store.register_late_pass(|| Box::new(mut_key::MutableKeyType));
752 store.register_early_pass(|| Box::new(reference::DerefAddrOf));
753 store.register_early_pass(|| Box::new(double_parens::DoubleParens));
754 store.register_late_pass(|| Box::new(format_impl::FormatImpl::new()));
755 store.register_early_pass(|| Box::new(unsafe_removed_from_name::UnsafeNameRemoval));
756 store.register_early_pass(|| Box::new(else_if_without_else::ElseIfWithoutElse));
757 store.register_early_pass(|| Box::new(int_plus_one::IntPlusOne));
758 store.register_early_pass(|| Box::new(formatting::Formatting));
759 store.register_early_pass(|| Box::new(misc_early::MiscEarlyLints));
760 store.register_early_pass(|| Box::new(redundant_closure_call::RedundantClosureCall));
761 store.register_late_pass(|| Box::new(redundant_closure_call::RedundantClosureCall));
762 store.register_early_pass(|| Box::new(unused_unit::UnusedUnit));
763 store.register_late_pass(|| Box::new(returns::Return));
764 store.register_early_pass(|| Box::new(collapsible_if::CollapsibleIf));
765 store.register_early_pass(|| Box::new(items_after_statements::ItemsAfterStatements));
766 store.register_early_pass(|| Box::new(precedence::Precedence));
767 store.register_late_pass(|| Box::new(needless_parens_on_range_literals::NeedlessParensOnRangeLiterals));
768 store.register_early_pass(|| Box::new(needless_continue::NeedlessContinue));
769 store.register_early_pass(|| Box::new(redundant_else::RedundantElse));
770 store.register_late_pass(|| Box::new(create_dir::CreateDir));
771 store.register_early_pass(|| Box::new(needless_arbitrary_self_type::NeedlessArbitrarySelfType));
772 let literal_representation_lint_fraction_readability = conf.unreadable_literal_lint_fractions;
773 store.register_early_pass(move || {
774 Box::new(literal_representation::LiteralDigitGrouping::new(
775 literal_representation_lint_fraction_readability,
778 let literal_representation_threshold = conf.literal_representation_threshold;
779 store.register_early_pass(move || {
780 Box::new(literal_representation::DecimalLiteralRepresentation::new(
781 literal_representation_threshold,
784 let enum_variant_name_threshold = conf.enum_variant_name_threshold;
785 store.register_late_pass(move || {
786 Box::new(enum_variants::EnumVariantNames::new(
787 enum_variant_name_threshold,
788 avoid_breaking_exported_api,
791 store.register_early_pass(|| Box::new(tabs_in_doc_comments::TabsInDocComments));
792 let upper_case_acronyms_aggressive = conf.upper_case_acronyms_aggressive;
793 store.register_late_pass(move || {
794 Box::new(upper_case_acronyms::UpperCaseAcronyms::new(
795 avoid_breaking_exported_api,
796 upper_case_acronyms_aggressive,
799 store.register_late_pass(|| Box::new(default::Default::default()));
800 store.register_late_pass(move || Box::new(unused_self::UnusedSelf::new(avoid_breaking_exported_api)));
801 store.register_late_pass(|| Box::new(mutable_debug_assertion::DebugAssertWithMutCall));
802 store.register_late_pass(|| Box::new(exit::Exit));
803 store.register_late_pass(|| Box::new(to_digit_is_some::ToDigitIsSome));
804 let array_size_threshold = conf.array_size_threshold;
805 store.register_late_pass(move || Box::new(large_stack_arrays::LargeStackArrays::new(array_size_threshold)));
806 store.register_late_pass(move || Box::new(large_const_arrays::LargeConstArrays::new(array_size_threshold)));
807 store.register_late_pass(|| Box::new(floating_point_arithmetic::FloatingPointArithmetic));
808 store.register_early_pass(|| Box::new(as_conversions::AsConversions));
809 store.register_late_pass(|| Box::new(let_underscore::LetUnderscore));
810 store.register_early_pass(|| Box::new(single_component_path_imports::SingleComponentPathImports));
811 let max_fn_params_bools = conf.max_fn_params_bools;
812 let max_struct_bools = conf.max_struct_bools;
813 store.register_early_pass(move || {
814 Box::new(excessive_bools::ExcessiveBools::new(
819 store.register_early_pass(|| Box::new(option_env_unwrap::OptionEnvUnwrap));
820 let warn_on_all_wildcard_imports = conf.warn_on_all_wildcard_imports;
821 store.register_late_pass(move || Box::new(wildcard_imports::WildcardImports::new(warn_on_all_wildcard_imports)));
822 store.register_late_pass(|| Box::new(verbose_file_reads::VerboseFileReads));
823 store.register_late_pass(|| Box::new(redundant_pub_crate::RedundantPubCrate::default()));
824 store.register_late_pass(|| Box::new(unnamed_address::UnnamedAddress));
825 store.register_late_pass(|| Box::new(dereference::Dereferencing::default()));
826 store.register_late_pass(|| Box::new(option_if_let_else::OptionIfLetElse));
827 store.register_late_pass(|| Box::new(future_not_send::FutureNotSend));
828 store.register_late_pass(|| Box::new(if_let_mutex::IfLetMutex));
829 store.register_late_pass(|| Box::new(if_not_else::IfNotElse));
830 store.register_late_pass(|| Box::new(equatable_if_let::PatternEquality));
831 store.register_late_pass(|| Box::new(mut_mutex_lock::MutMutexLock));
832 store.register_late_pass(|| Box::new(manual_async_fn::ManualAsyncFn));
833 store.register_late_pass(|| Box::new(vec_resize_to_zero::VecResizeToZero));
834 store.register_late_pass(|| Box::new(panic_in_result_fn::PanicInResultFn));
835 let single_char_binding_names_threshold = conf.single_char_binding_names_threshold;
836 store.register_early_pass(move || {
837 Box::new(non_expressive_names::NonExpressiveNames {
838 single_char_binding_names_threshold,
841 let macro_matcher = conf.standard_macro_braces.iter().cloned().collect::<FxHashSet<_>>();
842 store.register_early_pass(move || Box::new(nonstandard_macro_braces::MacroBraces::new(¯o_matcher)));
843 store.register_late_pass(|| Box::new(macro_use::MacroUseImports::default()));
844 store.register_late_pass(|| Box::new(pattern_type_mismatch::PatternTypeMismatch));
845 store.register_late_pass(|| Box::new(stable_sort_primitive::StableSortPrimitive));
846 store.register_late_pass(|| Box::new(repeat_once::RepeatOnce));
847 store.register_late_pass(|| Box::new(unwrap_in_result::UnwrapInResult));
848 store.register_late_pass(|| Box::new(manual_ok_or::ManualOkOr));
849 store.register_late_pass(|| Box::new(semicolon_if_nothing_returned::SemicolonIfNothingReturned));
850 store.register_late_pass(|| Box::new(async_yields_async::AsyncYieldsAsync));
851 let disallowed_methods = conf.disallowed_methods.clone();
852 store.register_late_pass(move || Box::new(disallowed_methods::DisallowedMethods::new(disallowed_methods.clone())));
853 store.register_early_pass(|| Box::new(asm_syntax::InlineAsmX86AttSyntax));
854 store.register_early_pass(|| Box::new(asm_syntax::InlineAsmX86IntelSyntax));
855 store.register_late_pass(|| Box::new(empty_drop::EmptyDrop));
856 store.register_late_pass(|| Box::new(strings::StrToString));
857 store.register_late_pass(|| Box::new(strings::StringToString));
858 store.register_late_pass(|| Box::new(zero_sized_map_values::ZeroSizedMapValues));
859 store.register_late_pass(|| Box::new(vec_init_then_push::VecInitThenPush::default()));
860 store.register_late_pass(|| {
861 Box::new(case_sensitive_file_extension_comparisons::CaseSensitiveFileExtensionComparisons)
863 store.register_late_pass(|| Box::new(redundant_slicing::RedundantSlicing));
864 store.register_late_pass(|| Box::new(from_str_radix_10::FromStrRadix10));
865 store.register_late_pass(move || Box::new(if_then_some_else_none::IfThenSomeElseNone::new(msrv)));
866 store.register_late_pass(|| Box::new(bool_assert_comparison::BoolAssertComparison));
867 store.register_early_pass(move || Box::new(module_style::ModStyle));
868 store.register_late_pass(|| Box::new(unused_async::UnusedAsync));
869 let disallowed_types = conf.disallowed_types.clone();
870 store.register_late_pass(move || Box::new(disallowed_types::DisallowedTypes::new(disallowed_types.clone())));
871 let import_renames = conf.enforced_import_renames.clone();
872 store.register_late_pass(move || {
873 Box::new(missing_enforced_import_rename::ImportRename::new(
874 import_renames.clone(),
877 let scripts = conf.allowed_scripts.clone();
878 store.register_early_pass(move || Box::new(disallowed_script_idents::DisallowedScriptIdents::new(&scripts)));
879 store.register_late_pass(|| Box::new(strlen_on_c_strings::StrlenOnCStrings));
880 store.register_late_pass(move || Box::new(self_named_constructors::SelfNamedConstructors));
881 store.register_late_pass(move || Box::new(iter_not_returning_iterator::IterNotReturningIterator));
882 store.register_late_pass(move || Box::new(manual_assert::ManualAssert));
883 let enable_raw_pointer_heuristic_for_send = conf.enable_raw_pointer_heuristic_for_send;
884 store.register_late_pass(move || {
885 Box::new(non_send_fields_in_send_ty::NonSendFieldInSendTy::new(
886 enable_raw_pointer_heuristic_for_send,
889 store.register_late_pass(move || Box::new(undocumented_unsafe_blocks::UndocumentedUnsafeBlocks));
890 store.register_late_pass(move || Box::new(format_args::FormatArgs));
891 store.register_late_pass(|| Box::new(trailing_empty_array::TrailingEmptyArray));
892 store.register_early_pass(|| Box::new(octal_escapes::OctalEscapes));
893 store.register_late_pass(|| Box::new(needless_late_init::NeedlessLateInit));
894 store.register_late_pass(|| Box::new(return_self_not_must_use::ReturnSelfNotMustUse));
895 store.register_late_pass(|| Box::new(init_numbered_fields::NumberedFields));
896 store.register_early_pass(|| Box::new(single_char_lifetime_names::SingleCharLifetimeNames));
897 store.register_late_pass(move || Box::new(borrow_as_ptr::BorrowAsPtr::new(msrv)));
898 store.register_late_pass(move || Box::new(manual_bits::ManualBits::new(msrv)));
899 store.register_late_pass(|| Box::new(default_union_representation::DefaultUnionRepresentation));
900 store.register_early_pass(|| Box::new(doc_link_with_quotes::DocLinkWithQuotes));
901 store.register_late_pass(|| Box::new(only_used_in_recursion::OnlyUsedInRecursion));
902 let allow_dbg_in_tests = conf.allow_dbg_in_tests;
903 store.register_late_pass(move || Box::new(dbg_macro::DbgMacro::new(allow_dbg_in_tests)));
904 let cargo_ignore_publish = conf.cargo_ignore_publish;
905 store.register_late_pass(move || {
906 Box::new(cargo::Cargo {
907 ignore_publish: cargo_ignore_publish,
910 store.register_early_pass(|| Box::new(crate_in_macro_def::CrateInMacroDef));
911 store.register_early_pass(|| Box::new(empty_structs_with_brackets::EmptyStructsWithBrackets));
912 store.register_late_pass(|| Box::new(unnecessary_owned_empty_strings::UnnecessaryOwnedEmptyStrings));
913 store.register_early_pass(|| Box::new(pub_use::PubUse));
914 store.register_late_pass(|| Box::new(format_push_string::FormatPushString));
915 store.register_late_pass(|| Box::new(bytes_count_to_len::BytesCountToLen));
916 let max_include_file_size = conf.max_include_file_size;
917 store.register_late_pass(move || Box::new(large_include_file::LargeIncludeFile::new(max_include_file_size)));
918 store.register_late_pass(|| Box::new(strings::TrimSplitWhitespace));
919 store.register_late_pass(|| Box::new(rc_clone_in_vec_init::RcCloneInVecInit));
920 store.register_early_pass(|| Box::new(duplicate_mod::DuplicateMod::default()));
921 store.register_late_pass(|| Box::new(get_first::GetFirst));
922 store.register_early_pass(|| Box::new(unused_rounding::UnusedRounding));
923 store.register_early_pass(move || Box::new(almost_complete_letter_range::AlmostCompleteLetterRange::new(msrv)));
924 store.register_late_pass(|| Box::new(swap_ptr_to_ref::SwapPtrToRef));
925 store.register_late_pass(|| Box::new(mismatching_type_param_order::TypeParamMismatch));
926 store.register_late_pass(|| Box::new(as_underscore::AsUnderscore));
927 store.register_late_pass(|| Box::new(read_zero_byte_vec::ReadZeroByteVec));
928 store.register_late_pass(|| Box::new(default_instead_of_iter_empty::DefaultIterEmpty));
929 store.register_late_pass(move || Box::new(manual_rem_euclid::ManualRemEuclid::new(msrv)));
930 store.register_late_pass(move || Box::new(manual_retain::ManualRetain::new(msrv)));
931 let verbose_bit_mask_threshold = conf.verbose_bit_mask_threshold;
932 store.register_late_pass(move || Box::new(operators::Operators::new(verbose_bit_mask_threshold)));
933 store.register_late_pass(|| Box::new(invalid_utf8_in_unchecked::InvalidUtf8InUnchecked));
934 store.register_late_pass(|| Box::new(std_instead_of_core::StdReexports::default()));
935 store.register_late_pass(|| Box::new(manual_instant_elapsed::ManualInstantElapsed));
936 store.register_late_pass(|| Box::new(partialeq_to_none::PartialeqToNone));
937 // add lints here, do not remove this comment, it's used in `new_lint`
941 fn register_removed_non_tool_lints(store: &mut rustc_lint::LintStore) {
942 store.register_removed(
944 "`assert!()` will be more flexible with RFC 2011",
946 store.register_removed(
948 "`.extend_from_slice(_)` is a faster way to extend a Vec by a slice",
950 store.register_removed(
951 "range_step_by_zero",
952 "`iterator.step_by(0)` panics nowadays",
954 store.register_removed(
956 "`Vec::as_slice` has been stabilized in 1.7",
958 store.register_removed(
959 "unstable_as_mut_slice",
960 "`Vec::as_mut_slice` has been stabilized in 1.7",
962 store.register_removed(
963 "misaligned_transmute",
964 "this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr",
966 store.register_removed(
968 "using compound assignment operators (e.g., `+=`) is harmless",
970 store.register_removed(
971 "if_let_redundant_pattern_matching",
972 "this lint has been changed to redundant_pattern_matching",
974 store.register_removed(
975 "unsafe_vector_initialization",
976 "the replacement suggested by this lint had substantially different behavior",
978 store.register_removed(
979 "reverse_range_loop",
980 "this lint is now included in reversed_empty_ranges",
984 /// Register renamed lints.
986 /// Used in `./src/driver.rs`.
987 pub fn register_renamed(ls: &mut rustc_lint::LintStore) {
988 for (old_name, new_name) in renamed_lints::RENAMED_LINTS {
989 ls.register_renamed(old_name, new_name);
993 // only exists to let the dogfood integration test works.
994 // Don't run clippy as an executable directly
997 panic!("Please use the cargo-clippy executable");