Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 15244a8

Browse files
author
Michael Wright
committed
Fix manual-strip dogfood errors
1 parent d1f0f04 commit 15244a8

File tree

6 files changed

+14
-16
lines changed

6 files changed

+14
-16
lines changed

clippy_lints/src/doc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ fn check_word(cx: &LateContext<'_>, word: &str, span: Span) {
534534
return false;
535535
}
536536

537-
let s = if s.ends_with('s') { &s[..s.len() - 1] } else { s };
537+
let s = s.strip_suffix('s').unwrap_or(s);
538538

539539
s.chars().all(char::is_alphanumeric)
540540
&& s.chars().filter(|&c| c.is_uppercase()).take(2).count() > 1

clippy_lints/src/loops.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2601,11 +2601,9 @@ fn check_needless_collect_direct_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCont
26012601
span,
26022602
NEEDLESS_COLLECT_MSG,
26032603
|diag| {
2604-
let (arg, pred) = if contains_arg.starts_with('&') {
2605-
("x", &contains_arg[1..])
2606-
} else {
2607-
("&x", &*contains_arg)
2608-
};
2604+
let (arg, pred) = contains_arg
2605+
.strip_prefix('&')
2606+
.map_or(("&x", &*contains_arg), |s| ("x", s));
26092607
diag.span_suggestion(
26102608
span,
26112609
"replace with",

clippy_lints/src/misc_early.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,16 +377,16 @@ impl EarlyLintPass for MiscEarlyLints {
377377
if let PatKind::Ident(_, ident, None) = arg.pat.kind {
378378
let arg_name = ident.to_string();
379379

380-
if arg_name.starts_with('_') {
381-
if let Some(correspondence) = registered_names.get(&arg_name[1..]) {
380+
if let Some(arg_name) = arg_name.strip_prefix('_') {
381+
if let Some(correspondence) = registered_names.get(arg_name) {
382382
span_lint(
383383
cx,
384384
DUPLICATE_UNDERSCORE_ARGUMENT,
385385
*correspondence,
386386
&format!(
387387
"`{}` already exists, having another argument having almost the same \
388388
name makes code comprehension and documentation more difficult",
389-
arg_name[1..].to_owned()
389+
arg_name
390390
),
391391
);
392392
}

clippy_lints/src/redundant_clone.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,9 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone {
239239
);
240240
let mut app = Applicability::MaybeIncorrect;
241241

242-
let mut call_snip = &snip[dot + 1..];
242+
let call_snip = &snip[dot + 1..];
243243
// Machine applicable when `call_snip` looks like `foobar()`
244-
if call_snip.ends_with("()") {
245-
call_snip = call_snip[..call_snip.len()-2].trim();
244+
if let Some(call_snip) = call_snip.strip_suffix("()").map(str::trim) {
246245
if call_snip.as_bytes().iter().all(|b| b.is_ascii_alphabetic() || *b == b'_') {
247246
app = Applicability::MachineApplicable;
248247
}

tests/ui/let_if_seq.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ fn issue985_alt() -> i32 {
3333
x
3434
}
3535

36+
#[allow(clippy::manual_strip)]
3637
fn issue975() -> String {
3738
let mut udn = "dummy".to_string();
3839
if udn.starts_with("uuid:") {

tests/ui/let_if_seq.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: `if _ { .. } else { .. }` is an expression
2-
--> $DIR/let_if_seq.rs:63:5
2+
--> $DIR/let_if_seq.rs:64:5
33
|
44
LL | / let mut foo = 0;
55
LL | | if f() {
@@ -11,7 +11,7 @@ LL | | }
1111
= note: you might not need `mut` at all
1212

1313
error: `if _ { .. } else { .. }` is an expression
14-
--> $DIR/let_if_seq.rs:68:5
14+
--> $DIR/let_if_seq.rs:69:5
1515
|
1616
LL | / let mut bar = 0;
1717
LL | | if f() {
@@ -25,7 +25,7 @@ LL | | }
2525
= note: you might not need `mut` at all
2626

2727
error: `if _ { .. } else { .. }` is an expression
28-
--> $DIR/let_if_seq.rs:76:5
28+
--> $DIR/let_if_seq.rs:77:5
2929
|
3030
LL | / let quz;
3131
LL | | if f() {
@@ -36,7 +36,7 @@ LL | | }
3636
| |_____^ help: it is more idiomatic to write: `let quz = if f() { 42 } else { 0 };`
3737

3838
error: `if _ { .. } else { .. }` is an expression
39-
--> $DIR/let_if_seq.rs:105:5
39+
--> $DIR/let_if_seq.rs:106:5
4040
|
4141
LL | / let mut baz = 0;
4242
LL | | if f() {

0 commit comments

Comments
 (0)