Skip to content

missing_transmute_annotations: handle pattern_types in suggestion - #17613

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

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

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
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
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

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.

2 participants