Skip to content

Commit

Permalink
Auto merge of #6950 - Sciencentistguy:master, r=phansch
Browse files Browse the repository at this point in the history
Ignore str::len() in or_fun_call lint.

changelog: Changed `or_fun_call` to ignore `str::len`, in the same way it ignores `slice::len` and `array::len`

Closes #6943
  • Loading branch information
bors committed Mar 22, 2021
2 parents 029777f + 45e7756 commit b80903b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/or_fun_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub(super) fn check<'tcx>(
let ty = cx.typeck_results().expr_ty(&args[0]).peel_refs();

match ty.kind() {
ty::Slice(_) | ty::Array(_, _) => return,
ty::Slice(_) | ty::Array(_, _) | ty::Str => return,
_ => (),
}

Expand Down
3 changes: 3 additions & 0 deletions tests/ui/or_fun_call.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ fn test_or_with_ctors() {

let slice = &["foo"][..];
let _ = opt.ok_or(slice.len());

let string = "foo";
let _ = opt.ok_or(string.len());
}

// Issue 4514 - early return
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/or_fun_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ fn test_or_with_ctors() {

let slice = &["foo"][..];
let _ = opt.ok_or(slice.len());

let string = "foo";
let _ = opt.ok_or(string.len());
}

// Issue 4514 - early return
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/or_fun_call.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,19 @@ LL | .or(Some(Bar(b, Duration::from_secs(2))));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_else(|| Some(Bar(b, Duration::from_secs(2))))`

error: use of `unwrap_or` followed by a function call
--> $DIR/or_fun_call.rs:138:14
--> $DIR/or_fun_call.rs:141:14
|
LL | None.unwrap_or(s.as_mut_vec());
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| s.as_mut_vec())`

error: use of `unwrap_or` followed by a function call
--> $DIR/or_fun_call.rs:143:14
--> $DIR/or_fun_call.rs:146:14
|
LL | None.unwrap_or(unsafe { s.as_mut_vec() });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| unsafe { s.as_mut_vec() })`

error: use of `unwrap_or` followed by a function call
--> $DIR/or_fun_call.rs:145:14
--> $DIR/or_fun_call.rs:148:14
|
LL | None.unwrap_or( unsafe { s.as_mut_vec() } );
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| unsafe { s.as_mut_vec() })`
Expand Down

0 comments on commit b80903b

Please sign in to comment.