diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2025-02-06 13:09:58 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-06 13:09:58 +0100 |
| commit | 62cad970e86b00bd731226426cb259148679fbb7 (patch) | |
| tree | 8ad2ef69a923d8599060c09282ee96f54f924dcd /compiler/rustc_middle/src | |
| parent | 7ca29360a7983323c0c3a9623ba8eef0cc68e663 (diff) | |
| parent | ab3115990d333b8b782f8ea062c881fda377a353 (diff) | |
| download | rust-62cad970e86b00bd731226426cb259148679fbb7.tar.gz rust-62cad970e86b00bd731226426cb259148679fbb7.zip | |
Rollup merge of #136235 - oli-obk:transmuty-pat-tys, r=RalfJung
Pretty print pattern type values with transmute if they don't satisfy their pattern
Instead of printing `0_u32 is 1..`, we now print the default fallback rendering that we also use for invalid bools, chars, ...: `{transmute(0x00000000): (u32) is 1..=}`.
These cases can occur in mir dumps when const prop propagates a constant across a safety check that would prevent the actually UB value from existing. That's fine though, as it's dead code and we always need to allow UB in dead code.
follow-up to https://github.com/rust-lang/rust/pull/136176
cc ``@compiler-errors`` ``@scottmcm``
r? ``@RalfJung`` because of the interpreter changes
Diffstat (limited to 'compiler/rustc_middle/src')
| -rw-r--r-- | compiler/rustc_middle/src/hooks/mod.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/print/pretty.rs | 2 |
2 files changed, 5 insertions, 1 deletions
diff --git a/compiler/rustc_middle/src/hooks/mod.rs b/compiler/rustc_middle/src/hooks/mod.rs index 276a02b4e0f..c5ce6efcb81 100644 --- a/compiler/rustc_middle/src/hooks/mod.rs +++ b/compiler/rustc_middle/src/hooks/mod.rs @@ -98,6 +98,10 @@ declare_hooks! { hook save_dep_graph() -> (); hook query_key_hash_verify_all() -> (); + + /// Ensure the given scalar is valid for the given type. + /// This checks non-recursive runtime validity. + hook validate_scalar_in_layout(scalar: crate::ty::ScalarInt, ty: Ty<'tcx>) -> bool; } #[cold] diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 3431081b189..feae8ea312e 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -1741,7 +1741,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { " as ", )?; } - ty::Pat(base_ty, pat) => { + ty::Pat(base_ty, pat) if self.tcx().validate_scalar_in_layout(int, ty) => { self.pretty_print_const_scalar_int(int, *base_ty, print_ty)?; p!(write(" is {pat:?}")); } |
