diff --git a/CHANGELOG.md b/CHANGELOG.md index caa488a7a9cc..b3abdc61e639 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 dac6aed61c0e..3e46ba12c446 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 be58e1441849..e99b4ffdb3a0 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 13474127e8d7..03c3c202e0a8 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 d34aadd1d377..b5cb078e7a3c 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 64c43d9acc44..be91630b8fa6 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 a2a10eb91e59..a90eaa8fdcbe 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 caf0c657c81a..a376411bfbc8 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 ed39a05ed5c4..6bfc52fb1bce 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 f38ba02a508f..e5ecfc61947a 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 _ = ::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 c390618ca98b..40052c41039e 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 4a9d6125eb12..2304dff5192b 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