Skip to content

Commit

Permalink
Address suggestions in PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
ebroto committed Oct 30, 2020
1 parent d958269 commit f8ac1f9
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/single_char_add_str.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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, '?');
}
2 changes: 2 additions & 0 deletions tests/ui/single_char_add_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, "?");
}
14 changes: 13 additions & 1 deletion tests/ui/single_char_add_str.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,23 @@ error: calling `insert_str()` using a single-character string literal
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

0 comments on commit f8ac1f9

Please sign in to comment.