Skip to content

Commit 9a1d1b6

Browse files
committed
Move methods lint pass to a new crate part 2
1 parent 54d4034 commit 9a1d1b6

24 files changed

+258
-175
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ path = "src/driver.rs"
2323
[dependencies]
2424
clippy_config = { path = "clippy_config" }
2525
clippy_lints = { path = "clippy_lints" }
26+
clippy_lints_methods = { path = "clippy_lints_methods" }
2627
clippy_utils = { path = "clippy_utils" }
2728
declare_clippy_lint = { path = "declare_clippy_lint" }
2829
rustc_tools_util = { path = "rustc_tools_util", version = "0.4.2" }

clippy_dev/src/release.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::fmt::Write;
44
static CARGO_TOML_FILES: &[&str] = &[
55
"clippy_config/Cargo.toml",
66
"clippy_lints/Cargo.toml",
7+
"clippy_lints_methods/Cargo.toml",
78
"clippy_utils/Cargo.toml",
89
"declare_clippy_lint/Cargo.toml",
910
"Cargo.toml",

clippy_dev/src/serve.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub fn run(port: u16, lint: Option<String>) -> ! {
2222
let index_time = mtime("util/gh-pages/index.html");
2323
let times = [
2424
"clippy_lints/src",
25+
"clippy_lints_methods/src",
2526
"util/gh-pages/index_template.html",
2627
"tests/compile-test.rs",
2728
]

clippy_dev/src/setup/intellij.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ const DEPENDENCIES_SECTION: &str = "[dependencies]";
1414
const CLIPPY_PROJECTS: &[ClippyProjectInfo] = &[
1515
ClippyProjectInfo::new("root", "Cargo.toml", "src/driver.rs"),
1616
ClippyProjectInfo::new("clippy_lints", "clippy_lints/Cargo.toml", "clippy_lints/src/lib.rs"),
17+
ClippyProjectInfo::new(
18+
"clippy_lints_methods",
19+
"clippy_lints_methods/Cargo.toml",
20+
"clippy_lints_methods/src/lib.rs",
21+
),
1722
ClippyProjectInfo::new("clippy_utils", "clippy_utils/Cargo.toml", "clippy_utils/src/lib.rs"),
1823
];
1924

clippy_lints/src/declared_lints.rs

Lines changed: 0 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -349,155 +349,6 @@ pub static LINTS: &[&::declare_clippy_lint::LintInfo] = &[
349349
crate::mem_replace::MEM_REPLACE_OPTION_WITH_SOME_INFO,
350350
crate::mem_replace::MEM_REPLACE_WITH_DEFAULT_INFO,
351351
crate::mem_replace::MEM_REPLACE_WITH_UNINIT_INFO,
352-
crate::methods::BIND_INSTEAD_OF_MAP_INFO,
353-
crate::methods::BYTES_COUNT_TO_LEN_INFO,
354-
crate::methods::BYTES_NTH_INFO,
355-
crate::methods::CASE_SENSITIVE_FILE_EXTENSION_COMPARISONS_INFO,
356-
crate::methods::CHARS_LAST_CMP_INFO,
357-
crate::methods::CHARS_NEXT_CMP_INFO,
358-
crate::methods::CLEAR_WITH_DRAIN_INFO,
359-
crate::methods::CLONE_ON_COPY_INFO,
360-
crate::methods::CLONE_ON_REF_PTR_INFO,
361-
crate::methods::CLONED_INSTEAD_OF_COPIED_INFO,
362-
crate::methods::COLLAPSIBLE_STR_REPLACE_INFO,
363-
crate::methods::CONST_IS_EMPTY_INFO,
364-
crate::methods::DOUBLE_ENDED_ITERATOR_LAST_INFO,
365-
crate::methods::DRAIN_COLLECT_INFO,
366-
crate::methods::ERR_EXPECT_INFO,
367-
crate::methods::EXPECT_FUN_CALL_INFO,
368-
crate::methods::EXPECT_USED_INFO,
369-
crate::methods::EXTEND_WITH_DRAIN_INFO,
370-
crate::methods::FILETYPE_IS_FILE_INFO,
371-
crate::methods::FILTER_MAP_BOOL_THEN_INFO,
372-
crate::methods::FILTER_MAP_IDENTITY_INFO,
373-
crate::methods::FILTER_MAP_NEXT_INFO,
374-
crate::methods::FILTER_NEXT_INFO,
375-
crate::methods::FLAT_MAP_IDENTITY_INFO,
376-
crate::methods::FLAT_MAP_OPTION_INFO,
377-
crate::methods::FORMAT_COLLECT_INFO,
378-
crate::methods::FROM_ITER_INSTEAD_OF_COLLECT_INFO,
379-
crate::methods::GET_FIRST_INFO,
380-
crate::methods::GET_LAST_WITH_LEN_INFO,
381-
crate::methods::GET_UNWRAP_INFO,
382-
crate::methods::IMPLICIT_CLONE_INFO,
383-
crate::methods::INEFFICIENT_TO_STRING_INFO,
384-
crate::methods::INSPECT_FOR_EACH_INFO,
385-
crate::methods::INTO_ITER_ON_REF_INFO,
386-
crate::methods::IO_OTHER_ERROR_INFO,
387-
crate::methods::IP_CONSTANT_INFO,
388-
crate::methods::IS_DIGIT_ASCII_RADIX_INFO,
389-
crate::methods::ITER_CLONED_COLLECT_INFO,
390-
crate::methods::ITER_COUNT_INFO,
391-
crate::methods::ITER_FILTER_IS_OK_INFO,
392-
crate::methods::ITER_FILTER_IS_SOME_INFO,
393-
crate::methods::ITER_KV_MAP_INFO,
394-
crate::methods::ITER_NEXT_SLICE_INFO,
395-
crate::methods::ITER_NTH_INFO,
396-
crate::methods::ITER_NTH_ZERO_INFO,
397-
crate::methods::ITER_ON_EMPTY_COLLECTIONS_INFO,
398-
crate::methods::ITER_ON_SINGLE_ITEMS_INFO,
399-
crate::methods::ITER_OUT_OF_BOUNDS_INFO,
400-
crate::methods::ITER_OVEREAGER_CLONED_INFO,
401-
crate::methods::ITER_SKIP_NEXT_INFO,
402-
crate::methods::ITER_SKIP_ZERO_INFO,
403-
crate::methods::ITER_WITH_DRAIN_INFO,
404-
crate::methods::ITERATOR_STEP_BY_ZERO_INFO,
405-
crate::methods::JOIN_ABSOLUTE_PATHS_INFO,
406-
crate::methods::MANUAL_C_STR_LITERALS_INFO,
407-
crate::methods::MANUAL_CONTAINS_INFO,
408-
crate::methods::MANUAL_FILTER_MAP_INFO,
409-
crate::methods::MANUAL_FIND_MAP_INFO,
410-
crate::methods::MANUAL_INSPECT_INFO,
411-
crate::methods::MANUAL_IS_VARIANT_AND_INFO,
412-
crate::methods::MANUAL_NEXT_BACK_INFO,
413-
crate::methods::MANUAL_OK_OR_INFO,
414-
crate::methods::MANUAL_REPEAT_N_INFO,
415-
crate::methods::MANUAL_SATURATING_ARITHMETIC_INFO,
416-
crate::methods::MANUAL_SPLIT_ONCE_INFO,
417-
crate::methods::MANUAL_STR_REPEAT_INFO,
418-
crate::methods::MANUAL_TRY_FOLD_INFO,
419-
crate::methods::MAP_ALL_ANY_IDENTITY_INFO,
420-
crate::methods::MAP_CLONE_INFO,
421-
crate::methods::MAP_COLLECT_RESULT_UNIT_INFO,
422-
crate::methods::MAP_ERR_IGNORE_INFO,
423-
crate::methods::MAP_FLATTEN_INFO,
424-
crate::methods::MAP_IDENTITY_INFO,
425-
crate::methods::MAP_UNWRAP_OR_INFO,
426-
crate::methods::MAP_WITH_UNUSED_ARGUMENT_OVER_RANGES_INFO,
427-
crate::methods::MUT_MUTEX_LOCK_INFO,
428-
crate::methods::NAIVE_BYTECOUNT_INFO,
429-
crate::methods::NEEDLESS_AS_BYTES_INFO,
430-
crate::methods::NEEDLESS_CHARACTER_ITERATION_INFO,
431-
crate::methods::NEEDLESS_COLLECT_INFO,
432-
crate::methods::NEEDLESS_OPTION_AS_DEREF_INFO,
433-
crate::methods::NEEDLESS_OPTION_TAKE_INFO,
434-
crate::methods::NEEDLESS_SPLITN_INFO,
435-
crate::methods::NEW_RET_NO_SELF_INFO,
436-
crate::methods::NO_EFFECT_REPLACE_INFO,
437-
crate::methods::NONSENSICAL_OPEN_OPTIONS_INFO,
438-
crate::methods::OBFUSCATED_IF_ELSE_INFO,
439-
crate::methods::OK_EXPECT_INFO,
440-
crate::methods::OPTION_AS_REF_CLONED_INFO,
441-
crate::methods::OPTION_AS_REF_DEREF_INFO,
442-
crate::methods::OPTION_FILTER_MAP_INFO,
443-
crate::methods::OPTION_MAP_OR_NONE_INFO,
444-
crate::methods::OR_FUN_CALL_INFO,
445-
crate::methods::OR_THEN_UNWRAP_INFO,
446-
crate::methods::PATH_BUF_PUSH_OVERWRITE_INFO,
447-
crate::methods::PATH_ENDS_WITH_EXT_INFO,
448-
crate::methods::RANGE_ZIP_WITH_LEN_INFO,
449-
crate::methods::READ_LINE_WITHOUT_TRIM_INFO,
450-
crate::methods::READONLY_WRITE_LOCK_INFO,
451-
crate::methods::REDUNDANT_AS_STR_INFO,
452-
crate::methods::REDUNDANT_ITER_CLONED_INFO,
453-
crate::methods::REPEAT_ONCE_INFO,
454-
crate::methods::RESULT_FILTER_MAP_INFO,
455-
crate::methods::RESULT_MAP_OR_INTO_OPTION_INFO,
456-
crate::methods::RETURN_AND_THEN_INFO,
457-
crate::methods::SEARCH_IS_SOME_INFO,
458-
crate::methods::SEEK_FROM_CURRENT_INFO,
459-
crate::methods::SEEK_TO_START_INSTEAD_OF_REWIND_INFO,
460-
crate::methods::SHOULD_IMPLEMENT_TRAIT_INFO,
461-
crate::methods::SINGLE_CHAR_ADD_STR_INFO,
462-
crate::methods::SKIP_WHILE_NEXT_INFO,
463-
crate::methods::SLICED_STRING_AS_BYTES_INFO,
464-
crate::methods::STABLE_SORT_PRIMITIVE_INFO,
465-
crate::methods::STR_SPLIT_AT_NEWLINE_INFO,
466-
crate::methods::STRING_EXTEND_CHARS_INFO,
467-
crate::methods::STRING_LIT_CHARS_ANY_INFO,
468-
crate::methods::SUSPICIOUS_COMMAND_ARG_SPACE_INFO,
469-
crate::methods::SUSPICIOUS_MAP_INFO,
470-
crate::methods::SUSPICIOUS_OPEN_OPTIONS_INFO,
471-
crate::methods::SUSPICIOUS_SPLITN_INFO,
472-
crate::methods::SUSPICIOUS_TO_OWNED_INFO,
473-
crate::methods::SWAP_WITH_TEMPORARY_INFO,
474-
crate::methods::TYPE_ID_ON_BOX_INFO,
475-
crate::methods::UNBUFFERED_BYTES_INFO,
476-
crate::methods::UNINIT_ASSUMED_INIT_INFO,
477-
crate::methods::UNIT_HASH_INFO,
478-
crate::methods::UNNECESSARY_FALLIBLE_CONVERSIONS_INFO,
479-
crate::methods::UNNECESSARY_FILTER_MAP_INFO,
480-
crate::methods::UNNECESSARY_FIND_MAP_INFO,
481-
crate::methods::UNNECESSARY_FIRST_THEN_CHECK_INFO,
482-
crate::methods::UNNECESSARY_FOLD_INFO,
483-
crate::methods::UNNECESSARY_GET_THEN_CHECK_INFO,
484-
crate::methods::UNNECESSARY_JOIN_INFO,
485-
crate::methods::UNNECESSARY_LAZY_EVALUATIONS_INFO,
486-
crate::methods::UNNECESSARY_LITERAL_UNWRAP_INFO,
487-
crate::methods::UNNECESSARY_MAP_OR_INFO,
488-
crate::methods::UNNECESSARY_MIN_OR_MAX_INFO,
489-
crate::methods::UNNECESSARY_RESULT_MAP_OR_ELSE_INFO,
490-
crate::methods::UNNECESSARY_SORT_BY_INFO,
491-
crate::methods::UNNECESSARY_TO_OWNED_INFO,
492-
crate::methods::UNWRAP_OR_DEFAULT_INFO,
493-
crate::methods::UNWRAP_USED_INFO,
494-
crate::methods::USELESS_ASREF_INFO,
495-
crate::methods::USELESS_NONZERO_NEW_UNCHECKED_INFO,
496-
crate::methods::VEC_RESIZE_TO_ZERO_INFO,
497-
crate::methods::VERBOSE_FILE_READS_INFO,
498-
crate::methods::WAKER_CLONE_WAKE_INFO,
499-
crate::methods::WRONG_SELF_CONVENTION_INFO,
500-
crate::methods::ZST_OFFSET_INFO,
501352
crate::min_ident_chars::MIN_IDENT_CHARS_INFO,
502353
crate::minmax::MIN_MAX_INFO,
503354
crate::misc::SHORT_CIRCUIT_STATEMENT_INFO,

clippy_lints/src/lib.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ extern crate rustc_session;
5555
extern crate rustc_span;
5656
extern crate rustc_target;
5757
extern crate rustc_trait_selection;
58-
extern crate smallvec;
5958
extern crate thin_vec;
6059

6160
#[macro_use]
@@ -231,7 +230,6 @@ mod map_unit_fn;
231230
mod match_result_ok;
232231
mod matches;
233232
mod mem_replace;
234-
mod methods;
235233
mod min_ident_chars;
236234
mod minmax;
237235
mod misc;
@@ -440,7 +438,7 @@ pub fn explain(name: &str) -> i32 {
440438
///
441439
/// Used in `./src/driver.rs`.
442440
#[expect(clippy::too_many_lines)]
443-
pub fn register_lint_passes(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
441+
pub fn register_lint_passes(store: &mut rustc_lint::LintStore, conf: &'static Conf) -> FormatArgsStorage {
444442
for (old_name, new_name) in deprecated_lints::RENAMED {
445443
store.register_renamed(old_name, new_name);
446444
}
@@ -503,8 +501,6 @@ pub fn register_lint_passes(store: &mut rustc_lint::LintStore, conf: &'static Co
503501
store.register_late_pass(|_| Box::new(non_octal_unix_permissions::NonOctalUnixPermissions));
504502
store.register_early_pass(|| Box::new(unnecessary_self_imports::UnnecessarySelfImports));
505503
store.register_late_pass(move |_| Box::new(approx_const::ApproxConstant::new(conf)));
506-
let format_args = format_args_storage.clone();
507-
store.register_late_pass(move |_| Box::new(methods::Methods::new(conf, format_args.clone())));
508504
store.register_late_pass(move |_| Box::new(matches::Matches::new(conf)));
509505
store.register_late_pass(move |_| Box::new(manual_non_exhaustive::ManualNonExhaustive::new(conf)));
510506
store.register_late_pass(move |_| Box::new(manual_strip::ManualStrip::new(conf)));
@@ -831,4 +827,6 @@ pub fn register_lint_passes(store: &mut rustc_lint::LintStore, conf: &'static Co
831827
store.register_late_pass(|_| Box::new(infallible_try_from::InfallibleTryFrom));
832828
store.register_late_pass(|_| Box::new(coerce_container_to_any::CoerceContainerToAny));
833829
// add lints here, do not remove this comment, it's used in `new_lint`
830+
831+
format_args_storage
834832
}

clippy_lints_methods/Cargo.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "clippy_lints_methods"
3+
version = "0.1.90"
4+
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
5+
repository = "https://github.com/rust-lang/rust-clippy"
6+
readme = "README.md"
7+
license = "MIT OR Apache-2.0"
8+
keywords = ["clippy", "lint", "plugin"]
9+
edition = "2024"
10+
11+
[dependencies]
12+
clippy_config = { path = "../clippy_config" }
13+
clippy_utils = { path = "../clippy_utils" }
14+
declare_clippy_lint = { path = "../declare_clippy_lint" }
15+
itertools = "0.12"
16+
17+
[package.metadata.rust-analyzer]
18+
# This crate uses #[feature(rustc_private)]
19+
rustc_private = true

clippy_lints_methods/src/bytes_nth.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_errors::Applicability;
66
use rustc_hir::{Expr, LangItem};
77
use rustc_lint::LateContext;
88

9-
use crate::methods::method_call;
9+
use crate::method_call;
1010

1111
use super::BYTES_NTH;
1212

clippy_lints_methods/src/chars_cmp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_span::Symbol;
1010
/// Wrapper fn for `CHARS_NEXT_CMP` and `CHARS_LAST_CMP` lints.
1111
pub(super) fn check(
1212
cx: &LateContext<'_>,
13-
info: &crate::methods::BinaryExprInfo<'_>,
13+
info: &crate::BinaryExprInfo<'_>,
1414
chain_methods: &[Symbol],
1515
lint: &'static Lint,
1616
suggest: &str,

clippy_lints_methods/src/chars_cmp_with_unwrap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_span::Symbol;
1010
/// Wrapper fn for `CHARS_NEXT_CMP` and `CHARS_LAST_CMP` lints with `unwrap()`.
1111
pub(super) fn check(
1212
cx: &LateContext<'_>,
13-
info: &crate::methods::BinaryExprInfo<'_>,
13+
info: &crate::BinaryExprInfo<'_>,
1414
chain_methods: &[Symbol],
1515
lint: &'static Lint,
1616
suggest: &str,

0 commit comments

Comments
 (0)