about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Wright <mikerite@lavabit.com>2020-09-14 06:11:35 +0200
committerMichael Wright <mikerite@lavabit.com>2020-09-14 06:11:35 +0200
commit15244a88df5cfd475df010ad945474c658749192 (patch)
treed9b055cf5cc5bd3959951e3889e8203037f8f883
parentd1f0f04a488d027fdf91e08cdf25df00fb677205 (diff)
downloadrust-15244a88df5cfd475df010ad945474c658749192.tar.gz
rust-15244a88df5cfd475df010ad945474c658749192.zip
Fix `manual-strip` dogfood errors
-rw-r--r--clippy_lints/src/doc.rs2
-rw-r--r--clippy_lints/src/loops.rs8
-rw-r--r--clippy_lints/src/misc_early.rs6
-rw-r--r--clippy_lints/src/redundant_clone.rs5
-rw-r--r--tests/ui/let_if_seq.rs1
-rw-r--r--tests/ui/let_if_seq.stderr8
6 files changed, 14 insertions, 16 deletions
diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs
index 50121a054c7..62bb70af06e 100644
--- a/clippy_lints/src/doc.rs
+++ b/clippy_lints/src/doc.rs
@@ -534,7 +534,7 @@ fn check_word(cx: &LateContext<'_>, word: &str, span: Span) {
             return false;
         }
 
-        let s = if s.ends_with('s') { &s[..s.len() - 1] } else { s };
+        let s = s.strip_suffix('s').unwrap_or(s);
 
         s.chars().all(char::is_alphanumeric)
             && s.chars().filter(|&c| c.is_uppercase()).take(2).count() > 1
diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs
index 6c54c07869a..8f5675a61b9 100644
--- a/clippy_lints/src/loops.rs
+++ b/clippy_lints/src/loops.rs
@@ -2601,11 +2601,9 @@ fn check_needless_collect_direct_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCont
                         span,
                         NEEDLESS_COLLECT_MSG,
                         |diag| {
-                            let (arg, pred) = if contains_arg.starts_with('&') {
-                                ("x", &contains_arg[1..])
-                            } else {
-                                ("&x", &*contains_arg)
-                            };
+                            let (arg, pred) = contains_arg
+                                    .strip_prefix('&')
+                                    .map_or(("&x", &*contains_arg), |s| ("x", s));
                             diag.span_suggestion(
                                 span,
                                 "replace with",
diff --git a/clippy_lints/src/misc_early.rs b/clippy_lints/src/misc_early.rs
index 02789735c17..9cb1cfb915d 100644
--- a/clippy_lints/src/misc_early.rs
+++ b/clippy_lints/src/misc_early.rs
@@ -377,8 +377,8 @@ impl EarlyLintPass for MiscEarlyLints {
             if let PatKind::Ident(_, ident, None) = arg.pat.kind {
                 let arg_name = ident.to_string();
 
-                if arg_name.starts_with('_') {
-                    if let Some(correspondence) = registered_names.get(&arg_name[1..]) {
+                if let Some(arg_name) = arg_name.strip_prefix('_') {
+                    if let Some(correspondence) = registered_names.get(arg_name) {
                         span_lint(
                             cx,
                             DUPLICATE_UNDERSCORE_ARGUMENT,
@@ -386,7 +386,7 @@ impl EarlyLintPass for MiscEarlyLints {
                             &format!(
                                 "`{}` already exists, having another argument having almost the same \
                                  name makes code comprehension and documentation more difficult",
-                                arg_name[1..].to_owned()
+                                arg_name
                             ),
                         );
                     }
diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs
index 57a45e628db..1a7f36fbdad 100644
--- a/clippy_lints/src/redundant_clone.rs
+++ b/clippy_lints/src/redundant_clone.rs
@@ -239,10 +239,9 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone {
                         );
                         let mut app = Applicability::MaybeIncorrect;
 
-                        let mut call_snip = &snip[dot + 1..];
+                        let call_snip = &snip[dot + 1..];
                         // Machine applicable when `call_snip` looks like `foobar()`
-                        if call_snip.ends_with("()") {
-                            call_snip = call_snip[..call_snip.len()-2].trim();
+                        if let Some(call_snip) = call_snip.strip_suffix("()").map(str::trim) {
                             if call_snip.as_bytes().iter().all(|b| b.is_ascii_alphabetic() || *b == b'_') {
                                 app = Applicability::MachineApplicable;
                             }
diff --git a/tests/ui/let_if_seq.rs b/tests/ui/let_if_seq.rs
index 802beeb4be6..32a67f181df 100644
--- a/tests/ui/let_if_seq.rs
+++ b/tests/ui/let_if_seq.rs
@@ -33,6 +33,7 @@ fn issue985_alt() -> i32 {
     x
 }
 
+#[allow(clippy::manual_strip)]
 fn issue975() -> String {
     let mut udn = "dummy".to_string();
     if udn.starts_with("uuid:") {
diff --git a/tests/ui/let_if_seq.stderr b/tests/ui/let_if_seq.stderr
index c53a63a541b..7de560c7348 100644
--- a/tests/ui/let_if_seq.stderr
+++ b/tests/ui/let_if_seq.stderr
@@ -1,5 +1,5 @@
 error: `if _ { .. } else { .. }` is an expression
-  --> $DIR/let_if_seq.rs:63:5
+  --> $DIR/let_if_seq.rs:64:5
    |
 LL | /     let mut foo = 0;
 LL | |     if f() {
@@ -11,7 +11,7 @@ LL | |     }
    = note: you might not need `mut` at all
 
 error: `if _ { .. } else { .. }` is an expression
-  --> $DIR/let_if_seq.rs:68:5
+  --> $DIR/let_if_seq.rs:69:5
    |
 LL | /     let mut bar = 0;
 LL | |     if f() {
@@ -25,7 +25,7 @@ LL | |     }
    = note: you might not need `mut` at all
 
 error: `if _ { .. } else { .. }` is an expression
-  --> $DIR/let_if_seq.rs:76:5
+  --> $DIR/let_if_seq.rs:77:5
    |
 LL | /     let quz;
 LL | |     if f() {
@@ -36,7 +36,7 @@ LL | |     }
    | |_____^ help: it is more idiomatic to write: `let quz = if f() { 42 } else { 0 };`
 
 error: `if _ { .. } else { .. }` is an expression
-  --> $DIR/let_if_seq.rs:105:5
+  --> $DIR/let_if_seq.rs:106:5
    |
 LL | /     let mut baz = 0;
 LL | |     if f() {