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;
175 mod assertions_on_constants;
177 mod async_yields_async;
179 mod await_holding_invalid;
181 mod blacklisted_name;
182 mod blocks_in_if_conditions;
183 mod bool_assert_comparison;
187 mod bytes_count_to_len;
189 mod case_sensitive_file_extension_comparisons;
191 mod checked_conversions;
192 mod cognitive_complexity;
194 mod collapsible_match;
195 mod comparison_chain;
198 mod crate_in_macro_def;
202 mod default_numeric_fallback;
203 mod default_union_representation;
207 mod disallowed_methods;
208 mod disallowed_script_idents;
209 mod disallowed_types;
211 mod double_comparison;
216 mod else_if_without_else;
219 mod empty_structs_with_brackets;
224 mod equatable_if_let;
229 mod exhaustive_items;
232 mod fallible_impl_from;
233 mod float_equality_without_abs;
235 mod floating_point_arithmetic;
239 mod format_push_string;
242 mod from_str_radix_10;
245 mod get_last_with_len;
249 mod if_then_some_else_none;
252 mod implicit_saturating_sub;
253 mod inconsistent_struct_constructor;
254 mod index_refutable_slice;
255 mod indexing_slicing;
258 mod inherent_to_string;
259 mod init_numbered_fields;
260 mod inline_fn_without_body;
262 mod integer_division;
263 mod invalid_upcast_comparisons;
264 mod items_after_statements;
265 mod iter_not_returning_iterator;
266 mod large_const_arrays;
267 mod large_enum_variant;
268 mod large_include_file;
269 mod large_stack_arrays;
274 mod literal_representation;
282 mod manual_non_exhaustive;
285 mod manual_unwrap_or;
289 mod match_on_vec_items;
291 mod match_str_case_mismatch;
299 mod missing_const_for_fn;
301 mod missing_enforced_import_rename;
303 mod mixed_read_write_in_expression;
305 mod modulo_arithmetic;
310 mod mutable_debug_assertion;
312 mod needless_arbitrary_self_type;
313 mod needless_bitwise_bool;
315 mod needless_borrowed_ref;
316 mod needless_continue;
317 mod needless_for_each;
318 mod needless_late_init;
319 mod needless_pass_by_value;
320 mod needless_question_mark;
322 mod neg_cmp_op_on_partial_ord;
324 mod new_without_default;
327 mod non_expressive_names;
328 mod non_octal_unix_permissions;
329 mod non_send_fields_in_send_ty;
330 mod nonstandard_macro_braces;
332 mod only_used_in_recursion;
334 mod option_env_unwrap;
335 mod option_if_let_else;
336 mod overflow_check_conditional;
337 mod panic_in_result_fn;
338 mod panic_unimplemented;
339 mod partialeq_ne_impl;
340 mod pass_by_ref_or_value;
341 mod path_buf_push_overwrite;
342 mod pattern_type_mismatch;
346 mod ptr_offset_with_cast;
350 mod rc_clone_in_vec_init;
352 mod redundant_closure_call;
354 mod redundant_field_names;
355 mod redundant_pub_crate;
356 mod redundant_slicing;
357 mod redundant_static_lifetimes;
362 mod return_self_not_must_use;
364 mod same_name_method;
366 mod self_named_constructors;
367 mod semicolon_if_nothing_returned;
370 mod significant_drop_in_scrutinee;
371 mod single_char_lifetime_names;
372 mod single_component_path_imports;
373 mod size_of_in_element_count;
374 mod slow_vector_initialization;
375 mod stable_sort_primitive;
377 mod strlen_on_c_strings;
378 mod suspicious_operation_groupings;
379 mod suspicious_trait_impl;
381 mod tabs_in_doc_comments;
382 mod temporary_assignment;
383 mod to_digit_is_some;
384 mod trailing_empty_array;
387 mod transmuting_null;
390 mod undocumented_unsafe_blocks;
394 mod unit_return_expecting_ord;
397 mod unnecessary_owned_empty_strings;
398 mod unnecessary_self_imports;
399 mod unnecessary_sort_by;
400 mod unnecessary_wraps;
401 mod unnested_or_patterns;
402 mod unsafe_removed_from_name;
404 mod unused_io_amount;
408 mod unwrap_in_result;
409 mod upper_case_acronyms;
411 mod useless_conversion;
413 mod vec_init_then_push;
414 mod vec_resize_to_zero;
415 mod verbose_file_reads;
416 mod wildcard_imports;
419 mod zero_sized_map_values;
420 // end lints modules, do not remove this comment, it’s used in `update_lints`
422 pub use crate::utils::conf::Conf;
423 use crate::utils::conf::{format_error, TryConf};
425 /// Register all pre expansion lints
427 /// Pre-expansion lints run before any macro expansion has happened.
429 /// Note that due to the architecture of the compiler, currently `cfg_attr` attributes on crate
430 /// level (i.e `#![cfg_attr(...)]`) will still be expanded even when using a pre-expansion pass.
432 /// Used in `./src/driver.rs`.
433 pub fn register_pre_expansion_lints(store: &mut rustc_lint::LintStore, sess: &Session, conf: &Conf) {
434 // NOTE: Do not add any more pre-expansion passes. These should be removed eventually.
436 let msrv = conf.msrv.as_ref().and_then(|s| {
437 parse_msrv(s, None, None).or_else(|| {
439 "error reading Clippy's configuration file. `{}` is not a valid Rust version",
446 store.register_pre_expansion_pass(|| Box::new(write::Write::default()));
447 store.register_pre_expansion_pass(move || Box::new(attrs::EarlyAttributes { msrv }));
451 pub fn read_conf(sess: &Session) -> Conf {
452 let file_name = match utils::conf::lookup_conf_file() {
453 Ok(Some(path)) => path,
454 Ok(None) => return Conf::default(),
456 sess.struct_err(&format!("error finding Clippy's configuration file: {}", error))
458 return Conf::default();
462 let TryConf { conf, errors } = utils::conf::read(&file_name);
463 // all conf errors are non-fatal, we just use the default conf in case of error
464 for error in errors {
465 sess.struct_err(&format!(
466 "error reading Clippy's configuration file `{}`: {}",
476 /// Register all lints and lint groups with the rustc plugin registry
478 /// Used in `./src/driver.rs`.
479 #[expect(clippy::too_many_lines)]
480 pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: &Conf) {
481 register_removed_non_tool_lints(store);
483 include!("lib.deprecated.rs");
485 include!("lib.register_lints.rs");
486 include!("lib.register_restriction.rs");
487 include!("lib.register_pedantic.rs");
489 #[cfg(feature = "internal")]
490 include!("lib.register_internal.rs");
492 include!("lib.register_all.rs");
493 include!("lib.register_style.rs");
494 include!("lib.register_complexity.rs");
495 include!("lib.register_correctness.rs");
496 include!("lib.register_suspicious.rs");
497 include!("lib.register_perf.rs");
498 include!("lib.register_cargo.rs");
499 include!("lib.register_nursery.rs");
501 #[cfg(feature = "internal")]
503 if std::env::var("ENABLE_METADATA_COLLECTION").eq(&Ok("1".to_string())) {
504 store.register_late_pass(|| Box::new(utils::internal_lints::metadata_collector::MetadataCollector::new()));
509 // all the internal lints
510 #[cfg(feature = "internal")]
512 store.register_early_pass(|| Box::new(utils::internal_lints::ClippyLintsInternal));
513 store.register_early_pass(|| Box::new(utils::internal_lints::ProduceIce));
514 store.register_late_pass(|| Box::new(utils::internal_lints::CollapsibleCalls));
515 store.register_late_pass(|| Box::new(utils::internal_lints::CompilerLintFunctions::new()));
516 store.register_late_pass(|| Box::new(utils::internal_lints::IfChainStyle));
517 store.register_late_pass(|| Box::new(utils::internal_lints::InvalidPaths));
518 store.register_late_pass(|| Box::new(utils::internal_lints::InterningDefinedSymbol::default()));
519 store.register_late_pass(|| Box::new(utils::internal_lints::LintWithoutLintPass::default()));
520 store.register_late_pass(|| Box::new(utils::internal_lints::MatchTypeOnDiagItem));
521 store.register_late_pass(|| Box::new(utils::internal_lints::OuterExpnDataPass));
522 store.register_late_pass(|| Box::new(utils::internal_lints::MsrvAttrImpl));
525 store.register_late_pass(|| Box::new(utils::dump_hir::DumpHir));
526 store.register_late_pass(|| Box::new(utils::author::Author));
527 let await_holding_invalid_types = conf.await_holding_invalid_types.clone();
528 store.register_late_pass(move || {
529 Box::new(await_holding_invalid::AwaitHolding::new(
530 await_holding_invalid_types.clone(),
533 store.register_late_pass(|| Box::new(serde_api::SerdeApi));
534 let vec_box_size_threshold = conf.vec_box_size_threshold;
535 let type_complexity_threshold = conf.type_complexity_threshold;
536 let avoid_breaking_exported_api = conf.avoid_breaking_exported_api;
537 store.register_late_pass(move || {
538 Box::new(types::Types::new(
539 vec_box_size_threshold,
540 type_complexity_threshold,
541 avoid_breaking_exported_api,
544 store.register_late_pass(|| Box::new(booleans::NonminimalBool));
545 store.register_late_pass(|| Box::new(needless_bitwise_bool::NeedlessBitwiseBool));
546 store.register_late_pass(|| Box::new(eq_op::EqOp));
547 store.register_late_pass(|| Box::new(enum_clike::UnportableVariant));
548 store.register_late_pass(|| Box::new(float_literal::FloatLiteral));
549 let verbose_bit_mask_threshold = conf.verbose_bit_mask_threshold;
550 store.register_late_pass(move || Box::new(bit_mask::BitMask::new(verbose_bit_mask_threshold)));
551 store.register_late_pass(|| Box::new(ptr::Ptr));
552 store.register_late_pass(|| Box::new(ptr_eq::PtrEq));
553 store.register_late_pass(|| Box::new(needless_bool::NeedlessBool));
554 store.register_late_pass(|| Box::new(needless_bool::BoolComparison));
555 store.register_late_pass(|| Box::new(needless_for_each::NeedlessForEach));
556 store.register_late_pass(|| Box::new(misc::MiscLints));
557 store.register_late_pass(|| Box::new(eta_reduction::EtaReduction));
558 store.register_late_pass(|| Box::new(identity_op::IdentityOp));
559 store.register_late_pass(|| Box::new(erasing_op::ErasingOp));
560 store.register_late_pass(|| Box::new(mut_mut::MutMut));
561 store.register_late_pass(|| Box::new(mut_reference::UnnecessaryMutPassed));
562 store.register_late_pass(|| Box::new(len_zero::LenZero));
563 store.register_late_pass(|| Box::new(attrs::Attributes));
564 store.register_late_pass(|| Box::new(blocks_in_if_conditions::BlocksInIfConditions));
565 store.register_late_pass(|| Box::new(collapsible_match::CollapsibleMatch));
566 store.register_late_pass(|| Box::new(unicode::Unicode));
567 store.register_late_pass(|| Box::new(uninit_vec::UninitVec));
568 store.register_late_pass(|| Box::new(unit_hash::UnitHash));
569 store.register_late_pass(|| Box::new(unit_return_expecting_ord::UnitReturnExpectingOrd));
570 store.register_late_pass(|| Box::new(strings::StringAdd));
571 store.register_late_pass(|| Box::new(implicit_return::ImplicitReturn));
572 store.register_late_pass(|| Box::new(implicit_saturating_sub::ImplicitSaturatingSub));
573 store.register_late_pass(|| Box::new(default_numeric_fallback::DefaultNumericFallback));
574 store.register_late_pass(|| Box::new(inconsistent_struct_constructor::InconsistentStructConstructor));
575 store.register_late_pass(|| Box::new(non_octal_unix_permissions::NonOctalUnixPermissions));
576 store.register_early_pass(|| Box::new(unnecessary_self_imports::UnnecessarySelfImports));
578 let msrv = conf.msrv.as_ref().and_then(|s| {
579 parse_msrv(s, None, None).or_else(|| {
581 "error reading Clippy's configuration file. `{}` is not a valid Rust version",
588 let avoid_breaking_exported_api = conf.avoid_breaking_exported_api;
589 let allow_expect_in_tests = conf.allow_expect_in_tests;
590 let allow_unwrap_in_tests = conf.allow_unwrap_in_tests;
591 store.register_late_pass(move || Box::new(approx_const::ApproxConstant::new(msrv)));
592 store.register_late_pass(move || {
593 Box::new(methods::Methods::new(
594 avoid_breaking_exported_api,
596 allow_expect_in_tests,
597 allow_unwrap_in_tests,
600 store.register_late_pass(move || Box::new(matches::Matches::new(msrv)));
601 store.register_early_pass(move || Box::new(manual_non_exhaustive::ManualNonExhaustiveStruct::new(msrv)));
602 store.register_late_pass(move || Box::new(manual_non_exhaustive::ManualNonExhaustiveEnum::new(msrv)));
603 store.register_late_pass(move || Box::new(manual_strip::ManualStrip::new(msrv)));
604 store.register_early_pass(move || Box::new(redundant_static_lifetimes::RedundantStaticLifetimes::new(msrv)));
605 store.register_early_pass(move || Box::new(redundant_field_names::RedundantFieldNames::new(msrv)));
606 store.register_late_pass(move || Box::new(checked_conversions::CheckedConversions::new(msrv)));
607 store.register_late_pass(move || Box::new(mem_replace::MemReplace::new(msrv)));
608 store.register_late_pass(move || Box::new(ranges::Ranges::new(msrv)));
609 store.register_late_pass(move || Box::new(from_over_into::FromOverInto::new(msrv)));
610 store.register_late_pass(move || Box::new(use_self::UseSelf::new(msrv)));
611 store.register_late_pass(move || Box::new(missing_const_for_fn::MissingConstForFn::new(msrv)));
612 store.register_late_pass(move || Box::new(needless_question_mark::NeedlessQuestionMark));
613 store.register_late_pass(move || Box::new(casts::Casts::new(msrv)));
614 store.register_early_pass(move || Box::new(unnested_or_patterns::UnnestedOrPatterns::new(msrv)));
615 store.register_late_pass(move || Box::new(map_clone::MapClone::new(msrv)));
617 store.register_late_pass(|| Box::new(size_of_in_element_count::SizeOfInElementCount));
618 store.register_late_pass(|| Box::new(same_name_method::SameNameMethod));
619 let max_suggested_slice_pattern_length = conf.max_suggested_slice_pattern_length;
620 store.register_late_pass(move || {
621 Box::new(index_refutable_slice::IndexRefutableSlice::new(
622 max_suggested_slice_pattern_length,
626 store.register_late_pass(|| Box::new(map_err_ignore::MapErrIgnore));
627 store.register_late_pass(|| Box::new(shadow::Shadow::default()));
628 store.register_late_pass(|| Box::new(unit_types::UnitTypes));
629 store.register_late_pass(|| Box::new(loops::Loops));
630 store.register_late_pass(|| Box::new(main_recursion::MainRecursion::default()));
631 store.register_late_pass(|| Box::new(lifetimes::Lifetimes));
632 store.register_late_pass(|| Box::new(entry::HashMapPass));
633 store.register_late_pass(|| Box::new(minmax::MinMaxPass));
634 store.register_late_pass(|| Box::new(open_options::OpenOptions));
635 store.register_late_pass(|| Box::new(zero_div_zero::ZeroDiv));
636 store.register_late_pass(|| Box::new(mutex_atomic::Mutex));
637 store.register_late_pass(|| Box::new(needless_update::NeedlessUpdate));
638 store.register_late_pass(|| Box::new(needless_borrowed_ref::NeedlessBorrowedRef));
639 store.register_late_pass(|| Box::new(no_effect::NoEffect));
640 store.register_late_pass(|| Box::new(temporary_assignment::TemporaryAssignment));
641 store.register_late_pass(|| Box::new(transmute::Transmute));
642 let cognitive_complexity_threshold = conf.cognitive_complexity_threshold;
643 store.register_late_pass(move || {
644 Box::new(cognitive_complexity::CognitiveComplexity::new(
645 cognitive_complexity_threshold,
648 let too_large_for_stack = conf.too_large_for_stack;
649 store.register_late_pass(move || Box::new(escape::BoxedLocal { too_large_for_stack }));
650 store.register_late_pass(move || Box::new(vec::UselessVec { too_large_for_stack }));
651 store.register_late_pass(|| Box::new(panic_unimplemented::PanicUnimplemented));
652 store.register_late_pass(|| Box::new(strings::StringLitAsBytes));
653 store.register_late_pass(|| Box::new(derive::Derive));
654 store.register_late_pass(|| Box::new(derivable_impls::DerivableImpls));
655 store.register_late_pass(|| Box::new(get_last_with_len::GetLastWithLen));
656 store.register_late_pass(|| Box::new(drop_forget_ref::DropForgetRef));
657 store.register_late_pass(|| Box::new(empty_enum::EmptyEnum));
658 store.register_late_pass(|| Box::new(absurd_extreme_comparisons::AbsurdExtremeComparisons));
659 store.register_late_pass(|| Box::new(invalid_upcast_comparisons::InvalidUpcastComparisons));
660 store.register_late_pass(|| Box::new(regex::Regex));
661 store.register_late_pass(|| Box::new(copies::CopyAndPaste));
662 store.register_late_pass(|| Box::new(copy_iterator::CopyIterator));
663 store.register_late_pass(|| Box::new(format::UselessFormat));
664 store.register_late_pass(|| Box::new(swap::Swap));
665 store.register_late_pass(|| Box::new(overflow_check_conditional::OverflowCheckConditional));
666 store.register_late_pass(|| Box::new(new_without_default::NewWithoutDefault::default()));
667 let blacklisted_names = conf.blacklisted_names.iter().cloned().collect::<FxHashSet<_>>();
668 store.register_late_pass(move || Box::new(blacklisted_name::BlacklistedName::new(blacklisted_names.clone())));
669 let too_many_arguments_threshold = conf.too_many_arguments_threshold;
670 let too_many_lines_threshold = conf.too_many_lines_threshold;
671 store.register_late_pass(move || {
672 Box::new(functions::Functions::new(
673 too_many_arguments_threshold,
674 too_many_lines_threshold,
677 let doc_valid_idents = conf.doc_valid_idents.iter().cloned().collect::<FxHashSet<_>>();
678 store.register_late_pass(move || Box::new(doc::DocMarkdown::new(doc_valid_idents.clone())));
679 store.register_late_pass(|| Box::new(neg_multiply::NegMultiply));
680 store.register_late_pass(|| Box::new(mem_forget::MemForget));
681 store.register_late_pass(|| Box::new(arithmetic::Arithmetic::default()));
682 store.register_late_pass(|| Box::new(assign_ops::AssignOps));
683 store.register_late_pass(|| Box::new(let_if_seq::LetIfSeq));
684 store.register_late_pass(|| Box::new(mixed_read_write_in_expression::EvalOrderDependence));
685 store.register_late_pass(|| Box::new(missing_doc::MissingDoc::new()));
686 store.register_late_pass(|| Box::new(missing_inline::MissingInline));
687 store.register_late_pass(move || Box::new(exhaustive_items::ExhaustiveItems));
688 store.register_late_pass(|| Box::new(match_result_ok::MatchResultOk));
689 store.register_late_pass(|| Box::new(partialeq_ne_impl::PartialEqNeImpl));
690 store.register_late_pass(|| Box::new(unused_io_amount::UnusedIoAmount));
691 let enum_variant_size_threshold = conf.enum_variant_size_threshold;
692 store.register_late_pass(move || Box::new(large_enum_variant::LargeEnumVariant::new(enum_variant_size_threshold)));
693 store.register_late_pass(|| Box::new(explicit_write::ExplicitWrite));
694 store.register_late_pass(|| Box::new(needless_pass_by_value::NeedlessPassByValue));
695 let pass_by_ref_or_value = pass_by_ref_or_value::PassByRefOrValue::new(
696 conf.trivial_copy_size_limit,
697 conf.pass_by_value_size_limit,
698 conf.avoid_breaking_exported_api,
701 store.register_late_pass(move || Box::new(pass_by_ref_or_value));
702 store.register_late_pass(|| Box::new(ref_option_ref::RefOptionRef));
703 store.register_late_pass(|| Box::new(try_err::TryErr));
704 store.register_late_pass(|| Box::new(bytecount::ByteCount));
705 store.register_late_pass(|| Box::new(infinite_iter::InfiniteIter));
706 store.register_late_pass(|| Box::new(inline_fn_without_body::InlineFnWithoutBody));
707 store.register_late_pass(|| Box::new(useless_conversion::UselessConversion::default()));
708 store.register_late_pass(|| Box::new(implicit_hasher::ImplicitHasher));
709 store.register_late_pass(|| Box::new(fallible_impl_from::FallibleImplFrom));
710 store.register_late_pass(|| Box::new(double_comparison::DoubleComparisons));
711 store.register_late_pass(|| Box::new(question_mark::QuestionMark));
712 store.register_early_pass(|| Box::new(suspicious_operation_groupings::SuspiciousOperationGroupings));
713 store.register_late_pass(|| Box::new(suspicious_trait_impl::SuspiciousImpl));
714 store.register_late_pass(|| Box::new(map_unit_fn::MapUnit));
715 store.register_late_pass(|| Box::new(inherent_impl::MultipleInherentImpl));
716 store.register_late_pass(|| Box::new(neg_cmp_op_on_partial_ord::NoNegCompOpForPartialOrd));
717 store.register_late_pass(|| Box::new(unwrap::Unwrap));
718 store.register_late_pass(|| Box::new(duration_subsec::DurationSubsec));
719 store.register_late_pass(|| Box::new(indexing_slicing::IndexingSlicing));
720 store.register_late_pass(|| Box::new(non_copy_const::NonCopyConst));
721 store.register_late_pass(|| Box::new(ptr_offset_with_cast::PtrOffsetWithCast));
722 store.register_late_pass(|| Box::new(redundant_clone::RedundantClone));
723 store.register_late_pass(|| Box::new(slow_vector_initialization::SlowVectorInit));
724 store.register_late_pass(|| Box::new(unnecessary_sort_by::UnnecessarySortBy));
725 store.register_late_pass(move || Box::new(unnecessary_wraps::UnnecessaryWraps::new(avoid_breaking_exported_api)));
726 store.register_late_pass(|| Box::new(assertions_on_constants::AssertionsOnConstants));
727 store.register_late_pass(|| Box::new(transmuting_null::TransmutingNull));
728 store.register_late_pass(|| Box::new(path_buf_push_overwrite::PathBufPushOverwrite));
729 store.register_late_pass(|| Box::new(integer_division::IntegerDivision));
730 store.register_late_pass(|| Box::new(inherent_to_string::InherentToString));
731 let max_trait_bounds = conf.max_trait_bounds;
732 store.register_late_pass(move || Box::new(trait_bounds::TraitBounds::new(max_trait_bounds)));
733 store.register_late_pass(|| Box::new(comparison_chain::ComparisonChain));
734 store.register_late_pass(|| Box::new(mut_key::MutableKeyType));
735 store.register_late_pass(|| Box::new(modulo_arithmetic::ModuloArithmetic));
736 store.register_early_pass(|| Box::new(reference::DerefAddrOf));
737 store.register_early_pass(|| Box::new(double_parens::DoubleParens));
738 store.register_late_pass(|| Box::new(format_impl::FormatImpl::new()));
739 store.register_early_pass(|| Box::new(unsafe_removed_from_name::UnsafeNameRemoval));
740 store.register_early_pass(|| Box::new(else_if_without_else::ElseIfWithoutElse));
741 store.register_early_pass(|| Box::new(int_plus_one::IntPlusOne));
742 store.register_early_pass(|| Box::new(formatting::Formatting));
743 store.register_early_pass(|| Box::new(misc_early::MiscEarlyLints));
744 store.register_early_pass(|| Box::new(redundant_closure_call::RedundantClosureCall));
745 store.register_late_pass(|| Box::new(redundant_closure_call::RedundantClosureCall));
746 store.register_early_pass(|| Box::new(unused_unit::UnusedUnit));
747 store.register_late_pass(|| Box::new(returns::Return));
748 store.register_early_pass(|| Box::new(collapsible_if::CollapsibleIf));
749 store.register_early_pass(|| Box::new(items_after_statements::ItemsAfterStatements));
750 store.register_early_pass(|| Box::new(precedence::Precedence));
751 store.register_early_pass(|| Box::new(needless_continue::NeedlessContinue));
752 store.register_early_pass(|| Box::new(redundant_else::RedundantElse));
753 store.register_late_pass(|| Box::new(create_dir::CreateDir));
754 store.register_early_pass(|| Box::new(needless_arbitrary_self_type::NeedlessArbitrarySelfType));
755 let literal_representation_lint_fraction_readability = conf.unreadable_literal_lint_fractions;
756 store.register_early_pass(move || {
757 Box::new(literal_representation::LiteralDigitGrouping::new(
758 literal_representation_lint_fraction_readability,
761 let literal_representation_threshold = conf.literal_representation_threshold;
762 store.register_early_pass(move || {
763 Box::new(literal_representation::DecimalLiteralRepresentation::new(
764 literal_representation_threshold,
767 let enum_variant_name_threshold = conf.enum_variant_name_threshold;
768 store.register_late_pass(move || {
769 Box::new(enum_variants::EnumVariantNames::new(
770 enum_variant_name_threshold,
771 avoid_breaking_exported_api,
774 store.register_early_pass(|| Box::new(tabs_in_doc_comments::TabsInDocComments));
775 let upper_case_acronyms_aggressive = conf.upper_case_acronyms_aggressive;
776 store.register_late_pass(move || {
777 Box::new(upper_case_acronyms::UpperCaseAcronyms::new(
778 avoid_breaking_exported_api,
779 upper_case_acronyms_aggressive,
782 store.register_late_pass(|| Box::new(default::Default::default()));
783 store.register_late_pass(|| Box::new(unused_self::UnusedSelf));
784 store.register_late_pass(|| Box::new(mutable_debug_assertion::DebugAssertWithMutCall));
785 store.register_late_pass(|| Box::new(exit::Exit));
786 store.register_late_pass(|| Box::new(to_digit_is_some::ToDigitIsSome));
787 let array_size_threshold = conf.array_size_threshold;
788 store.register_late_pass(move || Box::new(large_stack_arrays::LargeStackArrays::new(array_size_threshold)));
789 store.register_late_pass(move || Box::new(large_const_arrays::LargeConstArrays::new(array_size_threshold)));
790 store.register_late_pass(|| Box::new(floating_point_arithmetic::FloatingPointArithmetic));
791 store.register_early_pass(|| Box::new(as_conversions::AsConversions));
792 store.register_late_pass(|| Box::new(let_underscore::LetUnderscore));
793 store.register_early_pass(|| Box::new(single_component_path_imports::SingleComponentPathImports));
794 let max_fn_params_bools = conf.max_fn_params_bools;
795 let max_struct_bools = conf.max_struct_bools;
796 store.register_early_pass(move || {
797 Box::new(excessive_bools::ExcessiveBools::new(
802 store.register_early_pass(|| Box::new(option_env_unwrap::OptionEnvUnwrap));
803 let warn_on_all_wildcard_imports = conf.warn_on_all_wildcard_imports;
804 store.register_late_pass(move || Box::new(wildcard_imports::WildcardImports::new(warn_on_all_wildcard_imports)));
805 store.register_late_pass(|| Box::new(verbose_file_reads::VerboseFileReads));
806 store.register_late_pass(|| Box::new(redundant_pub_crate::RedundantPubCrate::default()));
807 store.register_late_pass(|| Box::new(unnamed_address::UnnamedAddress));
808 store.register_late_pass(|| Box::new(dereference::Dereferencing::default()));
809 store.register_late_pass(|| Box::new(option_if_let_else::OptionIfLetElse));
810 store.register_late_pass(|| Box::new(future_not_send::FutureNotSend));
811 store.register_late_pass(|| Box::new(if_let_mutex::IfLetMutex));
812 store.register_late_pass(|| Box::new(if_not_else::IfNotElse));
813 store.register_late_pass(|| Box::new(equatable_if_let::PatternEquality));
814 store.register_late_pass(|| Box::new(mut_mutex_lock::MutMutexLock));
815 store.register_late_pass(|| Box::new(match_on_vec_items::MatchOnVecItems));
816 store.register_late_pass(|| Box::new(manual_async_fn::ManualAsyncFn));
817 store.register_late_pass(|| Box::new(vec_resize_to_zero::VecResizeToZero));
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::new(macro_use::MacroUseImports::default()));
828 store.register_late_pass(|| Box::new(pattern_type_mismatch::PatternTypeMismatch));
829 store.register_late_pass(|| Box::new(stable_sort_primitive::StableSortPrimitive));
830 store.register_late_pass(|| Box::new(repeat_once::RepeatOnce));
831 store.register_late_pass(|| Box::new(unwrap_in_result::UnwrapInResult));
832 store.register_late_pass(|| Box::new(self_assignment::SelfAssignment));
833 store.register_late_pass(|| Box::new(manual_unwrap_or::ManualUnwrapOr));
834 store.register_late_pass(|| Box::new(manual_ok_or::ManualOkOr));
835 store.register_late_pass(|| Box::new(float_equality_without_abs::FloatEqualityWithoutAbs));
836 store.register_late_pass(|| Box::new(semicolon_if_nothing_returned::SemicolonIfNothingReturned));
837 store.register_late_pass(|| Box::new(async_yields_async::AsyncYieldsAsync));
838 let disallowed_methods = conf.disallowed_methods.clone();
839 store.register_late_pass(move || Box::new(disallowed_methods::DisallowedMethods::new(disallowed_methods.clone())));
840 store.register_early_pass(|| Box::new(asm_syntax::InlineAsmX86AttSyntax));
841 store.register_early_pass(|| Box::new(asm_syntax::InlineAsmX86IntelSyntax));
842 store.register_late_pass(|| Box::new(empty_drop::EmptyDrop));
843 store.register_late_pass(|| Box::new(strings::StrToString));
844 store.register_late_pass(|| Box::new(strings::StringToString));
845 store.register_late_pass(|| Box::new(zero_sized_map_values::ZeroSizedMapValues));
846 store.register_late_pass(|| Box::new(vec_init_then_push::VecInitThenPush::default()));
847 store.register_late_pass(|| {
848 Box::new(case_sensitive_file_extension_comparisons::CaseSensitiveFileExtensionComparisons)
850 store.register_late_pass(|| Box::new(redundant_slicing::RedundantSlicing));
851 store.register_late_pass(|| Box::new(from_str_radix_10::FromStrRadix10));
852 store.register_late_pass(|| Box::new(manual_map::ManualMap));
853 store.register_late_pass(move || Box::new(if_then_some_else_none::IfThenSomeElseNone::new(msrv)));
854 store.register_late_pass(|| Box::new(bool_assert_comparison::BoolAssertComparison));
855 store.register_early_pass(move || Box::new(module_style::ModStyle));
856 store.register_late_pass(|| Box::new(unused_async::UnusedAsync));
857 let disallowed_types = conf.disallowed_types.clone();
858 store.register_late_pass(move || Box::new(disallowed_types::DisallowedTypes::new(disallowed_types.clone())));
859 let import_renames = conf.enforced_import_renames.clone();
860 store.register_late_pass(move || {
861 Box::new(missing_enforced_import_rename::ImportRename::new(
862 import_renames.clone(),
865 let scripts = conf.allowed_scripts.clone();
866 store.register_early_pass(move || Box::new(disallowed_script_idents::DisallowedScriptIdents::new(&scripts)));
867 store.register_late_pass(|| Box::new(strlen_on_c_strings::StrlenOnCStrings));
868 store.register_late_pass(move || Box::new(self_named_constructors::SelfNamedConstructors));
869 store.register_late_pass(move || Box::new(iter_not_returning_iterator::IterNotReturningIterator));
870 store.register_late_pass(move || Box::new(manual_assert::ManualAssert));
871 let enable_raw_pointer_heuristic_for_send = conf.enable_raw_pointer_heuristic_for_send;
872 store.register_late_pass(move || {
873 Box::new(non_send_fields_in_send_ty::NonSendFieldInSendTy::new(
874 enable_raw_pointer_heuristic_for_send,
877 store.register_late_pass(move || Box::new(undocumented_unsafe_blocks::UndocumentedUnsafeBlocks));
878 store.register_late_pass(|| Box::new(match_str_case_mismatch::MatchStrCaseMismatch));
879 store.register_late_pass(move || Box::new(format_args::FormatArgs));
880 store.register_late_pass(|| Box::new(trailing_empty_array::TrailingEmptyArray));
881 store.register_early_pass(|| Box::new(octal_escapes::OctalEscapes));
882 store.register_late_pass(|| Box::new(needless_late_init::NeedlessLateInit));
883 store.register_late_pass(|| Box::new(return_self_not_must_use::ReturnSelfNotMustUse));
884 store.register_late_pass(|| Box::new(init_numbered_fields::NumberedFields));
885 store.register_early_pass(|| Box::new(single_char_lifetime_names::SingleCharLifetimeNames));
886 store.register_late_pass(move || Box::new(borrow_as_ptr::BorrowAsPtr::new(msrv)));
887 store.register_late_pass(move || Box::new(manual_bits::ManualBits::new(msrv)));
888 store.register_late_pass(|| Box::new(default_union_representation::DefaultUnionRepresentation));
889 store.register_late_pass(|| Box::new(only_used_in_recursion::OnlyUsedInRecursion));
890 store.register_late_pass(|| Box::new(significant_drop_in_scrutinee::SignificantDropInScrutinee));
891 store.register_late_pass(|| Box::new(dbg_macro::DbgMacro));
892 let cargo_ignore_publish = conf.cargo_ignore_publish;
893 store.register_late_pass(move || {
894 Box::new(cargo::Cargo {
895 ignore_publish: cargo_ignore_publish,
898 store.register_early_pass(|| Box::new(crate_in_macro_def::CrateInMacroDef));
899 store.register_early_pass(|| Box::new(empty_structs_with_brackets::EmptyStructsWithBrackets));
900 store.register_late_pass(|| Box::new(unnecessary_owned_empty_strings::UnnecessaryOwnedEmptyStrings));
901 store.register_early_pass(|| Box::new(pub_use::PubUse));
902 store.register_late_pass(|| Box::new(format_push_string::FormatPushString));
903 store.register_late_pass(|| Box::new(bytes_count_to_len::BytesCountToLen));
904 let max_include_file_size = conf.max_include_file_size;
905 store.register_late_pass(move || Box::new(large_include_file::LargeIncludeFile::new(max_include_file_size)));
906 store.register_late_pass(|| Box::new(strings::TrimSplitWhitespace));
907 store.register_late_pass(|| Box::new(rc_clone_in_vec_init::RcCloneInVecInit));
908 store.register_early_pass(|| Box::new(duplicate_mod::DuplicateMod::default()));
909 // add lints here, do not remove this comment, it's used in `new_lint`
913 fn register_removed_non_tool_lints(store: &mut rustc_lint::LintStore) {
914 store.register_removed(
916 "`assert!()` will be more flexible with RFC 2011",
918 store.register_removed(
920 "`.extend_from_slice(_)` is a faster way to extend a Vec by a slice",
922 store.register_removed(
923 "range_step_by_zero",
924 "`iterator.step_by(0)` panics nowadays",
926 store.register_removed(
928 "`Vec::as_slice` has been stabilized in 1.7",
930 store.register_removed(
931 "unstable_as_mut_slice",
932 "`Vec::as_mut_slice` has been stabilized in 1.7",
934 store.register_removed(
935 "misaligned_transmute",
936 "this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr",
938 store.register_removed(
940 "using compound assignment operators (e.g., `+=`) is harmless",
942 store.register_removed(
943 "if_let_redundant_pattern_matching",
944 "this lint has been changed to redundant_pattern_matching",
946 store.register_removed(
947 "unsafe_vector_initialization",
948 "the replacement suggested by this lint had substantially different behavior",
950 store.register_removed(
951 "reverse_range_loop",
952 "this lint is now included in reversed_empty_ranges",
956 /// Register renamed lints.
958 /// Used in `./src/driver.rs`.
959 pub fn register_renamed(ls: &mut rustc_lint::LintStore) {
960 for (old_name, new_name) in renamed_lints::RENAMED_LINTS {
961 ls.register_renamed(old_name, new_name);
965 // only exists to let the dogfood integration test works.
966 // Don't run clippy as an executable directly
969 panic!("Please use the cargo-clippy executable");