-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Isolate the diagnostic code that expects thir::Pat
to be printable
#128304
Conversation
In several cases this avoids the need to clone the underlying pattern, and then print the clone later.
r? @fee1-dead rustbot has assigned @fee1-dead. Use |
Some changes occurred in exhaustiveness checking cc @Nadrieril Some changes occurred in match checking cc @Nadrieril |
Noting mostly for my own reference, another mention of obstacles to switching over to |
It looks like |
This hides the fact that we print `WitnessPat` by converting it to `thir::Pat` and then printing that.
This gives a clearer view of the (diagnostic) code that expects to be able to print THIR patterns, and makes it possible to experiment with requiring some kind of context (for ID lookup) when printing patterns.
3ba3ec2
to
ae0ec73
Compare
Looks good, thank you! r? Nadrieril @bors r+ |
…eril Isolate the diagnostic code that expects `thir::Pat` to be printable Currently, `thir::Pat` implements `fmt::Display` (and `IntoDiagArg`) directly, for use by a few diagnostics. That makes it tricky to experiment with alternate representations for THIR patterns, because the patterns currently need to be printable on their own. That immediately rules out possibilities like storing subpatterns as a `PatId` index into a central list (instead of the current directly-owned `Box<Pat>`). This PR therefore takes an incremental step away from that obstacle, by removing `thir::Pat` from diagnostic structs in `rustc_pattern_analysis`, and hiding the pattern-printing process behind a single public `Pat::to_string` method. Doing so makes it easier to identify and update the code that wants to print patterns, and gives a place to pass in additional context in the future if necessary. --- I'm currently not sure whether switching over to `PatId` is actually desirable or not, but I think this change makes sense on its own merits, by reducing the coupling between `thir::Pat` and the pattern-analysis error types.
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#128182 (handle no_std targets on std builds) - rust-lang#128277 (miri: fix offset_from behavior on wildcard pointers) - rust-lang#128304 (Isolate the diagnostic code that expects `thir::Pat` to be printable) - rust-lang#128307 (Clean and enable `rustdoc::unescaped_backticks` for `core/alloc/std/test/proc_macro`) - rust-lang#128322 (CI: move RFL job forward to v6.11-rc1) - rust-lang#128333 (Miri subtree update) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#128304 - Zalathar:thir-pat-display, r=Nadrieril Isolate the diagnostic code that expects `thir::Pat` to be printable Currently, `thir::Pat` implements `fmt::Display` (and `IntoDiagArg`) directly, for use by a few diagnostics. That makes it tricky to experiment with alternate representations for THIR patterns, because the patterns currently need to be printable on their own. That immediately rules out possibilities like storing subpatterns as a `PatId` index into a central list (instead of the current directly-owned `Box<Pat>`). This PR therefore takes an incremental step away from that obstacle, by removing `thir::Pat` from diagnostic structs in `rustc_pattern_analysis`, and hiding the pattern-printing process behind a single public `Pat::to_string` method. Doing so makes it easier to identify and update the code that wants to print patterns, and gives a place to pass in additional context in the future if necessary. --- I'm currently not sure whether switching over to `PatId` is actually desirable or not, but I think this change makes sense on its own merits, by reducing the coupling between `thir::Pat` and the pattern-analysis error types.
This reverts commit ae0ec73. The original change in rust-lang#128304 was intended to be a step towards being able to print `thir::Pat` even after switching to `PatId`. But because the only patterns that need to be printed are the synthetic ones created by pattern analysis (for diagnostic purposes only), it makes more sense to completely separate the printable patterns from the real THIR patterns.
Currently,
thir::Pat
implementsfmt::Display
(andIntoDiagArg
) directly, for use by a few diagnostics.That makes it tricky to experiment with alternate representations for THIR patterns, because the patterns currently need to be printable on their own. That immediately rules out possibilities like storing subpatterns as a
PatId
index into a central list (instead of the current directly-ownedBox<Pat>
).This PR therefore takes an incremental step away from that obstacle, by removing
thir::Pat
from diagnostic structs inrustc_pattern_analysis
, and hiding the pattern-printing process behind a single publicPat::to_string
method. Doing so makes it easier to identify and update the code that wants to print patterns, and gives a place to pass in additional context in the future if necessary.I'm currently not sure whether switching over to
PatId
is actually desirable or not, but I think this change makes sense on its own merits, by reducing the coupling betweenthir::Pat
and the pattern-analysis error types.