Skip to content

Commit 89f7d70

Browse files
committed
Remove several remnants of #![feature(inline_const_pat)]
1 parent b3c26f1 commit 89f7d70

4 files changed

Lines changed: 20 additions & 30 deletions

File tree

compiler/rustc_middle/src/thir.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -832,18 +832,18 @@ pub enum PatKind<'tcx> {
832832
value: ty::Value<'tcx>,
833833
},
834834

835-
/// Pattern obtained by converting a constant (inline or named) to its pattern
836-
/// representation using `const_to_pat`. This is used for unsafety checking.
835+
/// Wrapper node representing a named constant that was lowered to a pattern
836+
/// using `const_to_pat`.
837+
///
838+
/// This is used by some diagnostics for non-exhaustive matches, to map
839+
/// the pattern node back to the `DefId` of its original constant.
840+
///
841+
/// FIXME(#150498): Can we make this an `Option<DefId>` field on `Pat`
842+
/// instead, so that non-diagnostic code can ignore it more easily?
837843
ExpandedConstant {
838844
/// [DefId] of the constant item.
839845
def_id: DefId,
840846
/// The pattern that the constant lowered to.
841-
///
842-
/// HACK: we need to keep the `DefId` of inline constants around for unsafety checking;
843-
/// therefore when a range pattern contains inline constants, we re-wrap the range pattern
844-
/// with the `ExpandedConstant` nodes that correspond to the range endpoints. Hence
845-
/// `subpattern` may actually be a range pattern, and `def_id` be the constant for one of
846-
/// its endpoints.
847847
subpattern: Box<Pat<'tcx>>,
848848
},
849849

compiler/rustc_mir_build/src/check_unsafety.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -410,14 +410,6 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
410410
visit::walk_pat(self, pat);
411411
self.inside_adt = old_inside_adt;
412412
}
413-
PatKind::ExpandedConstant { def_id, .. } => {
414-
if let Some(def) = def_id.as_local()
415-
&& matches!(self.tcx.def_kind(def_id), DefKind::InlineConst)
416-
{
417-
self.visit_inner_body(def);
418-
}
419-
visit::walk_pat(self, pat);
420-
}
421413
_ => {
422414
visit::walk_pat(self, pat);
423415
}

compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl<'tcx> ConstToPat<'tcx> {
187187
}
188188

189189
// Wrap the pattern in a marker node to indicate that it is the result of lowering a
190-
// constant. This is used for diagnostics, and for unsafety checking of inline const blocks.
190+
// constant. This is used for diagnostics.
191191
let kind = PatKind::ExpandedConstant { subpattern: inlined_const_as_pat, def_id: uv.def };
192192
Box::new(Pat { kind, ty, span: self.span })
193193
}

compiler/rustc_mir_build/src/thir/pattern/mod.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use rustc_middle::ty::adjustment::{PatAdjust, PatAdjustment};
2121
use rustc_middle::ty::layout::IntegerExt;
2222
use rustc_middle::ty::{self, CanonicalUserTypeAnnotation, Ty, TyCtxt};
2323
use rustc_middle::{bug, span_bug};
24-
use rustc_span::def_id::DefId;
2524
use rustc_span::{ErrorGuaranteed, Span};
2625
use tracing::{debug, instrument};
2726

@@ -131,9 +130,8 @@ impl<'tcx> PatCtxt<'tcx> {
131130
fn lower_pattern_range_endpoint(
132131
&mut self,
133132
expr: Option<&'tcx hir::PatExpr<'tcx>>,
134-
// Out-parameters collecting extra data to be reapplied by the caller
133+
// Out-parameter collecting extra data to be reapplied by the caller
135134
ascriptions: &mut Vec<Ascription<'tcx>>,
136-
expanded_consts: &mut Vec<DefId>,
137135
) -> Result<Option<PatRangeBoundary<'tcx>>, ErrorGuaranteed> {
138136
let Some(expr) = expr else { return Ok(None) };
139137

@@ -148,8 +146,10 @@ impl<'tcx> PatCtxt<'tcx> {
148146
ascriptions.push(ascription);
149147
kind = subpattern.kind;
150148
}
151-
PatKind::ExpandedConstant { def_id, subpattern } => {
152-
expanded_consts.push(def_id);
149+
PatKind::ExpandedConstant { def_id: _, subpattern } => {
150+
// Expanded-constant nodes are currently only needed by
151+
// diagnostics that don't apply to range patterns, so we
152+
// can just discard them here.
153153
kind = subpattern.kind;
154154
}
155155
_ => break,
@@ -227,10 +227,7 @@ impl<'tcx> PatCtxt<'tcx> {
227227

228228
// Collect extra data while lowering the endpoints, to be reapplied later.
229229
let mut ascriptions = vec![];
230-
let mut expanded_consts = vec![];
231-
232-
let mut lower_endpoint =
233-
|expr| self.lower_pattern_range_endpoint(expr, &mut ascriptions, &mut expanded_consts);
230+
let mut lower_endpoint = |expr| self.lower_pattern_range_endpoint(expr, &mut ascriptions);
234231

235232
let lo = lower_endpoint(lo_expr)?.unwrap_or(PatRangeBoundary::NegInfinity);
236233
let hi = lower_endpoint(hi_expr)?.unwrap_or(PatRangeBoundary::PosInfinity);
@@ -282,10 +279,11 @@ impl<'tcx> PatCtxt<'tcx> {
282279
let subpattern = Box::new(Pat { span, ty, kind });
283280
kind = PatKind::AscribeUserType { ascription, subpattern };
284281
}
285-
for def_id in expanded_consts {
286-
let subpattern = Box::new(Pat { span, ty, kind });
287-
kind = PatKind::ExpandedConstant { def_id, subpattern };
288-
}
282+
// `PatKind::ExpandedConstant` wrappers from range endpoints used to
283+
// also be preserved here, but that was only needed for unsafeck of
284+
// inline `const { .. }` patterns, which were removed by
285+
// <https://github.com/rust-lang/rust/pull/138492>.
286+
289287
Ok(kind)
290288
}
291289

0 commit comments

Comments
 (0)