diff options
| author | Stuart Cook <Zalathar@users.noreply.github.com> | 2025-04-07 22:29:18 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-07 22:29:18 +1000 |
| commit | 9955b7634d3d830d58f2849c5fcce5094ff448f8 (patch) | |
| tree | 42779970d1618ba2bcd0cdec785ff276de9fa8ee /compiler/rustc_middle/src | |
| parent | 82df6229b6383ba1395eb0599309b30e257c3c3b (diff) | |
| parent | d912c0352516bc8196437bbf00566a1df985b621 (diff) | |
| download | rust-9955b7634d3d830d58f2849c5fcce5094ff448f8.tar.gz rust-9955b7634d3d830d58f2849c5fcce5094ff448f8.zip | |
Rollup merge of #139108 - Nadrieril:simplify-expandedconstant, r=oli-obk
Simplify `thir::PatKind::ExpandedConstant` I made it a bit less ad-hoc. In particular, I removed `is_inline: bool` that was just caching the output of `tcx.def_kind(def_id)`. This makes inline consts a tiny bit less special in patterns. r? `@oli-obk` cc `@Zalathar`
Diffstat (limited to 'compiler/rustc_middle/src')
| -rw-r--r-- | compiler/rustc_middle/src/thir.rs | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index 341678c69eb..c168142fb1e 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -815,23 +815,17 @@ pub enum PatKind<'tcx> { }, /// Pattern obtained by converting a constant (inline or named) to its pattern - /// representation using `const_to_pat`. + /// representation using `const_to_pat`. This is used for unsafety checking. ExpandedConstant { - /// [DefId] of the constant, we need this so that we have a - /// reference that can be used by unsafety checking to visit nested - /// unevaluated constants and for diagnostics. If the `DefId` doesn't - /// correspond to a local crate, it points at the `const` item. + /// [DefId] of the constant item. def_id: DefId, - /// If `false`, then `def_id` points at a `const` item, otherwise it - /// corresponds to a local inline const. - is_inline: bool, - /// If the inline constant is used in a range pattern, this subpattern - /// represents the range (if both ends are inline constants, there will - /// be multiple InlineConstant wrappers). + /// The pattern that the constant lowered to. /// - /// Otherwise, the actual pattern that the constant lowered to. As with - /// other constants, inline constants are matched structurally where - /// possible. + /// HACK: we need to keep the `DefId` of inline constants around for unsafety checking; + /// therefore when a range pattern contains inline constants, we re-wrap the range pattern + /// with the `ExpandedConstant` nodes that correspond to the range endpoints. Hence + /// `subpattern` may actually be a range pattern, and `def_id` be the constant for one of + /// its endpoints. subpattern: Box<Pat<'tcx>>, }, |
