-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[comparison_chain] #4827 Check core::cmp::Ord
is implemented
#4842
[comparison_chain] #4827 Check core::cmp::Ord
is implemented
#4842
Conversation
clippy_lints/src/comparison_chain.rs
Outdated
|
||
// Check that the type being compared implements `core::cmp::Ord` | ||
let ty = cx.tables.expr_ty(lhs1); | ||
let ord_id = get_trait_def_id(cx, &paths::ORD).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let ord_id = get_trait_def_id(cx, &paths::ORD).unwrap(); | |
if let Some(ord_id) = get_trait_def_id(cx, &paths::ORD); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no if_chain here, that would make this syntax work. Using map_or
and a default value of false
instead.
Only emit lint, if `cmp` is actually available on the type being compared. Don't emit lint in cases where only `PartialOrd` is implemented.
3708b8a
to
fff9a8e
Compare
Getting rid of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! r=me with rustup
@bors r=flip1995 rollup |
📌 Commit fff9a8e has been approved by |
…itive-4827, r=flip1995 [comparison_chain] rust-lang#4827 Check `core::cmp::Ord` is implemented Only emit `comparison_chain` lint, if `cmp` is actually available on the type being compared. Don't emit lint in cases where only `PartialOrd` is implemented. I haven't yet fully understood [Adjustments](https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/adjustment/struct.Adjustment.html). I would appreciate, if someone could double check whether my usage of [expr_ty](https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/struct.TypeckTables.html#method.expr_ty) in `clippy_lints/src/comparison_chain.rs:91` is correct or if there are cases where using [expr_ty_adjusted](https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/struct.TypeckTables.html#method.expr_ty_adjusted) would lead to a different result when used with `utils::implements_trait`. --- fixes rust-lang#4827 changelog: [comparison_chain] Check `core::cmp::Ord` is implemented
Only emit
comparison_chain
lint, ifcmp
is actually available on the type being compared. Don't emit lint in cases where onlyPartialOrd
is implemented.I haven't yet fully understood Adjustments. I would appreciate, if someone could double check whether my usage of expr_ty in
clippy_lints/src/comparison_chain.rs:91
is correct or if there are cases where using expr_ty_adjusted would lead to a different result when used withutils::implements_trait
.fixes #4827
changelog: [comparison_chain] Check
core::cmp::Ord
is implemented