Skip to content

Commit 5fcccd1

Browse files
committed
use NonHirLiteral instead of ScalarLiteral, move pattern related code to pat_is_poly in IsThirPolymorphic
1 parent 5e7f138 commit 5fcccd1

File tree

11 files changed

+28
-24
lines changed

11 files changed

+28
-24
lines changed

compiler/rustc_middle/src/thir.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ pub enum ExprKind<'tcx> {
413413
neg: bool,
414414
},
415415
/// For literals that don't correspond to anything in the HIR
416-
ScalarLiteral {
416+
NonHirLiteral {
417417
lit: ty::ScalarInt,
418418
user_ty: Option<Canonical<'tcx, UserType<'tcx>>>,
419419
},
@@ -454,7 +454,7 @@ pub enum ExprKind<'tcx> {
454454

455455
impl<'tcx> ExprKind<'tcx> {
456456
pub fn zero_sized_literal(user_ty: Option<Canonical<'tcx, UserType<'tcx>>>) -> Self {
457-
ExprKind::ScalarLiteral { lit: ty::ScalarInt::ZST, user_ty }
457+
ExprKind::NonHirLiteral { lit: ty::ScalarInt::ZST, user_ty }
458458
}
459459
}
460460

compiler/rustc_middle/src/thir/visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp
119119
}
120120
Closure { closure_id: _, substs: _, upvars: _, movability: _, fake_reads: _ } => {}
121121
Literal { lit: _, neg: _ } => {}
122-
ScalarLiteral { lit: _, user_ty: _ } => {}
122+
NonHirLiteral { lit: _, user_ty: _ } => {}
123123
NamedConst { def_id: _, substs: _, user_ty: _ } => {}
124124
ConstParam { param: _, def_id: _ } => {}
125125
StaticRef { alloc_id: _, ty: _, def_id: _ } => {}

compiler/rustc_mir_build/src/build/expr/as_constant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
4545

4646
Constant { span, user_ty: None, literal: literal.into() }
4747
}
48-
ExprKind::ScalarLiteral { lit, user_ty } => {
48+
ExprKind::NonHirLiteral { lit, user_ty } => {
4949
let user_ty = user_ty.map(|user_ty| {
5050
this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
5151
span,

compiler/rustc_mir_build/src/build/expr/as_place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
567567
| ExprKind::Return { .. }
568568
| ExprKind::Literal { .. }
569569
| ExprKind::NamedConst { .. }
570-
| ExprKind::ScalarLiteral { .. }
570+
| ExprKind::NonHirLiteral { .. }
571571
| ExprKind::ConstParam { .. }
572572
| ExprKind::ConstBlock { .. }
573573
| ExprKind::StaticRef { .. }

compiler/rustc_mir_build/src/build/expr/as_rvalue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
328328
ExprKind::Yield { .. }
329329
| ExprKind::Literal { .. }
330330
| ExprKind::NamedConst { .. }
331-
| ExprKind::ScalarLiteral { .. }
331+
| ExprKind::NonHirLiteral { .. }
332332
| ExprKind::ConstParam { .. }
333333
| ExprKind::ConstBlock { .. }
334334
| ExprKind::StaticRef { .. }

compiler/rustc_mir_build/src/build/expr/as_temp.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
7070
local_decl.local_info =
7171
Some(Box::new(LocalInfo::StaticRef { def_id, is_thread_local: true }));
7272
}
73-
// FIXME Might have to include `ExprKind::ConstParam` here as well
74-
ExprKind::NamedConst { def_id, .. } => {
73+
ExprKind::NamedConst { def_id, .. } | ExprKind::ConstParam { def_id, .. } => {
7574
local_decl.local_info = Some(Box::new(LocalInfo::ConstRef { def_id }));
7675
}
7776
_ => {}

compiler/rustc_mir_build/src/build/expr/category.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl Category {
7171

7272
ExprKind::ConstBlock { .. }
7373
| ExprKind::Literal { .. }
74-
| ExprKind::ScalarLiteral { .. }
74+
| ExprKind::NonHirLiteral { .. }
7575
| ExprKind::ConstParam { .. }
7676
| ExprKind::StaticRef { .. }
7777
| ExprKind::NamedConst { .. } => Some(Category::Constant),

compiler/rustc_mir_build/src/build/expr/into.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
534534
| ExprKind::ConstBlock { .. }
535535
| ExprKind::Literal { .. }
536536
| ExprKind::NamedConst { .. }
537-
| ExprKind::ScalarLiteral { .. }
537+
| ExprKind::NonHirLiteral { .. }
538538
| ExprKind::ConstParam { .. }
539539
| ExprKind::ThreadLocalRef(_)
540540
| ExprKind::StaticRef { .. } => {

compiler/rustc_mir_build/src/check_unsafety.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
304304
| ExprKind::Borrow { .. }
305305
| ExprKind::Literal { .. }
306306
| ExprKind::NamedConst { .. }
307-
| ExprKind::ScalarLiteral { .. }
307+
| ExprKind::NonHirLiteral { .. }
308308
| ExprKind::ConstParam { .. }
309309
| ExprKind::ConstBlock { .. }
310310
| ExprKind::Deref { .. }

compiler/rustc_mir_build/src/thir/cx/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ impl<'tcx> Cx<'tcx> {
695695
})
696696
.size;
697697
let lit = ScalarInt::try_from_uint(offset as u128, size).unwrap();
698-
let kind = ExprKind::ScalarLiteral { lit, user_ty: None };
698+
let kind = ExprKind::NonHirLiteral { lit, user_ty: None };
699699
let offset = self.thir.exprs.push(Expr {
700700
temp_lifetime,
701701
ty: var_ty,

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

+17-12
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,20 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
337337
_ => false,
338338
}
339339
}
340+
341+
fn pat_is_poly(&mut self, pat: &thir::Pat<'tcx>) -> bool {
342+
if pat.ty.has_param_types_or_consts() {
343+
return true;
344+
}
345+
346+
match pat.kind.as_ref() {
347+
thir::PatKind::Constant { value } => value.has_param_types_or_consts(),
348+
thir::PatKind::Range(thir::PatRange { lo, hi, .. }) => {
349+
lo.has_param_types_or_consts() || hi.has_param_types_or_consts()
350+
}
351+
_ => false,
352+
}
353+
}
340354
}
341355

342356
impl<'a, 'tcx> visit::Visitor<'a, 'tcx> for IsThirPolymorphic<'a, 'tcx> {
@@ -354,18 +368,9 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
354368

355369
#[instrument(skip(self), level = "debug")]
356370
fn visit_pat(&mut self, pat: &thir::Pat<'tcx>) {
357-
self.is_poly |= pat.ty.has_param_types_or_consts();
371+
self.is_poly |= self.pat_is_poly(pat);
358372
if !self.is_poly {
359-
match pat.kind.as_ref() {
360-
thir::PatKind::Constant { value } => {
361-
self.is_poly |= value.has_param_types_or_consts();
362-
}
363-
thir::PatKind::Range(thir::PatRange { lo, hi, .. }) => {
364-
self.is_poly |=
365-
lo.has_param_types_or_consts() | hi.has_param_types_or_consts();
366-
}
367-
_ => visit::walk_pat(self, pat),
368-
}
373+
visit::walk_pat(self, pat);
369374
}
370375
}
371376
}
@@ -443,7 +448,7 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
443448

444449
self.nodes.push(Node::Leaf(constant))
445450
}
446-
&ExprKind::ScalarLiteral { lit , user_ty: _} => {
451+
&ExprKind::NonHirLiteral { lit , user_ty: _} => {
447452
// FIXME Construct a Valtree from this ScalarInt when introducing Valtrees
448453
let const_value = ConstValue::Scalar(Scalar::Int(lit));
449454
self.nodes.push(Node::Leaf(ty::Const::from_value(self.tcx, const_value, node.ty)))

0 commit comments

Comments
 (0)