Replace some matches! with if let or ==#149933
Replace some matches! with if let or ==#149933estebank wants to merge 1 commit intorust-lang:mainfrom
matches! with if let or ==#149933Conversation
|
Some changes occurred to constck cc @fee1-dead Some changes occurred in compiler/rustc_attr_parsing Some changes occurred in exhaustiveness checking cc @Nadrieril
cc @Muscraft Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri Some changes occurred to the CTFE machinery Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt Some changes occurred in check-cfg diagnostics cc @Urgau Some changes occurred in compiler/rustc_passes/src/check_attr.rs Some changes occurred in need_type_info.rs cc @lcnr Some changes occurred in compiler/rustc_ast/src/expand/autodiff_attrs.rs cc @ZuseZ4 |
|
r? @nnethercote rustbot has assigned @nnethercote. Use |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
What is the reason for this change? What I like about So while I don't really mind any of these diffs, it also doesn't look like a clear improvement that's worth a sweeping change, and new "unnecessary" |
|
agreed, not sure this is necessarily better. |
|
I don't mind the change. I do think a PR touching 82 files deserves a description that explains the how and the why, though. What prompted this? Did you automate any of it? When did you use |
That's fair! I was touching something else and noticed a
I went through these manually because I wanted to get a sense for whether making a clippy or rustc lint for this would be useful. I see that clippy has almost the opposite, when a Regardless, the reason I created the PR was to gather feedback: is the style shown here what we'd want? I do think that if we have to keep |
|
Stylistically I don't like |
| match args[0].node.ty(&self.ccx.body.local_decls, tcx).kind() { | ||
| ty::Ref(_, ty, _) if matches!(ty.kind(), ty::Ref(_, ty, _) if ty.is_str()) => | ||
| {} | ||
| ty::Ref(_, ty, _) | ||
| if let ty::Ref(_, ty, _) = ty.kind() | ||
| && ty.is_str() => {} | ||
| _ => { | ||
| self.check_op(ops::PanicNonStr); | ||
| } | ||
| } |
There was a problem hiding this comment.
This one should be an if let chain:
| if let ty::Ref(_, ty, _) = args[0].node.ty(&self.ccx.body.local_decls, tcx).kind() | |
| && let ty::Ref(_, ty, _) = ty.kind() | |
| && ty.is_str() | |
| { | |
| // Allow this call, skip all the checks below. | |
| return; | |
| } else { | |
| self.check_op(ops::PanicNonStr); | |
| } |
|
Reminder, once the PR becomes ready for a review, use |
I agree that those case are particularly ugly, and if-let is an improvement. Sounds like splitting the changes into groups might help with progress. Using |
|
☔ The latest upstream changes (presumably #149114) made this pull request unmergeable. Please resolve the merge conflicts. |
Idk. It is annoying that you need to change back to
To me it's just a single variant version of |
…r=Kivooeo Don't use `matches!` when `==` suffices In the codebase we sometimes use `matches!` for values that can actually just be compared. Replace them with `==`. Subset of rust-lang#149933.
Don't use `matches!` when `==` suffices In the codebase we sometimes use `matches!` for values that can actually just be compared. Replace them with `==`. Subset of rust-lang/rust#149933.
"This code is uglier than the alternative, but it might minimize the size of a future diff" feels off-kilter to me. |
|
I think oli was talking about something like this: if MyEnum::Variant == value {}over if let MyEnum::Variant = value {}Which IMO I have no preference over either. But I don't think any of these are uglier over the other either. In any case, I don't think any of these things changed in the diff are using enum variants that might add new data soon. Someone's going to have to change the |
…bk,BoxyUwU,fmease Change some `matches!(.., .. if ..)` with let-chains Follow up to rust-lang#149933.
…bk,BoxyUwU,fmease Change some `matches!(.., .. if ..)` with let-chains Follow up to rust-lang#149933.
No description provided.