From 2cb5318e97f7083f397c45664f3808e2601fbe78 Mon Sep 17 00:00:00 2001 From: Alex Macleod <alex@macleod.io> Date: Tue, 23 Aug 2022 14:17:30 +0000 Subject: [PATCH] Rename `manual_empty_string_creation` and move to pedantic --- CHANGELOG.md | 2 +- clippy_lints/src/lib.register_all.rs | 1 - clippy_lints/src/lib.register_lints.rs | 2 +- clippy_lints/src/lib.register_pedantic.rs | 1 + clippy_lints/src/lib.register_style.rs | 1 - clippy_lints/src/lib.rs | 4 ++-- ...ring_creations.rs => manual_string_new.rs} | 11 +++++----- ...reations.fixed => manual_string_new.fixed} | 2 +- ...ring_creations.rs => manual_string_new.rs} | 2 +- ...ations.stderr => manual_string_new.stderr} | 20 +++++++++---------- .../ui/unnecessary_owned_empty_strings.fixed | 2 +- tests/ui/unnecessary_owned_empty_strings.rs | 2 +- 12 files changed, 24 insertions(+), 26 deletions(-) rename clippy_lints/src/{manual_empty_string_creations.rs => manual_string_new.rs} (93%) rename tests/ui/{manual_empty_string_creations.fixed => manual_string_new.fixed} (97%) rename tests/ui/{manual_empty_string_creations.rs => manual_string_new.rs} (97%) rename tests/ui/{manual_empty_string_creations.stderr => manual_string_new.stderr} (75%) diff --git a/CHANGELOG.md b/CHANGELOG.md index caa488a7a9c..b3abdc61e63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3831,7 +3831,6 @@ Released 2018-09-13 [`manual_assert`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_assert [`manual_async_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_async_fn [`manual_bits`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_bits -[`manual_empty_string_creations`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_empty_string_creations [`manual_filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_filter_map [`manual_find`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_find [`manual_find_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_find_map @@ -3847,6 +3846,7 @@ Released 2018-09-13 [`manual_saturating_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_saturating_arithmetic [`manual_split_once`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_split_once [`manual_str_repeat`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_str_repeat +[`manual_string_new`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_string_new [`manual_strip`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_strip [`manual_swap`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_swap [`manual_unwrap_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_unwrap_or diff --git a/clippy_lints/src/lib.register_all.rs b/clippy_lints/src/lib.register_all.rs index dac6aed61c0..3e46ba12c44 100644 --- a/clippy_lints/src/lib.register_all.rs +++ b/clippy_lints/src/lib.register_all.rs @@ -122,7 +122,6 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![ LintId::of(main_recursion::MAIN_RECURSION), LintId::of(manual_async_fn::MANUAL_ASYNC_FN), LintId::of(manual_bits::MANUAL_BITS), - LintId::of(manual_empty_string_creations::MANUAL_EMPTY_STRING_CREATIONS), LintId::of(manual_non_exhaustive::MANUAL_NON_EXHAUSTIVE), LintId::of(manual_rem_euclid::MANUAL_REM_EUCLID), LintId::of(manual_retain::MANUAL_RETAIN), diff --git a/clippy_lints/src/lib.register_lints.rs b/clippy_lints/src/lib.register_lints.rs index be58e144184..e99b4ffdb3a 100644 --- a/clippy_lints/src/lib.register_lints.rs +++ b/clippy_lints/src/lib.register_lints.rs @@ -240,11 +240,11 @@ store.register_lints(&[ manual_assert::MANUAL_ASSERT, manual_async_fn::MANUAL_ASYNC_FN, manual_bits::MANUAL_BITS, - manual_empty_string_creations::MANUAL_EMPTY_STRING_CREATIONS, manual_instant_elapsed::MANUAL_INSTANT_ELAPSED, manual_non_exhaustive::MANUAL_NON_EXHAUSTIVE, manual_rem_euclid::MANUAL_REM_EUCLID, manual_retain::MANUAL_RETAIN, + manual_string_new::MANUAL_STRING_NEW, manual_strip::MANUAL_STRIP, map_unit_fn::OPTION_MAP_UNIT_FN, map_unit_fn::RESULT_MAP_UNIT_FN, diff --git a/clippy_lints/src/lib.register_pedantic.rs b/clippy_lints/src/lib.register_pedantic.rs index 13474127e8d..03c3c202e0a 100644 --- a/clippy_lints/src/lib.register_pedantic.rs +++ b/clippy_lints/src/lib.register_pedantic.rs @@ -48,6 +48,7 @@ store.register_group(true, "clippy::pedantic", Some("clippy_pedantic"), vec![ LintId::of(macro_use::MACRO_USE_IMPORTS), LintId::of(manual_assert::MANUAL_ASSERT), LintId::of(manual_instant_elapsed::MANUAL_INSTANT_ELAPSED), + LintId::of(manual_string_new::MANUAL_STRING_NEW), LintId::of(matches::MATCH_BOOL), LintId::of(matches::MATCH_ON_VEC_ITEMS), LintId::of(matches::MATCH_SAME_ARMS), diff --git a/clippy_lints/src/lib.register_style.rs b/clippy_lints/src/lib.register_style.rs index d34aadd1d37..b5cb078e7a3 100644 --- a/clippy_lints/src/lib.register_style.rs +++ b/clippy_lints/src/lib.register_style.rs @@ -43,7 +43,6 @@ store.register_group(true, "clippy::style", Some("clippy_style"), vec![ LintId::of(main_recursion::MAIN_RECURSION), LintId::of(manual_async_fn::MANUAL_ASYNC_FN), LintId::of(manual_bits::MANUAL_BITS), - LintId::of(manual_empty_string_creations::MANUAL_EMPTY_STRING_CREATIONS), LintId::of(manual_non_exhaustive::MANUAL_NON_EXHAUSTIVE), LintId::of(match_result_ok::MATCH_RESULT_OK), LintId::of(matches::COLLAPSIBLE_MATCH), diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 64c43d9acc4..be91630b8fa 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -267,11 +267,11 @@ mod main_recursion; mod manual_assert; mod manual_async_fn; mod manual_bits; -mod manual_empty_string_creations; mod manual_instant_elapsed; mod manual_non_exhaustive; mod manual_rem_euclid; mod manual_retain; +mod manual_string_new; mod manual_strip; mod map_unit_fn; mod match_result_ok; @@ -894,7 +894,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: store.register_late_pass(|| Box::new(std_instead_of_core::StdReexports::default())); store.register_late_pass(|| Box::new(manual_instant_elapsed::ManualInstantElapsed)); store.register_late_pass(|| Box::new(partialeq_to_none::PartialeqToNone)); - store.register_late_pass(|| Box::new(manual_empty_string_creations::ManualEmptyStringCreations)); + store.register_late_pass(|| Box::new(manual_string_new::ManualStringNew)); store.register_late_pass(|| Box::new(unused_peekable::UnusedPeekable)); // add lints here, do not remove this comment, it's used in `new_lint` } diff --git a/clippy_lints/src/manual_empty_string_creations.rs b/clippy_lints/src/manual_string_new.rs similarity index 93% rename from clippy_lints/src/manual_empty_string_creations.rs rename to clippy_lints/src/manual_string_new.rs index a2a10eb91e5..a90eaa8fdcb 100644 --- a/clippy_lints/src/manual_empty_string_creations.rs +++ b/clippy_lints/src/manual_string_new.rs @@ -29,13 +29,13 @@ declare_clippy_lint! { /// let b = String::new(); /// ``` #[clippy::version = "1.65.0"] - pub MANUAL_EMPTY_STRING_CREATIONS, - style, + pub MANUAL_STRING_NEW, + pedantic, "empty String is being created manually" } -declare_lint_pass!(ManualEmptyStringCreations => [MANUAL_EMPTY_STRING_CREATIONS]); +declare_lint_pass!(ManualStringNew => [MANUAL_STRING_NEW]); -impl LateLintPass<'_> for ManualEmptyStringCreations { +impl LateLintPass<'_> for ManualStringNew { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { if expr.span.from_expansion() { return; @@ -75,11 +75,10 @@ fn is_expr_kind_empty_str(expr_kind: &ExprKind<'_>) -> bool { false } -/// Emits the `MANUAL_EMPTY_STRING_CREATION` warning and suggests the appropriate fix. fn warn_then_suggest(cx: &LateContext<'_>, span: Span) { span_lint_and_sugg( cx, - MANUAL_EMPTY_STRING_CREATIONS, + MANUAL_STRING_NEW, span, "empty String is being created manually", "consider using", diff --git a/tests/ui/manual_empty_string_creations.fixed b/tests/ui/manual_string_new.fixed similarity index 97% rename from tests/ui/manual_empty_string_creations.fixed rename to tests/ui/manual_string_new.fixed index caf0c657c81..a376411bfbc 100644 --- a/tests/ui/manual_empty_string_creations.fixed +++ b/tests/ui/manual_string_new.fixed @@ -1,6 +1,6 @@ // run-rustfix -#![warn(clippy::manual_empty_string_creations)] +#![warn(clippy::manual_string_new)] macro_rules! create_strings_from_macro { // When inside a macro, nothing should warn to prevent false positives. diff --git a/tests/ui/manual_empty_string_creations.rs b/tests/ui/manual_string_new.rs similarity index 97% rename from tests/ui/manual_empty_string_creations.rs rename to tests/ui/manual_string_new.rs index ed39a05ed5c..6bfc52fb1bc 100644 --- a/tests/ui/manual_empty_string_creations.rs +++ b/tests/ui/manual_string_new.rs @@ -1,6 +1,6 @@ // run-rustfix -#![warn(clippy::manual_empty_string_creations)] +#![warn(clippy::manual_string_new)] macro_rules! create_strings_from_macro { // When inside a macro, nothing should warn to prevent false positives. diff --git a/tests/ui/manual_empty_string_creations.stderr b/tests/ui/manual_string_new.stderr similarity index 75% rename from tests/ui/manual_empty_string_creations.stderr rename to tests/ui/manual_string_new.stderr index f38ba02a508..e5ecfc61947 100644 --- a/tests/ui/manual_empty_string_creations.stderr +++ b/tests/ui/manual_string_new.stderr @@ -1,55 +1,55 @@ error: empty String is being created manually - --> $DIR/manual_empty_string_creations.rs:15:13 + --> $DIR/manual_string_new.rs:15:13 | LL | let _ = "".to_string(); | ^^^^^^^^^^^^^^ help: consider using: `String::new()` | - = note: `-D clippy::manual-empty-string-creations` implied by `-D warnings` + = note: `-D clippy::manual-string-new` implied by `-D warnings` error: empty String is being created manually - --> $DIR/manual_empty_string_creations.rs:18:13 + --> $DIR/manual_string_new.rs:18:13 | LL | let _ = "".to_owned(); | ^^^^^^^^^^^^^ help: consider using: `String::new()` error: empty String is being created manually - --> $DIR/manual_empty_string_creations.rs:21:21 + --> $DIR/manual_string_new.rs:21:21 | LL | let _: String = "".into(); | ^^^^^^^^^ help: consider using: `String::new()` error: empty String is being created manually - --> $DIR/manual_empty_string_creations.rs:28:13 + --> $DIR/manual_string_new.rs:28:13 | LL | let _ = String::from(""); | ^^^^^^^^^^^^^^^^ help: consider using: `String::new()` error: empty String is being created manually - --> $DIR/manual_empty_string_creations.rs:29:13 + --> $DIR/manual_string_new.rs:29:13 | LL | let _ = <String>::from(""); | ^^^^^^^^^^^^^^^^^^ help: consider using: `String::new()` error: empty String is being created manually - --> $DIR/manual_empty_string_creations.rs:34:13 + --> $DIR/manual_string_new.rs:34:13 | LL | let _ = String::try_from("").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `String::new()` error: empty String is being created manually - --> $DIR/manual_empty_string_creations.rs:40:21 + --> $DIR/manual_string_new.rs:40:21 | LL | let _: String = From::from(""); | ^^^^^^^^^^^^^^ help: consider using: `String::new()` error: empty String is being created manually - --> $DIR/manual_empty_string_creations.rs:45:21 + --> $DIR/manual_string_new.rs:45:21 | LL | let _: String = TryFrom::try_from("").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `String::new()` error: empty String is being created manually - --> $DIR/manual_empty_string_creations.rs:48:21 + --> $DIR/manual_string_new.rs:48:21 | LL | let _: String = TryFrom::try_from("").expect("this should warn"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `String::new()` diff --git a/tests/ui/unnecessary_owned_empty_strings.fixed b/tests/ui/unnecessary_owned_empty_strings.fixed index c390618ca98..40052c41039 100644 --- a/tests/ui/unnecessary_owned_empty_strings.fixed +++ b/tests/ui/unnecessary_owned_empty_strings.fixed @@ -12,7 +12,7 @@ fn main() { ref_str_argument(""); // should be linted - #[allow(clippy::manual_empty_string_creations)] + #[allow(clippy::manual_string_new)] ref_str_argument(""); // should not be linted diff --git a/tests/ui/unnecessary_owned_empty_strings.rs b/tests/ui/unnecessary_owned_empty_strings.rs index 4a9d6125eb1..2304dff5192 100644 --- a/tests/ui/unnecessary_owned_empty_strings.rs +++ b/tests/ui/unnecessary_owned_empty_strings.rs @@ -12,7 +12,7 @@ fn main() { ref_str_argument(&String::new()); // should be linted - #[allow(clippy::manual_empty_string_creations)] + #[allow(clippy::manual_string_new)] ref_str_argument(&String::from("")); // should not be linted