missing_transmute_annotations: handle pattern_types in suggestion - #17613
missing_transmute_annotations: handle pattern_types in suggestion#17613GTimothy wants to merge 2 commits into
missing_transmute_annotations: handle pattern_types in suggestion#17613Conversation
| /// Tries to render a `ty::Pat` type as a valid `pattern_type!(...)` macro invocation, | ||
| fn try_format_pat_ty(ty: Ty<'_>) -> Option<String> { | ||
| let ty::Pat(base, pat) = ty.kind() else { return None }; | ||
| if matches!(base.kind(), ty::Pat(..)) { |
There was a problem hiding this comment.
Is this right, or should I just return None here?
|
Hm, I think the usual expectation is that the |
Ok, I will thanks |
|
@ada4a I opened this PR: rust-lang/rust#161707 that solves the same issue but in the more elegant way you pointed me at. It avoids adding a test in clippy that depends on the format of If rust-lang/rust#161707 gets merged, I will close this PR. |
Rollup merge of #161707 - GTimothy:pattern_type-pretty-print-impl, r=mejrs pattern_type: make print format match the current syntax Print a pattern type using the `pattern_type!(type is pattern)` syntax instead of `(type) is pattern`. This helps for example when suggesting fixes: `(type) is pattern` is not valid rust right now but `pattern_type!(type is pattern)` is. This is not a bug as `pattern_type` is not on stable but it is a fairly impact-less change, just a print change. discussion: [#t-compiler > pattern_type pretty format](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/pattern_type.20pretty.20format/with/618658793) closes rust-lang/rust-clippy#17613
|
It's astonishing that a push to a random fork of rust closed a PR on clippy... But this was supposed to be closed by rust-lang/rust#161707 anyway, so yeah |
|
@ada4a Btw I'm not that random, I'm actually an infra-admin in |
|
Sorry @ubiratansoares, I didn't mean to be disrespectful 🙂 I'm pretty sure that is a GitHub bug, yeah. Thank you for your work on infra! |
|
@ada4a No offenses taken 😄 |
|
Edit: ah, i see this link is about issues, not PRs... perhaps they are both considered issues by Github? I guess that if you refreshed your fork and Then it is working as intended? Seems easy to abuse though. |
…mejrs pattern_type: make print format match the current syntax Print a pattern type using the `pattern_type!(type is pattern)` syntax instead of `(type) is pattern`. This helps for example when suggesting fixes: `(type) is pattern` is not valid rust right now but `pattern_type!(type is pattern)` is. This is not a bug as `pattern_type` is not on stable but it is a fairly impact-less change, just a print change. discussion: [#t-compiler > pattern_type pretty format](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/pattern_type.20pretty.20format/with/618658793) closes rust-lang/rust-clippy#17613

transmute_missing_annotationsdoes not suggest valid rust code forpattern_types. For instance, a range pattern_type likepattern_type!(u8 is 1..)gets suggested as((u8) is 1..).This PR addresses this issue.
It also gates the suggestion itself on the
pattern_typefeature being enabled to avoid suggesting code that cannot compile without it.changelog:[
transmute_missing_annotations]: handle pattern_types in suggestion