Skip to content

Commit b80903b

Browse files
committed
Auto merge of #6950 - Sciencentistguy:master, r=phansch
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
2 parents 029777f + 45e7756 commit b80903b

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

clippy_lints/src/methods/or_fun_call.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub(super) fn check<'tcx>(
9191
let ty = cx.typeck_results().expr_ty(&args[0]).peel_refs();
9292

9393
match ty.kind() {
94-
ty::Slice(_) | ty::Array(_, _) => return,
94+
ty::Slice(_) | ty::Array(_, _) | ty::Str => return,
9595
_ => (),
9696
}
9797

tests/ui/or_fun_call.fixed

+3
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ fn test_or_with_ctors() {
120120

121121
let slice = &["foo"][..];
122122
let _ = opt.ok_or(slice.len());
123+
124+
let string = "foo";
125+
let _ = opt.ok_or(string.len());
123126
}
124127

125128
// Issue 4514 - early return

tests/ui/or_fun_call.rs

+3
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ fn test_or_with_ctors() {
120120

121121
let slice = &["foo"][..];
122122
let _ = opt.ok_or(slice.len());
123+
124+
let string = "foo";
125+
let _ = opt.ok_or(string.len());
123126
}
124127

125128
// Issue 4514 - early return

tests/ui/or_fun_call.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,19 @@ LL | .or(Some(Bar(b, Duration::from_secs(2))));
115115
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_else(|| Some(Bar(b, Duration::from_secs(2))))`
116116

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

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

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

0 commit comments

Comments
 (0)