1 // error-pattern:cargo-clippy
3 #![feature(array_windows)]
4 #![feature(binary_heap_into_iter_sorted)]
5 #![feature(box_patterns)]
6 #![feature(control_flow_enum)]
7 #![feature(drain_filter)]
8 #![feature(iter_intersperse)]
9 #![feature(let_chains)]
11 #![feature(lint_reasons)]
12 #![feature(once_cell)]
13 #![feature(rustc_private)]
14 #![feature(stmt_expr_attributes)]
15 #![recursion_limit = "512"]
16 #![cfg_attr(feature = "deny-warnings", deny(warnings))]
17 #![allow(clippy::missing_docs_in_private_items, clippy::must_use_candidate)]
18 #![warn(trivial_casts, trivial_numeric_casts)]
19 // warn on lints, that are included in `rust-lang/rust`s bootstrap
20 #![warn(rust_2018_idioms, unused_lifetimes)]
21 // warn on rustc internal lints
22 #![warn(rustc::internal)]
23 // Disable this rustc lint for now, as it was also done in rustc
24 #![allow(rustc::potential_query_instability)]
26 // FIXME: switch to something more ergonomic here, once available.
27 // (Currently there is no way to opt into sysroot crates without `extern crate`.)
28 extern crate rustc_arena;
29 extern crate rustc_ast;
30 extern crate rustc_ast_pretty;
31 extern crate rustc_attr;
32 extern crate rustc_data_structures;
33 extern crate rustc_driver;
34 extern crate rustc_errors;
35 extern crate rustc_hir;
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_mir_dataflow;
43 extern crate rustc_parse;
44 extern crate rustc_parse_format;
45 extern crate rustc_session;
46 extern crate rustc_span;
47 extern crate rustc_target;
48 extern crate rustc_trait_selection;
49 extern crate rustc_typeck;
52 extern crate clippy_utils;
54 use clippy_utils::parse_msrv;
55 use rustc_data_structures::fx::FxHashSet;
56 use rustc_lint::LintId;
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.
92 /// /// Insert a short example of code that triggers the lint
95 /// /// Insert a short example of improved code that doesn't trigger the lint
102 /// [lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints
104 macro_rules! declare_clippy_lint {
105 { $(#[$attr:meta])* pub $name:tt, style, $description:tt } => {
107 $(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
110 { $(#[$attr:meta])* pub $name:tt, correctness, $description:tt } => {
112 $(#[$attr])* pub clippy::$name, Deny, $description, report_in_external_macro: true
115 { $(#[$attr:meta])* pub $name:tt, suspicious, $description:tt } => {
117 $(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
120 { $(#[$attr:meta])* pub $name:tt, complexity, $description:tt } => {
122 $(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
125 { $(#[$attr:meta])* pub $name:tt, perf, $description:tt } => {
127 $(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
130 { $(#[$attr:meta])* pub $name:tt, pedantic, $description:tt } => {
132 $(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
135 { $(#[$attr:meta])* pub $name:tt, restriction, $description:tt } => {
137 $(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
140 { $(#[$attr:meta])* pub $name:tt, cargo, $description:tt } => {
142 $(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
145 { $(#[$attr:meta])* pub $name:tt, nursery, $description:tt } => {
147 $(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
150 { $(#[$attr:meta])* pub $name:tt, internal, $description:tt } => {
152 $(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
155 { $(#[$attr:meta])* pub $name:tt, internal_warn, $description:tt } => {
157 $(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
162 #[cfg(feature = "internal")]
163 mod deprecated_lints;
164 #[cfg_attr(feature = "internal", allow(clippy::missing_clippy_version_attribute))]
169 // begin lints modules, do not remove this comment, it’s used in `update_lints`
170 mod absurd_extreme_comparisons;
171 mod almost_complete_letter_range;
176 mod assertions_on_constants;
178 mod async_yields_async;
180 mod await_holding_invalid;
182 mod blacklisted_name;
183 mod blocks_in_if_conditions;
184 mod bool_assert_comparison;
187 mod borrow_deref_ref;
189 mod bytes_count_to_len;
191 mod case_sensitive_file_extension_comparisons;
193 mod checked_conversions;
194 mod cognitive_complexity;
196 mod collapsible_match;
197 mod comparison_chain;
200 mod crate_in_macro_def;
204 mod default_numeric_fallback;
205 mod default_union_representation;
209 mod disallowed_methods;
210 mod disallowed_script_idents;
211 mod disallowed_types;
213 mod doc_link_with_quotes;
214 mod double_comparison;
219 mod else_if_without_else;
222 mod empty_structs_with_brackets;
227 mod equatable_if_let;
232 mod exhaustive_items;
235 mod fallible_impl_from;
236 mod float_equality_without_abs;
238 mod floating_point_arithmetic;
242 mod format_push_string;
245 mod from_str_radix_10;
252 mod if_then_some_else_none;
255 mod implicit_saturating_sub;
256 mod inconsistent_struct_constructor;
257 mod index_refutable_slice;
258 mod indexing_slicing;
261 mod inherent_to_string;
262 mod init_numbered_fields;
263 mod inline_fn_without_body;
265 mod integer_division;
266 mod invalid_upcast_comparisons;
267 mod items_after_statements;
268 mod iter_not_returning_iterator;
269 mod large_const_arrays;
270 mod large_enum_variant;
271 mod large_include_file;
272 mod large_stack_arrays;
277 mod literal_representation;
285 mod manual_non_exhaustive;
288 mod manual_unwrap_or;
292 mod match_on_vec_items;
294 mod match_str_case_mismatch;
302 mod missing_const_for_fn;
304 mod missing_enforced_import_rename;
306 mod mixed_read_write_in_expression;
308 mod modulo_arithmetic;
313 mod mutable_debug_assertion;
315 mod needless_arbitrary_self_type;
316 mod needless_bitwise_bool;
318 mod needless_borrowed_ref;
319 mod needless_continue;
320 mod needless_for_each;
321 mod needless_late_init;
322 mod needless_pass_by_value;
323 mod needless_question_mark;
325 mod neg_cmp_op_on_partial_ord;
327 mod new_without_default;
330 mod non_expressive_names;
331 mod non_octal_unix_permissions;
332 mod non_send_fields_in_send_ty;
333 mod nonstandard_macro_braces;
335 mod only_used_in_recursion;
337 mod option_env_unwrap;
338 mod option_if_let_else;
339 mod overflow_check_conditional;
340 mod panic_in_result_fn;
341 mod panic_unimplemented;
342 mod partialeq_ne_impl;
343 mod pass_by_ref_or_value;
344 mod path_buf_push_overwrite;
345 mod pattern_type_mismatch;
349 mod ptr_offset_with_cast;
353 mod rc_clone_in_vec_init;
355 mod redundant_closure_call;
357 mod redundant_field_names;
358 mod redundant_pub_crate;
359 mod redundant_slicing;
360 mod redundant_static_lifetimes;
365 mod return_self_not_must_use;
367 mod same_name_method;
369 mod self_named_constructors;
370 mod semicolon_if_nothing_returned;
373 mod significant_drop_in_scrutinee;
374 mod single_char_lifetime_names;
375 mod single_component_path_imports;
376 mod size_of_in_element_count;
377 mod slow_vector_initialization;
378 mod stable_sort_primitive;
380 mod strlen_on_c_strings;
381 mod suspicious_operation_groupings;
382 mod suspicious_trait_impl;
385 mod tabs_in_doc_comments;
386 mod temporary_assignment;
387 mod to_digit_is_some;
388 mod trailing_empty_array;
391 mod transmuting_null;
394 mod undocumented_unsafe_blocks;
398 mod unit_return_expecting_ord;
401 mod unnecessary_owned_empty_strings;
402 mod unnecessary_self_imports;
403 mod unnecessary_sort_by;
404 mod unnecessary_wraps;
405 mod unnested_or_patterns;
406 mod unsafe_removed_from_name;
408 mod unused_io_amount;
413 mod unwrap_in_result;
414 mod upper_case_acronyms;
416 mod useless_conversion;
418 mod vec_init_then_push;
419 mod vec_resize_to_zero;
420 mod verbose_file_reads;
421 mod wildcard_imports;
424 mod zero_sized_map_values;
425 // end lints modules, do not remove this comment, it’s used in `update_lints`
427 pub use crate::utils::conf::Conf;
428 use crate::utils::conf::{format_error, TryConf};
430 /// Register all pre expansion lints
432 /// Pre-expansion lints run before any macro expansion has happened.
434 /// Note that due to the architecture of the compiler, currently `cfg_attr` attributes on crate
435 /// level (i.e `#![cfg_attr(...)]`) will still be expanded even when using a pre-expansion pass.
437 /// Used in `./src/driver.rs`.
438 pub fn register_pre_expansion_lints(store: &mut rustc_lint::LintStore, sess: &Session, conf: &Conf) {
439 // NOTE: Do not add any more pre-expansion passes. These should be removed eventually.
441 let msrv = conf.msrv.as_ref().and_then(|s| {
442 parse_msrv(s, None, None).or_else(|| {
444 "error reading Clippy's configuration file. `{}` is not a valid Rust version",
451 store.register_pre_expansion_pass(|| Box::new(write::Write::default()));
452 store.register_pre_expansion_pass(move || Box::new(attrs::EarlyAttributes { msrv }));
456 pub fn read_conf(sess: &Session) -> Conf {
457 let file_name = match utils::conf::lookup_conf_file() {
458 Ok(Some(path)) => path,
459 Ok(None) => return Conf::default(),
461 sess.struct_err(&format!("error finding Clippy's configuration file: {}", error))
463 return Conf::default();
467 let TryConf { conf, errors } = utils::conf::read(&file_name);
468 // all conf errors are non-fatal, we just use the default conf in case of error
469 for error in errors {
470 sess.struct_err(&format!(
471 "error reading Clippy's configuration file `{}`: {}",
481 /// Register all lints and lint groups with the rustc plugin registry
483 /// Used in `./src/driver.rs`.
484 #[expect(clippy::too_many_lines)]
485 pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: &Conf) {
486 register_removed_non_tool_lints(store);
488 include!("lib.deprecated.rs");
490 include!("lib.register_lints.rs");
491 include!("lib.register_restriction.rs");
492 include!("lib.register_pedantic.rs");
494 #[cfg(feature = "internal")]
495 include!("lib.register_internal.rs");
497 include!("lib.register_all.rs");
498 include!("lib.register_style.rs");
499 include!("lib.register_complexity.rs");
500 include!("lib.register_correctness.rs");
501 include!("lib.register_suspicious.rs");
502 include!("lib.register_perf.rs");
503 include!("lib.register_cargo.rs");
504 include!("lib.register_nursery.rs");
506 #[cfg(feature = "internal")]
508 if std::env::var("ENABLE_METADATA_COLLECTION").eq(&Ok("1".to_string())) {
509 store.register_late_pass(|| Box::new(utils::internal_lints::metadata_collector::MetadataCollector::new()));
514 // all the internal lints
515 #[cfg(feature = "internal")]
517 store.register_early_pass(|| Box::new(utils::internal_lints::ClippyLintsInternal));
518 store.register_early_pass(|| Box::new(utils::internal_lints::ProduceIce));
519 store.register_late_pass(|| Box::new(utils::internal_lints::CollapsibleCalls));
520 store.register_late_pass(|| Box::new(utils::internal_lints::CompilerLintFunctions::new()));
521 store.register_late_pass(|| Box::new(utils::internal_lints::IfChainStyle));
522 store.register_late_pass(|| Box::new(utils::internal_lints::InvalidPaths));
523 store.register_late_pass(|| Box::new(utils::internal_lints::InterningDefinedSymbol::default()));
524 store.register_late_pass(|| Box::new(utils::internal_lints::LintWithoutLintPass::default()));
525 store.register_late_pass(|| Box::new(utils::internal_lints::MatchTypeOnDiagItem));
526 store.register_late_pass(|| Box::new(utils::internal_lints::OuterExpnDataPass));
527 store.register_late_pass(|| Box::new(utils::internal_lints::MsrvAttrImpl));
530 store.register_late_pass(|| Box::new(utils::dump_hir::DumpHir));
531 store.register_late_pass(|| Box::new(utils::author::Author));
532 let await_holding_invalid_types = conf.await_holding_invalid_types.clone();
533 store.register_late_pass(move || {
534 Box::new(await_holding_invalid::AwaitHolding::new(
535 await_holding_invalid_types.clone(),
538 store.register_late_pass(|| Box::new(serde_api::SerdeApi));
539 let vec_box_size_threshold = conf.vec_box_size_threshold;
540 let type_complexity_threshold = conf.type_complexity_threshold;
541 let avoid_breaking_exported_api = conf.avoid_breaking_exported_api;
542 store.register_late_pass(move || {
543 Box::new(types::Types::new(
544 vec_box_size_threshold,
545 type_complexity_threshold,
546 avoid_breaking_exported_api,
549 store.register_late_pass(|| Box::new(booleans::NonminimalBool));
550 store.register_late_pass(|| Box::new(needless_bitwise_bool::NeedlessBitwiseBool));
551 store.register_late_pass(|| Box::new(eq_op::EqOp));
552 store.register_late_pass(|| Box::new(enum_clike::UnportableVariant));
553 store.register_late_pass(|| Box::new(float_literal::FloatLiteral));
554 let verbose_bit_mask_threshold = conf.verbose_bit_mask_threshold;
555 store.register_late_pass(move || Box::new(bit_mask::BitMask::new(verbose_bit_mask_threshold)));
556 store.register_late_pass(|| Box::new(ptr::Ptr));
557 store.register_late_pass(|| Box::new(ptr_eq::PtrEq));
558 store.register_late_pass(|| Box::new(needless_bool::NeedlessBool));
559 store.register_late_pass(|| Box::new(needless_bool::BoolComparison));
560 store.register_late_pass(|| Box::new(needless_for_each::NeedlessForEach));
561 store.register_late_pass(|| Box::new(misc::MiscLints));
562 store.register_late_pass(|| Box::new(eta_reduction::EtaReduction));
563 store.register_late_pass(|| Box::new(identity_op::IdentityOp));
564 store.register_late_pass(|| Box::new(erasing_op::ErasingOp));
565 store.register_late_pass(|| Box::new(mut_mut::MutMut));
566 store.register_late_pass(|| Box::new(mut_reference::UnnecessaryMutPassed));
567 store.register_late_pass(|| Box::new(len_zero::LenZero));
568 store.register_late_pass(|| Box::new(attrs::Attributes));
569 store.register_late_pass(|| Box::new(blocks_in_if_conditions::BlocksInIfConditions));
570 store.register_late_pass(|| Box::new(collapsible_match::CollapsibleMatch));
571 store.register_late_pass(|| Box::new(unicode::Unicode));
572 store.register_late_pass(|| Box::new(uninit_vec::UninitVec));
573 store.register_late_pass(|| Box::new(unit_hash::UnitHash));
574 store.register_late_pass(|| Box::new(unit_return_expecting_ord::UnitReturnExpectingOrd));
575 store.register_late_pass(|| Box::new(strings::StringAdd));
576 store.register_late_pass(|| Box::new(implicit_return::ImplicitReturn));
577 store.register_late_pass(|| Box::new(implicit_saturating_sub::ImplicitSaturatingSub));
578 store.register_late_pass(|| Box::new(default_numeric_fallback::DefaultNumericFallback));
579 store.register_late_pass(|| Box::new(inconsistent_struct_constructor::InconsistentStructConstructor));
580 store.register_late_pass(|| Box::new(non_octal_unix_permissions::NonOctalUnixPermissions));
581 store.register_early_pass(|| Box::new(unnecessary_self_imports::UnnecessarySelfImports));
583 let msrv = conf.msrv.as_ref().and_then(|s| {
584 parse_msrv(s, None, None).or_else(|| {
586 "error reading Clippy's configuration file. `{}` is not a valid Rust version",
593 let avoid_breaking_exported_api = conf.avoid_breaking_exported_api;
594 let allow_expect_in_tests = conf.allow_expect_in_tests;
595 let allow_unwrap_in_tests = conf.allow_unwrap_in_tests;
596 store.register_late_pass(move || Box::new(approx_const::ApproxConstant::new(msrv)));
597 store.register_late_pass(move || {
598 Box::new(methods::Methods::new(
599 avoid_breaking_exported_api,
601 allow_expect_in_tests,
602 allow_unwrap_in_tests,
605 store.register_late_pass(move || Box::new(matches::Matches::new(msrv)));
606 store.register_early_pass(move || Box::new(manual_non_exhaustive::ManualNonExhaustiveStruct::new(msrv)));
607 store.register_late_pass(move || Box::new(manual_non_exhaustive::ManualNonExhaustiveEnum::new(msrv)));
608 store.register_late_pass(move || Box::new(manual_strip::ManualStrip::new(msrv)));
609 store.register_early_pass(move || Box::new(redundant_static_lifetimes::RedundantStaticLifetimes::new(msrv)));
610 store.register_early_pass(move || Box::new(redundant_field_names::RedundantFieldNames::new(msrv)));
611 store.register_late_pass(move || Box::new(checked_conversions::CheckedConversions::new(msrv)));
612 store.register_late_pass(move || Box::new(mem_replace::MemReplace::new(msrv)));
613 store.register_late_pass(move || Box::new(ranges::Ranges::new(msrv)));
614 store.register_late_pass(move || Box::new(from_over_into::FromOverInto::new(msrv)));
615 store.register_late_pass(move || Box::new(use_self::UseSelf::new(msrv)));
616 store.register_late_pass(move || Box::new(missing_const_for_fn::MissingConstForFn::new(msrv)));
617 store.register_late_pass(move || Box::new(needless_question_mark::NeedlessQuestionMark));
618 store.register_late_pass(move || Box::new(casts::Casts::new(msrv)));
619 store.register_early_pass(move || Box::new(unnested_or_patterns::UnnestedOrPatterns::new(msrv)));
620 store.register_late_pass(move || Box::new(map_clone::MapClone::new(msrv)));
622 store.register_late_pass(|| Box::new(size_of_in_element_count::SizeOfInElementCount));
623 store.register_late_pass(|| Box::new(same_name_method::SameNameMethod));
624 let max_suggested_slice_pattern_length = conf.max_suggested_slice_pattern_length;
625 store.register_late_pass(move || {
626 Box::new(index_refutable_slice::IndexRefutableSlice::new(
627 max_suggested_slice_pattern_length,
631 store.register_late_pass(|| Box::new(map_err_ignore::MapErrIgnore));
632 store.register_late_pass(|| Box::new(shadow::Shadow::default()));
633 store.register_late_pass(|| Box::new(unit_types::UnitTypes));
634 store.register_late_pass(|| Box::new(loops::Loops));
635 store.register_late_pass(|| Box::new(main_recursion::MainRecursion::default()));
636 store.register_late_pass(|| Box::new(lifetimes::Lifetimes));
637 store.register_late_pass(|| Box::new(entry::HashMapPass));
638 store.register_late_pass(|| Box::new(minmax::MinMaxPass));
639 store.register_late_pass(|| Box::new(open_options::OpenOptions));
640 store.register_late_pass(|| Box::new(zero_div_zero::ZeroDiv));
641 store.register_late_pass(|| Box::new(mutex_atomic::Mutex));
642 store.register_late_pass(|| Box::new(needless_update::NeedlessUpdate));
643 store.register_late_pass(|| Box::new(needless_borrowed_ref::NeedlessBorrowedRef));
644 store.register_late_pass(|| Box::new(borrow_deref_ref::BorrowDerefRef));
645 store.register_late_pass(|| Box::new(no_effect::NoEffect));
646 store.register_late_pass(|| Box::new(temporary_assignment::TemporaryAssignment));
647 store.register_late_pass(|| Box::new(transmute::Transmute));
648 let cognitive_complexity_threshold = conf.cognitive_complexity_threshold;
649 store.register_late_pass(move || {
650 Box::new(cognitive_complexity::CognitiveComplexity::new(
651 cognitive_complexity_threshold,
654 let too_large_for_stack = conf.too_large_for_stack;
655 store.register_late_pass(move || Box::new(escape::BoxedLocal { too_large_for_stack }));
656 store.register_late_pass(move || Box::new(vec::UselessVec { too_large_for_stack }));
657 store.register_late_pass(|| Box::new(panic_unimplemented::PanicUnimplemented));
658 store.register_late_pass(|| Box::new(strings::StringLitAsBytes));
659 store.register_late_pass(|| Box::new(derive::Derive));
660 store.register_late_pass(|| Box::new(derivable_impls::DerivableImpls));
661 store.register_late_pass(|| Box::new(drop_forget_ref::DropForgetRef));
662 store.register_late_pass(|| Box::new(empty_enum::EmptyEnum));
663 store.register_late_pass(|| Box::new(absurd_extreme_comparisons::AbsurdExtremeComparisons));
664 store.register_late_pass(|| Box::new(invalid_upcast_comparisons::InvalidUpcastComparisons));
665 store.register_late_pass(|| Box::new(regex::Regex));
666 store.register_late_pass(|| Box::new(copies::CopyAndPaste));
667 store.register_late_pass(|| Box::new(copy_iterator::CopyIterator));
668 store.register_late_pass(|| Box::new(format::UselessFormat));
669 store.register_late_pass(|| Box::new(swap::Swap));
670 store.register_late_pass(|| Box::new(overflow_check_conditional::OverflowCheckConditional));
671 store.register_late_pass(|| Box::new(new_without_default::NewWithoutDefault::default()));
672 let blacklisted_names = conf.blacklisted_names.iter().cloned().collect::<FxHashSet<_>>();
673 store.register_late_pass(move || Box::new(blacklisted_name::BlacklistedName::new(blacklisted_names.clone())));
674 let too_many_arguments_threshold = conf.too_many_arguments_threshold;
675 let too_many_lines_threshold = conf.too_many_lines_threshold;
676 store.register_late_pass(move || {
677 Box::new(functions::Functions::new(
678 too_many_arguments_threshold,
679 too_many_lines_threshold,
682 let doc_valid_idents = conf.doc_valid_idents.iter().cloned().collect::<FxHashSet<_>>();
683 store.register_late_pass(move || Box::new(doc::DocMarkdown::new(doc_valid_idents.clone())));
684 store.register_late_pass(|| Box::new(neg_multiply::NegMultiply));
685 store.register_late_pass(|| Box::new(mem_forget::MemForget));
686 store.register_late_pass(|| Box::new(arithmetic::Arithmetic::default()));
687 store.register_late_pass(|| Box::new(assign_ops::AssignOps));
688 store.register_late_pass(|| Box::new(let_if_seq::LetIfSeq));
689 store.register_late_pass(|| Box::new(mixed_read_write_in_expression::EvalOrderDependence));
690 store.register_late_pass(|| Box::new(missing_doc::MissingDoc::new()));
691 store.register_late_pass(|| Box::new(missing_inline::MissingInline));
692 store.register_late_pass(move || Box::new(exhaustive_items::ExhaustiveItems));
693 store.register_late_pass(|| Box::new(match_result_ok::MatchResultOk));
694 store.register_late_pass(|| Box::new(partialeq_ne_impl::PartialEqNeImpl));
695 store.register_late_pass(|| Box::new(unused_io_amount::UnusedIoAmount));
696 let enum_variant_size_threshold = conf.enum_variant_size_threshold;
697 store.register_late_pass(move || Box::new(large_enum_variant::LargeEnumVariant::new(enum_variant_size_threshold)));
698 store.register_late_pass(|| Box::new(explicit_write::ExplicitWrite));
699 store.register_late_pass(|| Box::new(needless_pass_by_value::NeedlessPassByValue));
700 let pass_by_ref_or_value = pass_by_ref_or_value::PassByRefOrValue::new(
701 conf.trivial_copy_size_limit,
702 conf.pass_by_value_size_limit,
703 conf.avoid_breaking_exported_api,
706 store.register_late_pass(move || Box::new(pass_by_ref_or_value));
707 store.register_late_pass(|| Box::new(ref_option_ref::RefOptionRef));
708 store.register_late_pass(|| Box::new(try_err::TryErr));
709 store.register_late_pass(|| Box::new(bytecount::ByteCount));
710 store.register_late_pass(|| Box::new(infinite_iter::InfiniteIter));
711 store.register_late_pass(|| Box::new(inline_fn_without_body::InlineFnWithoutBody));
712 store.register_late_pass(|| Box::new(useless_conversion::UselessConversion::default()));
713 store.register_late_pass(|| Box::new(implicit_hasher::ImplicitHasher));
714 store.register_late_pass(|| Box::new(fallible_impl_from::FallibleImplFrom));
715 store.register_late_pass(|| Box::new(double_comparison::DoubleComparisons));
716 store.register_late_pass(|| Box::new(question_mark::QuestionMark));
717 store.register_early_pass(|| Box::new(suspicious_operation_groupings::SuspiciousOperationGroupings));
718 store.register_late_pass(|| Box::new(suspicious_trait_impl::SuspiciousImpl));
719 store.register_late_pass(|| Box::new(map_unit_fn::MapUnit));
720 store.register_late_pass(|| Box::new(inherent_impl::MultipleInherentImpl));
721 store.register_late_pass(|| Box::new(neg_cmp_op_on_partial_ord::NoNegCompOpForPartialOrd));
722 store.register_late_pass(|| Box::new(unwrap::Unwrap));
723 store.register_late_pass(|| Box::new(duration_subsec::DurationSubsec));
724 store.register_late_pass(|| Box::new(indexing_slicing::IndexingSlicing));
725 store.register_late_pass(|| Box::new(non_copy_const::NonCopyConst));
726 store.register_late_pass(|| Box::new(ptr_offset_with_cast::PtrOffsetWithCast));
727 store.register_late_pass(|| Box::new(redundant_clone::RedundantClone));
728 store.register_late_pass(|| Box::new(slow_vector_initialization::SlowVectorInit));
729 store.register_late_pass(|| Box::new(unnecessary_sort_by::UnnecessarySortBy));
730 store.register_late_pass(move || Box::new(unnecessary_wraps::UnnecessaryWraps::new(avoid_breaking_exported_api)));
731 store.register_late_pass(|| Box::new(assertions_on_constants::AssertionsOnConstants));
732 store.register_late_pass(|| Box::new(transmuting_null::TransmutingNull));
733 store.register_late_pass(|| Box::new(path_buf_push_overwrite::PathBufPushOverwrite));
734 store.register_late_pass(|| Box::new(integer_division::IntegerDivision));
735 store.register_late_pass(|| Box::new(inherent_to_string::InherentToString));
736 let max_trait_bounds = conf.max_trait_bounds;
737 store.register_late_pass(move || Box::new(trait_bounds::TraitBounds::new(max_trait_bounds)));
738 store.register_late_pass(|| Box::new(comparison_chain::ComparisonChain));
739 store.register_late_pass(|| Box::new(mut_key::MutableKeyType));
740 store.register_late_pass(|| Box::new(modulo_arithmetic::ModuloArithmetic));
741 store.register_early_pass(|| Box::new(reference::DerefAddrOf));
742 store.register_early_pass(|| Box::new(double_parens::DoubleParens));
743 store.register_late_pass(|| Box::new(format_impl::FormatImpl::new()));
744 store.register_early_pass(|| Box::new(unsafe_removed_from_name::UnsafeNameRemoval));
745 store.register_early_pass(|| Box::new(else_if_without_else::ElseIfWithoutElse));
746 store.register_early_pass(|| Box::new(int_plus_one::IntPlusOne));
747 store.register_early_pass(|| Box::new(formatting::Formatting));
748 store.register_early_pass(|| Box::new(misc_early::MiscEarlyLints));
749 store.register_early_pass(|| Box::new(redundant_closure_call::RedundantClosureCall));
750 store.register_late_pass(|| Box::new(redundant_closure_call::RedundantClosureCall));
751 store.register_early_pass(|| Box::new(unused_unit::UnusedUnit));
752 store.register_late_pass(|| Box::new(returns::Return));
753 store.register_early_pass(|| Box::new(collapsible_if::CollapsibleIf));
754 store.register_early_pass(|| Box::new(items_after_statements::ItemsAfterStatements));
755 store.register_early_pass(|| Box::new(precedence::Precedence));
756 store.register_early_pass(|| Box::new(needless_continue::NeedlessContinue));
757 store.register_early_pass(|| Box::new(redundant_else::RedundantElse));
758 store.register_late_pass(|| Box::new(create_dir::CreateDir));
759 store.register_early_pass(|| Box::new(needless_arbitrary_self_type::NeedlessArbitrarySelfType));
760 let literal_representation_lint_fraction_readability = conf.unreadable_literal_lint_fractions;
761 store.register_early_pass(move || {
762 Box::new(literal_representation::LiteralDigitGrouping::new(
763 literal_representation_lint_fraction_readability,
766 let literal_representation_threshold = conf.literal_representation_threshold;
767 store.register_early_pass(move || {
768 Box::new(literal_representation::DecimalLiteralRepresentation::new(
769 literal_representation_threshold,
772 let enum_variant_name_threshold = conf.enum_variant_name_threshold;
773 store.register_late_pass(move || {
774 Box::new(enum_variants::EnumVariantNames::new(
775 enum_variant_name_threshold,
776 avoid_breaking_exported_api,
779 store.register_early_pass(|| Box::new(tabs_in_doc_comments::TabsInDocComments));
780 let upper_case_acronyms_aggressive = conf.upper_case_acronyms_aggressive;
781 store.register_late_pass(move || {
782 Box::new(upper_case_acronyms::UpperCaseAcronyms::new(
783 avoid_breaking_exported_api,
784 upper_case_acronyms_aggressive,
787 store.register_late_pass(|| Box::new(default::Default::default()));
788 store.register_late_pass(|| Box::new(unused_self::UnusedSelf));
789 store.register_late_pass(|| Box::new(mutable_debug_assertion::DebugAssertWithMutCall));
790 store.register_late_pass(|| Box::new(exit::Exit));
791 store.register_late_pass(|| Box::new(to_digit_is_some::ToDigitIsSome));
792 let array_size_threshold = conf.array_size_threshold;
793 store.register_late_pass(move || Box::new(large_stack_arrays::LargeStackArrays::new(array_size_threshold)));
794 store.register_late_pass(move || Box::new(large_const_arrays::LargeConstArrays::new(array_size_threshold)));
795 store.register_late_pass(|| Box::new(floating_point_arithmetic::FloatingPointArithmetic));
796 store.register_early_pass(|| Box::new(as_conversions::AsConversions));
797 store.register_late_pass(|| Box::new(let_underscore::LetUnderscore));
798 store.register_early_pass(|| Box::new(single_component_path_imports::SingleComponentPathImports));
799 let max_fn_params_bools = conf.max_fn_params_bools;
800 let max_struct_bools = conf.max_struct_bools;
801 store.register_early_pass(move || {
802 Box::new(excessive_bools::ExcessiveBools::new(
807 store.register_early_pass(|| Box::new(option_env_unwrap::OptionEnvUnwrap));
808 let warn_on_all_wildcard_imports = conf.warn_on_all_wildcard_imports;
809 store.register_late_pass(move || Box::new(wildcard_imports::WildcardImports::new(warn_on_all_wildcard_imports)));
810 store.register_late_pass(|| Box::new(verbose_file_reads::VerboseFileReads));
811 store.register_late_pass(|| Box::new(redundant_pub_crate::RedundantPubCrate::default()));
812 store.register_late_pass(|| Box::new(unnamed_address::UnnamedAddress));
813 store.register_late_pass(|| Box::new(dereference::Dereferencing::default()));
814 store.register_late_pass(|| Box::new(option_if_let_else::OptionIfLetElse));
815 store.register_late_pass(|| Box::new(future_not_send::FutureNotSend));
816 store.register_late_pass(|| Box::new(if_let_mutex::IfLetMutex));
817 store.register_late_pass(|| Box::new(if_not_else::IfNotElse));
818 store.register_late_pass(|| Box::new(equatable_if_let::PatternEquality));
819 store.register_late_pass(|| Box::new(mut_mutex_lock::MutMutexLock));
820 store.register_late_pass(|| Box::new(match_on_vec_items::MatchOnVecItems));
821 store.register_late_pass(|| Box::new(manual_async_fn::ManualAsyncFn));
822 store.register_late_pass(|| Box::new(vec_resize_to_zero::VecResizeToZero));
823 store.register_late_pass(|| Box::new(panic_in_result_fn::PanicInResultFn));
824 let single_char_binding_names_threshold = conf.single_char_binding_names_threshold;
825 store.register_early_pass(move || {
826 Box::new(non_expressive_names::NonExpressiveNames {
827 single_char_binding_names_threshold,
830 let macro_matcher = conf.standard_macro_braces.iter().cloned().collect::<FxHashSet<_>>();
831 store.register_early_pass(move || Box::new(nonstandard_macro_braces::MacroBraces::new(¯o_matcher)));
832 store.register_late_pass(|| Box::new(macro_use::MacroUseImports::default()));
833 store.register_late_pass(|| Box::new(pattern_type_mismatch::PatternTypeMismatch));
834 store.register_late_pass(|| Box::new(stable_sort_primitive::StableSortPrimitive));
835 store.register_late_pass(|| Box::new(repeat_once::RepeatOnce));
836 store.register_late_pass(|| Box::new(unwrap_in_result::UnwrapInResult));
837 store.register_late_pass(|| Box::new(self_assignment::SelfAssignment));
838 store.register_late_pass(|| Box::new(manual_unwrap_or::ManualUnwrapOr));
839 store.register_late_pass(|| Box::new(manual_ok_or::ManualOkOr));
840 store.register_late_pass(|| Box::new(float_equality_without_abs::FloatEqualityWithoutAbs));
841 store.register_late_pass(|| Box::new(semicolon_if_nothing_returned::SemicolonIfNothingReturned));
842 store.register_late_pass(|| Box::new(async_yields_async::AsyncYieldsAsync));
843 let disallowed_methods = conf.disallowed_methods.clone();
844 store.register_late_pass(move || Box::new(disallowed_methods::DisallowedMethods::new(disallowed_methods.clone())));
845 store.register_early_pass(|| Box::new(asm_syntax::InlineAsmX86AttSyntax));
846 store.register_early_pass(|| Box::new(asm_syntax::InlineAsmX86IntelSyntax));
847 store.register_late_pass(|| Box::new(empty_drop::EmptyDrop));
848 store.register_late_pass(|| Box::new(strings::StrToString));
849 store.register_late_pass(|| Box::new(strings::StringToString));
850 store.register_late_pass(|| Box::new(zero_sized_map_values::ZeroSizedMapValues));
851 store.register_late_pass(|| Box::new(vec_init_then_push::VecInitThenPush::default()));
852 store.register_late_pass(|| {
853 Box::new(case_sensitive_file_extension_comparisons::CaseSensitiveFileExtensionComparisons)
855 store.register_late_pass(|| Box::new(redundant_slicing::RedundantSlicing));
856 store.register_late_pass(|| Box::new(from_str_radix_10::FromStrRadix10));
857 store.register_late_pass(|| Box::new(manual_map::ManualMap));
858 store.register_late_pass(move || Box::new(if_then_some_else_none::IfThenSomeElseNone::new(msrv)));
859 store.register_late_pass(|| Box::new(bool_assert_comparison::BoolAssertComparison));
860 store.register_early_pass(move || Box::new(module_style::ModStyle));
861 store.register_late_pass(|| Box::new(unused_async::UnusedAsync));
862 let disallowed_types = conf.disallowed_types.clone();
863 store.register_late_pass(move || Box::new(disallowed_types::DisallowedTypes::new(disallowed_types.clone())));
864 let import_renames = conf.enforced_import_renames.clone();
865 store.register_late_pass(move || {
866 Box::new(missing_enforced_import_rename::ImportRename::new(
867 import_renames.clone(),
870 let scripts = conf.allowed_scripts.clone();
871 store.register_early_pass(move || Box::new(disallowed_script_idents::DisallowedScriptIdents::new(&scripts)));
872 store.register_late_pass(|| Box::new(strlen_on_c_strings::StrlenOnCStrings));
873 store.register_late_pass(move || Box::new(self_named_constructors::SelfNamedConstructors));
874 store.register_late_pass(move || Box::new(iter_not_returning_iterator::IterNotReturningIterator));
875 store.register_late_pass(move || Box::new(manual_assert::ManualAssert));
876 let enable_raw_pointer_heuristic_for_send = conf.enable_raw_pointer_heuristic_for_send;
877 store.register_late_pass(move || {
878 Box::new(non_send_fields_in_send_ty::NonSendFieldInSendTy::new(
879 enable_raw_pointer_heuristic_for_send,
882 store.register_late_pass(move || Box::new(undocumented_unsafe_blocks::UndocumentedUnsafeBlocks));
883 store.register_late_pass(|| Box::new(match_str_case_mismatch::MatchStrCaseMismatch));
884 store.register_late_pass(move || Box::new(format_args::FormatArgs));
885 store.register_late_pass(|| Box::new(trailing_empty_array::TrailingEmptyArray));
886 store.register_early_pass(|| Box::new(octal_escapes::OctalEscapes));
887 store.register_late_pass(|| Box::new(needless_late_init::NeedlessLateInit));
888 store.register_late_pass(|| Box::new(return_self_not_must_use::ReturnSelfNotMustUse));
889 store.register_late_pass(|| Box::new(init_numbered_fields::NumberedFields));
890 store.register_early_pass(|| Box::new(single_char_lifetime_names::SingleCharLifetimeNames));
891 store.register_late_pass(move || Box::new(borrow_as_ptr::BorrowAsPtr::new(msrv)));
892 store.register_late_pass(move || Box::new(manual_bits::ManualBits::new(msrv)));
893 store.register_late_pass(|| Box::new(default_union_representation::DefaultUnionRepresentation));
894 store.register_early_pass(|| Box::new(doc_link_with_quotes::DocLinkWithQuotes));
895 store.register_late_pass(|| Box::new(only_used_in_recursion::OnlyUsedInRecursion));
896 store.register_late_pass(|| Box::new(significant_drop_in_scrutinee::SignificantDropInScrutinee));
897 let allow_dbg_in_tests = conf.allow_dbg_in_tests;
898 store.register_late_pass(move || Box::new(dbg_macro::DbgMacro::new(allow_dbg_in_tests)));
899 let cargo_ignore_publish = conf.cargo_ignore_publish;
900 store.register_late_pass(move || {
901 Box::new(cargo::Cargo {
902 ignore_publish: cargo_ignore_publish,
905 store.register_early_pass(|| Box::new(crate_in_macro_def::CrateInMacroDef));
906 store.register_early_pass(|| Box::new(empty_structs_with_brackets::EmptyStructsWithBrackets));
907 store.register_late_pass(|| Box::new(unnecessary_owned_empty_strings::UnnecessaryOwnedEmptyStrings));
908 store.register_early_pass(|| Box::new(pub_use::PubUse));
909 store.register_late_pass(|| Box::new(format_push_string::FormatPushString));
910 store.register_late_pass(|| Box::new(bytes_count_to_len::BytesCountToLen));
911 let max_include_file_size = conf.max_include_file_size;
912 store.register_late_pass(move || Box::new(large_include_file::LargeIncludeFile::new(max_include_file_size)));
913 store.register_late_pass(|| Box::new(strings::TrimSplitWhitespace));
914 store.register_late_pass(|| Box::new(rc_clone_in_vec_init::RcCloneInVecInit));
915 store.register_early_pass(|| Box::new(duplicate_mod::DuplicateMod::default()));
916 store.register_late_pass(|| Box::new(get_first::GetFirst));
917 store.register_early_pass(|| Box::new(unused_rounding::UnusedRounding));
918 store.register_early_pass(move || Box::new(almost_complete_letter_range::AlmostCompleteLetterRange::new(msrv)));
919 store.register_late_pass(|| Box::new(swap_ptr_to_ref::SwapPtrToRef));
920 // add lints here, do not remove this comment, it's used in `new_lint`
924 fn register_removed_non_tool_lints(store: &mut rustc_lint::LintStore) {
925 store.register_removed(
927 "`assert!()` will be more flexible with RFC 2011",
929 store.register_removed(
931 "`.extend_from_slice(_)` is a faster way to extend a Vec by a slice",
933 store.register_removed(
934 "range_step_by_zero",
935 "`iterator.step_by(0)` panics nowadays",
937 store.register_removed(
939 "`Vec::as_slice` has been stabilized in 1.7",
941 store.register_removed(
942 "unstable_as_mut_slice",
943 "`Vec::as_mut_slice` has been stabilized in 1.7",
945 store.register_removed(
946 "misaligned_transmute",
947 "this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr",
949 store.register_removed(
951 "using compound assignment operators (e.g., `+=`) is harmless",
953 store.register_removed(
954 "if_let_redundant_pattern_matching",
955 "this lint has been changed to redundant_pattern_matching",
957 store.register_removed(
958 "unsafe_vector_initialization",
959 "the replacement suggested by this lint had substantially different behavior",
961 store.register_removed(
962 "reverse_range_loop",
963 "this lint is now included in reversed_empty_ranges",
967 /// Register renamed lints.
969 /// Used in `./src/driver.rs`.
970 pub fn register_renamed(ls: &mut rustc_lint::LintStore) {
971 for (old_name, new_name) in renamed_lints::RENAMED_LINTS {
972 ls.register_renamed(old_name, new_name);
976 // only exists to let the dogfood integration test works.
977 // Don't run clippy as an executable directly
980 panic!("Please use the cargo-clippy executable");