Skip to content

missing_transmute_annotations: handle pattern_types in suggestion - #17613

Closed
GTimothy wants to merge 2 commits into
rust-lang:masterfrom
GTimothy:missing_transmute_annotations_pattern_types
Closed

missing_transmute_annotations: handle pattern_types in suggestion#17613
GTimothy wants to merge 2 commits into
rust-lang:masterfrom
GTimothy:missing_transmute_annotations_pattern_types

Conversation

@GTimothy

Copy link
Copy Markdown
Contributor

transmute_missing_annotations does not suggest valid rust code for pattern_types. For instance, a range pattern_type like pattern_type!(u8 is 1..) gets suggested as ((u8) is 1..).

This PR addresses this issue.
It also gates the suggestion itself on the pattern_type feature being enabled to avoid suggesting code that cannot compile without it.

changelog:[transmute_missing_annotations]: handle pattern_types in suggestion

/// 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(..)) {

@GTimothy GTimothy Aug 23, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this right, or should I just return None here?

View changes since the review

@ada4a

ada4a commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Hm, I think the usual expectation is that the Display impl for Ty prints the type in a way that's suitable for suggestions. So this might actually be a bug in pretty-printing, namely at https://github.com/rust-lang/rust/blob/fb6531d550e0075b9eb9a51464f404805eec87d9/compiler/rustc_middle/src/ty/print/pretty.rs#L758-L762? I'd ask about this over at #t-compiler/help maybe

@GTimothy

Copy link
Copy Markdown
Contributor Author

Hm, I think the usual expectation is that the Display impl for Ty prints the type in a way that's suitable for suggestions. So this might actually be a bug in pretty-printing, namely at https://github.com/rust-lang/rust/blob/fb6531d550e0075b9eb9a51464f404805eec87d9/compiler/rustc_middle/src/ty/print/pretty.rs#L758-L762? I'd ask about this over at #t-compiler/help maybe

Ok, I will thanks

@GTimothy

Copy link
Copy Markdown
Contributor Author

@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 pattern_type that is still subject to change.

If rust-lang/rust#161707 gets merged, I will close this PR.

rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Aug 26, 2026
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
@ada4a

ada4a commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

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

@ubiratansoares

Copy link
Copy Markdown

Hey there 👋

I just want to highlight I think this is a Github bug, it's not the first notification of this type I got for PRs/commits I did not interact with.

screenshot-2026-08-26 at 21 47 08

@ubiratansoares

Copy link
Copy Markdown

@ada4a Btw I'm not that random, I'm actually an infra-admin in rust-lang

@ada4a

ada4a commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

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!

@ubiratansoares

Copy link
Copy Markdown

@ada4a No offenses taken 😄

@GTimothy

GTimothy commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

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

you have push access to that repository.

Then it is working as intended? Seems easy to abuse though.

pull Bot pushed a commit to xtqqczze/rust-lang-miri that referenced this pull request Aug 27, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants