mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-02-17 06:28:42 +00:00
Rename single_char_push_str to single_char_add_str
This commit is contained in:
parent
c1eb8ceede
commit
d958269fe5
14 changed files with 166 additions and 192 deletions
|
@ -1939,8 +1939,8 @@ Released 2018-09-13
|
|||
[`should_assert_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#should_assert_eq
|
||||
[`should_implement_trait`]: https://rust-lang.github.io/rust-clippy/master/index.html#should_implement_trait
|
||||
[`similar_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#similar_names
|
||||
[`single_char_add_str`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_char_add_str
|
||||
[`single_char_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_char_pattern
|
||||
[`single_char_push_str`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_char_push_str
|
||||
[`single_component_path_imports`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_component_path_imports
|
||||
[`single_element_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_element_loop
|
||||
[`single_match`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_match
|
||||
|
|
|
@ -713,8 +713,8 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||
&methods::RESULT_MAP_OR_INTO_OPTION,
|
||||
&methods::SEARCH_IS_SOME,
|
||||
&methods::SHOULD_IMPLEMENT_TRAIT,
|
||||
&methods::SINGLE_CHAR_ADD_STR,
|
||||
&methods::SINGLE_CHAR_PATTERN,
|
||||
&methods::SINGLE_CHAR_PUSH_STR,
|
||||
&methods::SKIP_WHILE_NEXT,
|
||||
&methods::STRING_EXTEND_CHARS,
|
||||
&methods::SUSPICIOUS_MAP,
|
||||
|
@ -1438,8 +1438,8 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||
LintId::of(&methods::RESULT_MAP_OR_INTO_OPTION),
|
||||
LintId::of(&methods::SEARCH_IS_SOME),
|
||||
LintId::of(&methods::SHOULD_IMPLEMENT_TRAIT),
|
||||
LintId::of(&methods::SINGLE_CHAR_ADD_STR),
|
||||
LintId::of(&methods::SINGLE_CHAR_PATTERN),
|
||||
LintId::of(&methods::SINGLE_CHAR_PUSH_STR),
|
||||
LintId::of(&methods::SKIP_WHILE_NEXT),
|
||||
LintId::of(&methods::STRING_EXTEND_CHARS),
|
||||
LintId::of(&methods::SUSPICIOUS_MAP),
|
||||
|
@ -1631,7 +1631,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||
LintId::of(&methods::OPTION_MAP_OR_NONE),
|
||||
LintId::of(&methods::RESULT_MAP_OR_INTO_OPTION),
|
||||
LintId::of(&methods::SHOULD_IMPLEMENT_TRAIT),
|
||||
LintId::of(&methods::SINGLE_CHAR_PUSH_STR),
|
||||
LintId::of(&methods::SINGLE_CHAR_ADD_STR),
|
||||
LintId::of(&methods::STRING_EXTEND_CHARS),
|
||||
LintId::of(&methods::UNNECESSARY_FOLD),
|
||||
LintId::of(&methods::UNNECESSARY_LAZY_EVALUATIONS),
|
||||
|
|
|
@ -1290,8 +1290,8 @@ declare_clippy_lint! {
|
|||
}
|
||||
|
||||
declare_clippy_lint! {
|
||||
/// **What it does:** Warns when using `push_str` with a single-character string literal
|
||||
/// where `push` with a `char` would work fine.
|
||||
/// **What it does:** Warns when using `push_str`/`insert_str` with a single-character string literal
|
||||
/// where `push`/`insert` with a `char` would work fine.
|
||||
///
|
||||
/// **Why is this bad?** It's less clear that we are pushing a single character.
|
||||
///
|
||||
|
@ -1300,16 +1300,18 @@ declare_clippy_lint! {
|
|||
/// **Example:**
|
||||
/// ```rust
|
||||
/// let mut string = String::new();
|
||||
/// string.insert_str(0, "R");
|
||||
/// string.push_str("R");
|
||||
/// ```
|
||||
/// Could be written as
|
||||
/// ```rust
|
||||
/// let mut string = String::new();
|
||||
/// string.insert(0, 'R');
|
||||
/// string.push('R');
|
||||
/// ```
|
||||
pub SINGLE_CHAR_PUSH_STR,
|
||||
pub SINGLE_CHAR_ADD_STR,
|
||||
style,
|
||||
"`push_str()` used with a single-character string literal as parameter"
|
||||
"`push_str()` or `insert_str()` used with a single-character string literal as parameter"
|
||||
}
|
||||
|
||||
declare_clippy_lint! {
|
||||
|
@ -1390,7 +1392,7 @@ declare_lint_pass!(Methods => [
|
|||
INEFFICIENT_TO_STRING,
|
||||
NEW_RET_NO_SELF,
|
||||
SINGLE_CHAR_PATTERN,
|
||||
SINGLE_CHAR_PUSH_STR,
|
||||
SINGLE_CHAR_ADD_STR,
|
||||
SEARCH_IS_SOME,
|
||||
FILTER_NEXT,
|
||||
SKIP_WHILE_NEXT,
|
||||
|
@ -3248,7 +3250,7 @@ fn lint_single_char_push_string(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args
|
|||
let sugg = format!("{}.push({})", base_string_snippet, extension_string);
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
SINGLE_CHAR_PUSH_STR,
|
||||
SINGLE_CHAR_ADD_STR,
|
||||
expr.span,
|
||||
"calling `push_str()` using a single-character string literal",
|
||||
"consider using `push` with a character literal",
|
||||
|
@ -3268,7 +3270,7 @@ fn lint_single_char_insert_string(cx: &LateContext<'_>, expr: &hir::Expr<'_>, ar
|
|||
let sugg = format!("{}.insert({}, {})", base_string_snippet, pos_arg, extension_string);
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
SINGLE_CHAR_PUSH_STR,
|
||||
SINGLE_CHAR_ADD_STR,
|
||||
expr.span,
|
||||
"calling `insert_str()` using a single-character string literal",
|
||||
"consider using `insert` with a character literal",
|
||||
|
|
|
@ -2147,16 +2147,16 @@ vec![
|
|||
module: "non_expressive_names",
|
||||
},
|
||||
Lint {
|
||||
name: "single_char_pattern",
|
||||
group: "perf",
|
||||
desc: "using a single-character str where a char could be used, e.g., `_.split(\"x\")`",
|
||||
name: "single_char_add_str",
|
||||
group: "style",
|
||||
desc: "`push_str()` or `insert_str()` used with a single-character string literal as parameter",
|
||||
deprecation: None,
|
||||
module: "methods",
|
||||
},
|
||||
Lint {
|
||||
name: "single_char_push_str",
|
||||
group: "style",
|
||||
desc: "`push_str()` used with a single-character string literal as parameter",
|
||||
name: "single_char_pattern",
|
||||
group: "perf",
|
||||
desc: "using a single-character str where a char could be used, e.g., `_.split(\"x\")`",
|
||||
deprecation: None,
|
||||
module: "methods",
|
||||
},
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// run-rustfix
|
||||
#![warn(clippy::single_char_push_str)]
|
||||
#![warn(clippy::single_char_add_str)]
|
||||
|
||||
macro_rules! get_string {
|
||||
() => {
|
||||
|
@ -8,6 +8,23 @@ macro_rules! get_string {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
// `push_str` tests
|
||||
|
||||
let mut string = String::new();
|
||||
string.push('R');
|
||||
string.push('\'');
|
||||
|
||||
string.push('u');
|
||||
string.push_str("st");
|
||||
string.push_str("");
|
||||
string.push('\x52');
|
||||
string.push('\u{0052}');
|
||||
string.push('a');
|
||||
|
||||
get_string!().push('ö');
|
||||
|
||||
// `insert_str` tests
|
||||
|
||||
let mut string = String::new();
|
||||
string.insert(0, 'R');
|
||||
string.insert(1, '\'');
|
|
@ -1,5 +1,5 @@
|
|||
// run-rustfix
|
||||
#![warn(clippy::single_char_push_str)]
|
||||
#![warn(clippy::single_char_add_str)]
|
||||
|
||||
macro_rules! get_string {
|
||||
() => {
|
||||
|
@ -8,6 +8,23 @@ macro_rules! get_string {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
// `push_str` tests
|
||||
|
||||
let mut string = String::new();
|
||||
string.push_str("R");
|
||||
string.push_str("'");
|
||||
|
||||
string.push('u');
|
||||
string.push_str("st");
|
||||
string.push_str("");
|
||||
string.push_str("\x52");
|
||||
string.push_str("\u{0052}");
|
||||
string.push_str(r##"a"##);
|
||||
|
||||
get_string!().push_str("ö");
|
||||
|
||||
// `insert_str` tests
|
||||
|
||||
let mut string = String::new();
|
||||
string.insert_str(0, "R");
|
||||
string.insert_str(1, "'");
|
82
tests/ui/single_char_add_str.stderr
Normal file
82
tests/ui/single_char_add_str.stderr
Normal file
|
@ -0,0 +1,82 @@
|
|||
error: calling `push_str()` using a single-character string literal
|
||||
--> $DIR/single_char_add_str.rs:14:5
|
||||
|
|
||||
LL | string.push_str("R");
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('R')`
|
||||
|
|
||||
= note: `-D clippy::single-char-add-str` implied by `-D warnings`
|
||||
|
||||
error: calling `push_str()` using a single-character string literal
|
||||
--> $DIR/single_char_add_str.rs:15:5
|
||||
|
|
||||
LL | string.push_str("'");
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('/'')`
|
||||
|
||||
error: calling `push_str()` using a single-character string literal
|
||||
--> $DIR/single_char_add_str.rs:20:5
|
||||
|
|
||||
LL | string.push_str("/x52");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('/x52')`
|
||||
|
||||
error: calling `push_str()` using a single-character string literal
|
||||
--> $DIR/single_char_add_str.rs:21:5
|
||||
|
|
||||
LL | string.push_str("/u{0052}");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('/u{0052}')`
|
||||
|
||||
error: calling `push_str()` using a single-character string literal
|
||||
--> $DIR/single_char_add_str.rs:22:5
|
||||
|
|
||||
LL | string.push_str(r##"a"##);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('a')`
|
||||
|
||||
error: calling `push_str()` using a single-character string literal
|
||||
--> $DIR/single_char_add_str.rs:24:5
|
||||
|
|
||||
LL | get_string!().push_str("ö");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `get_string!().push('ö')`
|
||||
|
||||
error: calling `insert_str()` using a single-character string literal
|
||||
--> $DIR/single_char_add_str.rs:29:5
|
||||
|
|
||||
LL | string.insert_str(0, "R");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(0, 'R')`
|
||||
|
||||
error: calling `insert_str()` using a single-character string literal
|
||||
--> $DIR/single_char_add_str.rs:30:5
|
||||
|
|
||||
LL | string.insert_str(1, "'");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(1, '/'')`
|
||||
|
||||
error: calling `insert_str()` using a single-character string literal
|
||||
--> $DIR/single_char_add_str.rs:35:5
|
||||
|
|
||||
LL | string.insert_str(0, "/x52");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(0, '/x52')`
|
||||
|
||||
error: calling `insert_str()` using a single-character string literal
|
||||
--> $DIR/single_char_add_str.rs:36:5
|
||||
|
|
||||
LL | string.insert_str(0, "/u{0052}");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(0, '/u{0052}')`
|
||||
|
||||
error: calling `insert_str()` using a single-character string literal
|
||||
--> $DIR/single_char_add_str.rs:38:5
|
||||
|
|
||||
LL | string.insert_str(x, r##"a"##);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(x, 'a')`
|
||||
|
||||
error: calling `insert_str()` using a single-character string literal
|
||||
--> $DIR/single_char_add_str.rs:40:5
|
||||
|
|
||||
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:42: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
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
error: calling `insert_str()` using a single-character string literal
|
||||
--> $DIR/single_char_insert_str.rs:12:5
|
||||
|
|
||||
LL | string.insert_str(0, "R");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(0, 'R')`
|
||||
|
|
||||
= note: `-D clippy::single-char-push-str` implied by `-D warnings`
|
||||
|
||||
error: calling `insert_str()` using a single-character string literal
|
||||
--> $DIR/single_char_insert_str.rs:13:5
|
||||
|
|
||||
LL | string.insert_str(1, "'");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(1, '/'')`
|
||||
|
||||
error: calling `insert_str()` using a single-character string literal
|
||||
--> $DIR/single_char_insert_str.rs:18:5
|
||||
|
|
||||
LL | string.insert_str(0, "/x52");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(0, '/x52')`
|
||||
|
||||
error: calling `insert_str()` using a single-character string literal
|
||||
--> $DIR/single_char_insert_str.rs:19:5
|
||||
|
|
||||
LL | string.insert_str(0, "/u{0052}");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(0, '/u{0052}')`
|
||||
|
||||
error: calling `insert_str()` using a single-character string literal
|
||||
--> $DIR/single_char_insert_str.rs:21:5
|
||||
|
|
||||
LL | string.insert_str(x, r##"a"##);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(x, 'a')`
|
||||
|
||||
error: calling `insert_str()` using a single-character string literal
|
||||
--> $DIR/single_char_insert_str.rs:23:5
|
||||
|
|
||||
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_insert_str.rs:25:5
|
||||
|
|
||||
LL | get_string!().insert_str(1, "?");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `get_string!().insert(1, '?')`
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
|
@ -12,12 +12,6 @@ fn main() {
|
|||
|
||||
let y = "x";
|
||||
x.split(y);
|
||||
// Not yet testing for multi-byte characters
|
||||
// Changing `r.len() == 1` to `r.chars().count() == 1` in `lint_clippy::single_char_pattern`
|
||||
// should have done this but produced an ICE
|
||||
//
|
||||
// We may not want to suggest changing these anyway
|
||||
// See: https://github.com/rust-lang/rust-clippy/issues/650#issuecomment-184328984
|
||||
x.split('ß');
|
||||
x.split('ℝ');
|
||||
x.split('💣');
|
||||
|
|
|
@ -12,12 +12,6 @@ fn main() {
|
|||
|
||||
let y = "x";
|
||||
x.split(y);
|
||||
// Not yet testing for multi-byte characters
|
||||
// Changing `r.len() == 1` to `r.chars().count() == 1` in `lint_clippy::single_char_pattern`
|
||||
// should have done this but produced an ICE
|
||||
//
|
||||
// We may not want to suggest changing these anyway
|
||||
// See: https://github.com/rust-lang/rust-clippy/issues/650#issuecomment-184328984
|
||||
x.split("ß");
|
||||
x.split("ℝ");
|
||||
x.split("💣");
|
||||
|
|
|
@ -7,175 +7,175 @@ LL | x.split("x");
|
|||
= note: `-D clippy::single-char-pattern` implied by `-D warnings`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:21:13
|
||||
--> $DIR/single_char_pattern.rs:15:13
|
||||
|
|
||||
LL | x.split("ß");
|
||||
| ^^^ help: try using a `char` instead: `'ß'`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:22:13
|
||||
--> $DIR/single_char_pattern.rs:16:13
|
||||
|
|
||||
LL | x.split("ℝ");
|
||||
| ^^^ help: try using a `char` instead: `'ℝ'`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:23:13
|
||||
--> $DIR/single_char_pattern.rs:17:13
|
||||
|
|
||||
LL | x.split("💣");
|
||||
| ^^^^ help: try using a `char` instead: `'💣'`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:26:16
|
||||
--> $DIR/single_char_pattern.rs:20:16
|
||||
|
|
||||
LL | x.contains("x");
|
||||
| ^^^ help: try using a `char` instead: `'x'`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:27:19
|
||||
--> $DIR/single_char_pattern.rs:21:19
|
||||
|
|
||||
LL | x.starts_with("x");
|
||||
| ^^^ help: try using a `char` instead: `'x'`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:28:17
|
||||
--> $DIR/single_char_pattern.rs:22:17
|
||||
|
|
||||
LL | x.ends_with("x");
|
||||
| ^^^ help: try using a `char` instead: `'x'`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:29:12
|
||||
--> $DIR/single_char_pattern.rs:23:12
|
||||
|
|
||||
LL | x.find("x");
|
||||
| ^^^ help: try using a `char` instead: `'x'`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:30:13
|
||||
--> $DIR/single_char_pattern.rs:24:13
|
||||
|
|
||||
LL | x.rfind("x");
|
||||
| ^^^ help: try using a `char` instead: `'x'`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:31:14
|
||||
--> $DIR/single_char_pattern.rs:25:14
|
||||
|
|
||||
LL | x.rsplit("x");
|
||||
| ^^^ help: try using a `char` instead: `'x'`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:32:24
|
||||
--> $DIR/single_char_pattern.rs:26:24
|
||||
|
|
||||
LL | x.split_terminator("x");
|
||||
| ^^^ help: try using a `char` instead: `'x'`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:33:25
|
||||
--> $DIR/single_char_pattern.rs:27:25
|
||||
|
|
||||
LL | x.rsplit_terminator("x");
|
||||
| ^^^ help: try using a `char` instead: `'x'`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:34:17
|
||||
--> $DIR/single_char_pattern.rs:28:17
|
||||
|
|
||||
LL | x.splitn(0, "x");
|
||||
| ^^^ help: try using a `char` instead: `'x'`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:35:18
|
||||
--> $DIR/single_char_pattern.rs:29:18
|
||||
|
|
||||
LL | x.rsplitn(0, "x");
|
||||
| ^^^ help: try using a `char` instead: `'x'`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:36:15
|
||||
--> $DIR/single_char_pattern.rs:30:15
|
||||
|
|
||||
LL | x.matches("x");
|
||||
| ^^^ help: try using a `char` instead: `'x'`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:37:16
|
||||
--> $DIR/single_char_pattern.rs:31:16
|
||||
|
|
||||
LL | x.rmatches("x");
|
||||
| ^^^ help: try using a `char` instead: `'x'`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:38:21
|
||||
--> $DIR/single_char_pattern.rs:32:21
|
||||
|
|
||||
LL | x.match_indices("x");
|
||||
| ^^^ help: try using a `char` instead: `'x'`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:39:22
|
||||
--> $DIR/single_char_pattern.rs:33:22
|
||||
|
|
||||
LL | x.rmatch_indices("x");
|
||||
| ^^^ help: try using a `char` instead: `'x'`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:40:26
|
||||
--> $DIR/single_char_pattern.rs:34:26
|
||||
|
|
||||
LL | x.trim_start_matches("x");
|
||||
| ^^^ help: try using a `char` instead: `'x'`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:41:24
|
||||
--> $DIR/single_char_pattern.rs:35:24
|
||||
|
|
||||
LL | x.trim_end_matches("x");
|
||||
| ^^^ help: try using a `char` instead: `'x'`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:43:13
|
||||
--> $DIR/single_char_pattern.rs:37:13
|
||||
|
|
||||
LL | x.split("/n");
|
||||
| ^^^^ help: try using a `char` instead: `'/n'`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:44:13
|
||||
--> $DIR/single_char_pattern.rs:38:13
|
||||
|
|
||||
LL | x.split("'");
|
||||
| ^^^ help: try using a `char` instead: `'/''`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:45:13
|
||||
--> $DIR/single_char_pattern.rs:39:13
|
||||
|
|
||||
LL | x.split("/'");
|
||||
| ^^^^ help: try using a `char` instead: `'/''`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:50:31
|
||||
--> $DIR/single_char_pattern.rs:44:31
|
||||
|
|
||||
LL | x.replace(";", ",").split(","); // issue #2978
|
||||
| ^^^ help: try using a `char` instead: `','`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:51:19
|
||||
--> $DIR/single_char_pattern.rs:45:19
|
||||
|
|
||||
LL | x.starts_with("/x03"); // issue #2996
|
||||
| ^^^^^^ help: try using a `char` instead: `'/x03'`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:58:13
|
||||
--> $DIR/single_char_pattern.rs:52:13
|
||||
|
|
||||
LL | x.split(r"a");
|
||||
| ^^^^ help: try using a `char` instead: `'a'`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:59:13
|
||||
--> $DIR/single_char_pattern.rs:53:13
|
||||
|
|
||||
LL | x.split(r#"a"#);
|
||||
| ^^^^^^ help: try using a `char` instead: `'a'`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:60:13
|
||||
--> $DIR/single_char_pattern.rs:54:13
|
||||
|
|
||||
LL | x.split(r###"a"###);
|
||||
| ^^^^^^^^^^ help: try using a `char` instead: `'a'`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:61:13
|
||||
--> $DIR/single_char_pattern.rs:55:13
|
||||
|
|
||||
LL | x.split(r###"'"###);
|
||||
| ^^^^^^^^^^ help: try using a `char` instead: `'/''`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:62:13
|
||||
--> $DIR/single_char_pattern.rs:56:13
|
||||
|
|
||||
LL | x.split(r###"#"###);
|
||||
| ^^^^^^^^^^ help: try using a `char` instead: `'#'`
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
// run-rustfix
|
||||
#![warn(clippy::single_char_push_str)]
|
||||
|
||||
macro_rules! get_string {
|
||||
() => {
|
||||
String::from("Hello world!")
|
||||
};
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut string = String::new();
|
||||
string.push('R');
|
||||
string.push('\'');
|
||||
|
||||
string.push('u');
|
||||
string.push_str("st");
|
||||
string.push_str("");
|
||||
string.push('\x52');
|
||||
string.push('\u{0052}');
|
||||
string.push('a');
|
||||
|
||||
get_string!().push('ö');
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
// run-rustfix
|
||||
#![warn(clippy::single_char_push_str)]
|
||||
|
||||
macro_rules! get_string {
|
||||
() => {
|
||||
String::from("Hello world!")
|
||||
};
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut string = String::new();
|
||||
string.push_str("R");
|
||||
string.push_str("'");
|
||||
|
||||
string.push('u');
|
||||
string.push_str("st");
|
||||
string.push_str("");
|
||||
string.push_str("\x52");
|
||||
string.push_str("\u{0052}");
|
||||
string.push_str(r##"a"##);
|
||||
|
||||
get_string!().push_str("ö");
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
error: calling `push_str()` using a single-character string literal
|
||||
--> $DIR/single_char_push_str.rs:12:5
|
||||
|
|
||||
LL | string.push_str("R");
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('R')`
|
||||
|
|
||||
= note: `-D clippy::single-char-push-str` implied by `-D warnings`
|
||||
|
||||
error: calling `push_str()` using a single-character string literal
|
||||
--> $DIR/single_char_push_str.rs:13:5
|
||||
|
|
||||
LL | string.push_str("'");
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('/'')`
|
||||
|
||||
error: calling `push_str()` using a single-character string literal
|
||||
--> $DIR/single_char_push_str.rs:18:5
|
||||
|
|
||||
LL | string.push_str("/x52");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('/x52')`
|
||||
|
||||
error: calling `push_str()` using a single-character string literal
|
||||
--> $DIR/single_char_push_str.rs:19:5
|
||||
|
|
||||
LL | string.push_str("/u{0052}");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('/u{0052}')`
|
||||
|
||||
error: calling `push_str()` using a single-character string literal
|
||||
--> $DIR/single_char_push_str.rs:20:5
|
||||
|
|
||||
LL | string.push_str(r##"a"##);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('a')`
|
||||
|
||||
error: calling `push_str()` using a single-character string literal
|
||||
--> $DIR/single_char_push_str.rs:22:5
|
||||
|
|
||||
LL | get_string!().push_str("ö");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `get_string!().push('ö')`
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
Loading…
Add table
Reference in a new issue