Skip to content

Commit

Permalink
Fix manual-strip dogfood errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Wright committed Sep 14, 2020
1 parent d1f0f04 commit 15244a8
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion clippy_lints/src/doc.rs
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions clippy_lints/src/loops.rs
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/misc_early.rs
Expand Up @@ -377,16 +377,16 @@ 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,
*correspondence,
&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
),
);
}
Expand Down
5 changes: 2 additions & 3 deletions clippy_lints/src/redundant_clone.rs
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions tests/ui/let_if_seq.rs
Expand Up @@ -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:") {
Expand Down
8 changes: 4 additions & 4 deletions 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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down

0 comments on commit 15244a8

Please sign in to comment.