You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pub fn inrange<T: Ord>(s: &[T], n: &T) -> bool {
s.last().map_or(false, |last| &s[0] <= n && n <= last)
}
Clippy warns:
--> src/lib.rs:2:35
|
2 | s.last().map_or(false, |last| &s[0] <= n && n <= last)
| -----^^^^^
| |
| help: use the left value directly: `s[0]`
|
= note: `#[warn(clippy::op_ref)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#op_ref
However, this is incorrect, as n has reference type &T. Changing it to s[0] <= n fails to compile:
error[E0308]: mismatched types
--> src/lib.rs:2:43
|
2 | s.last().map_or(false, |last| s[0] <= n && n <= last)
| ^ expected type parameter, found &T
|
= note: expected type `T`
found type `&T`
= help: type parameters must be constrained to match other types
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
The text was updated successfully, but these errors were encountered:
The span is fine. Usually the span of the suggestion == span of error message (especially in Clippy), this is then displayed with just ^^^. In this case the span of the suggestion is shorter than the span of the error message, which is displayed with --- (for the sugg span) and ^^^ (continuation for the error span).
Given the code:
Clippy warns:
However, this is incorrect, as
n
has reference type&T
. Changing it tos[0] <= n
fails to compile:The text was updated successfully, but these errors were encountered: