Ignore str::len() in or_fun_call lint.

This commit is contained in:
Jamie Quigley 2021-03-22 19:34:20 +00:00
parent aca95aac7b
commit 45e775697e
No known key found for this signature in database
GPG Key ID: 8E8FF66E2AE8D970
4 changed files with 10 additions and 4 deletions

View File

@ -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,
_ => (),
}

View File

@ -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

View File

@ -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

View File

@ -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() })`