about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEduardo Broto <ebroto@tutanota.com>2020-10-30 23:47:22 +0100
committerEduardo Broto <ebroto@tutanota.com>2020-10-30 23:47:22 +0100
commitf8ac1f99efd996bea2b05c83a915a830d69e1690 (patch)
treec76e0d57df9125c8231b3ac44f5ff98069561d6a
parentd958269fe5afb26ee5026be5bc0cea459593bccf (diff)
downloadrust-f8ac1f99efd996bea2b05c83a915a830d69e1690.tar.gz
rust-f8ac1f99efd996bea2b05c83a915a830d69e1690.zip
Address suggestions in PR review
-rw-r--r--CHANGELOG.md2
-rw-r--r--clippy_lints/src/lib.rs1
-rw-r--r--clippy_lints/src/methods/mod.rs2
-rw-r--r--tests/ui/single_char_add_str.fixed2
-rw-r--r--tests/ui/single_char_add_str.rs2
-rw-r--r--tests/ui/single_char_add_str.stderr14
6 files changed, 20 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 27e861b0d3e..be47eeaa073 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,7 +22,7 @@ Current beta, release 2020-11-19
 * [`map_err_ignore`] [#5998](https://github.com/rust-lang/rust-clippy/pull/5998)
 * [`rc_buffer`] [#6044](https://github.com/rust-lang/rust-clippy/pull/6044)
 * [`to_string_in_display`] [#5831](https://github.com/rust-lang/rust-clippy/pull/5831)
-* [`single_char_push_str`] [#5881](https://github.com/rust-lang/rust-clippy/pull/5881)
+* `single_char_push_str` [#5881](https://github.com/rust-lang/rust-clippy/pull/5881)
 
 ### Moves and Deprecations
 
diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs
index f2056c72c07..9d9097002d6 100644
--- a/clippy_lints/src/lib.rs
+++ b/clippy_lints/src/lib.rs
@@ -1958,6 +1958,7 @@ pub fn register_renamed(ls: &mut rustc_lint::LintStore) {
     ls.register_renamed("clippy::for_loop_over_result", "clippy::for_loops_over_fallibles");
     ls.register_renamed("clippy::identity_conversion", "clippy::useless_conversion");
     ls.register_renamed("clippy::zero_width_space", "clippy::invisible_characters");
+    ls.register_renamed("clippy::single_char_push_str", "clippy::single_char_add_str");
 }
 
 // only exists to let the dogfood integration test works.
diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs
index 89a2db2b76b..558c90249cc 100644
--- a/clippy_lints/src/methods/mod.rs
+++ b/clippy_lints/src/methods/mod.rs
@@ -3266,7 +3266,7 @@ fn lint_single_char_insert_string(cx: &LateContext<'_>, expr: &hir::Expr<'_>, ar
     if let Some(extension_string) = get_hint_if_single_char_arg(cx, &args[2], &mut applicability) {
         let base_string_snippet =
             snippet_with_applicability(cx, args[0].span.source_callsite(), "_", &mut applicability);
-        let pos_arg = snippet(cx, args[1].span, "..");
+        let pos_arg = snippet_with_applicability(cx, args[1].span, "..", &mut applicability);
         let sugg = format!("{}.insert({}, {})", base_string_snippet, pos_arg, extension_string);
         span_lint_and_sugg(
             cx,
diff --git a/tests/ui/single_char_add_str.fixed b/tests/ui/single_char_add_str.fixed
index 2feba4b8069..63a6d37a9cc 100644
--- a/tests/ui/single_char_add_str.fixed
+++ b/tests/ui/single_char_add_str.fixed
@@ -38,6 +38,8 @@ fn main() {
     string.insert(x, 'a');
     const Y: usize = 1;
     string.insert(Y, 'a');
+    string.insert(Y, '"');
+    string.insert(Y, '\'');
 
     get_string!().insert(1, '?');
 }
diff --git a/tests/ui/single_char_add_str.rs b/tests/ui/single_char_add_str.rs
index 681b3d10345..a799ea7d885 100644
--- a/tests/ui/single_char_add_str.rs
+++ b/tests/ui/single_char_add_str.rs
@@ -38,6 +38,8 @@ fn main() {
     string.insert_str(x, r##"a"##);
     const Y: usize = 1;
     string.insert_str(Y, r##"a"##);
+    string.insert_str(Y, r##"""##);
+    string.insert_str(Y, r##"'"##);
 
     get_string!().insert_str(1, "?");
 }
diff --git a/tests/ui/single_char_add_str.stderr b/tests/ui/single_char_add_str.stderr
index 2b17279a564..55d91583ad0 100644
--- a/tests/ui/single_char_add_str.stderr
+++ b/tests/ui/single_char_add_str.stderr
@@ -73,10 +73,22 @@ LL |     string.insert_str(Y, r##"a"##);
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(Y, 'a')`
 
 error: calling `insert_str()` using a single-character string literal
+  --> $DIR/single_char_add_str.rs:41:5
+   |
+LL |     string.insert_str(Y, r##"""##);
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(Y, '"')`
+
+error: calling `insert_str()` using a single-character string literal
   --> $DIR/single_char_add_str.rs:42:5
    |
+LL |     string.insert_str(Y, r##"'"##);
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(Y, '/'')`
+
+error: calling `insert_str()` using a single-character string literal
+  --> $DIR/single_char_add_str.rs:44:5
+   |
 LL |     get_string!().insert_str(1, "?");
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `get_string!().insert(1, '?')`
 
-error: aborting due to 13 previous errors
+error: aborting due to 15 previous errors