Skip to content

Rename manual_empty_string_creation and move to pedantic #9366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion clippy_lints/src/lib.register_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/lib.register_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions clippy_lints/src/lib.register_pedantic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
1 change: 0 additions & 1 deletion clippy_lints/src/lib.register_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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()`
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/unnecessary_owned_empty_strings.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/unnecessary_owned_empty_strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down