rust/compiler/rustc_pattern_analysis
Matthias Krüger d73decdaad
Rollup merge of #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.
2024-07-29 11:42:34 +02:00
..
src Rollup merge of #128304 - Zalathar:thir-pat-display, r=Nadrieril 2024-07-29 11:42:34 +02:00
tests Reformat use declarations. 2024-07-29 08:26:52 +10:00
Cargo.toml bump tracing-tree to 0.3 2024-03-30 17:39:43 +03:00
messages.ftl Lint small gaps between ranges 2024-03-09 01:14:22 +01:00