Skip to content

Commit 8818708

Browse files
committed
Use ConstArg for assoc item constraints
1 parent e7c85cb commit 8818708

File tree

9 files changed

+31
-22
lines changed

9 files changed

+31
-22
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10621062
AssocItemConstraintKind::Equality { term } => {
10631063
let term = match term {
10641064
Term::Ty(ty) => self.lower_ty(ty, itctx).into(),
1065-
Term::Const(c) => self.lower_anon_const_to_anon_const(c).into(),
1065+
Term::Const(c) => self.lower_anon_const_to_const_arg(c).into(),
10661066
};
10671067
hir::AssocItemConstraintKind::Equality { term }
10681068
}

compiler/rustc_hir/src/hir.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ impl<'hir> ConstArg<'hir> {
242242
}
243243
}
244244

245-
pub fn hir_id(&self) -> HirId {
245+
pub fn anon_const_hir_id(&self) -> HirId {
246246
match self.kind {
247247
ConstArgKind::Anon(anon) => anon.hir_id,
248248
}
@@ -288,7 +288,7 @@ impl GenericArg<'_> {
288288
match self {
289289
GenericArg::Lifetime(l) => l.hir_id,
290290
GenericArg::Type(t) => t.hir_id,
291-
GenericArg::Const(c) => c.hir_id(),
291+
GenericArg::Const(c) => c.anon_const_hir_id(), // FIXME
292292
GenericArg::Infer(i) => i.hir_id,
293293
}
294294
}
@@ -2453,7 +2453,7 @@ impl<'hir> AssocItemConstraint<'hir> {
24532453
}
24542454

24552455
/// Obtain the const on the RHS of an assoc const equality constraint if applicable.
2456-
pub fn ct(self) -> Option<&'hir AnonConst> {
2456+
pub fn ct(self) -> Option<&'hir ConstArg<'hir>> {
24572457
match self.kind {
24582458
AssocItemConstraintKind::Equality { term: Term::Const(ct) } => Some(ct),
24592459
_ => None,
@@ -2464,7 +2464,7 @@ impl<'hir> AssocItemConstraint<'hir> {
24642464
#[derive(Debug, Clone, Copy, HashStable_Generic)]
24652465
pub enum Term<'hir> {
24662466
Ty(&'hir Ty<'hir>),
2467-
Const(&'hir AnonConst),
2467+
Const(&'hir ConstArg<'hir>),
24682468
}
24692469

24702470
impl<'hir> From<&'hir Ty<'hir>> for Term<'hir> {
@@ -2473,8 +2473,8 @@ impl<'hir> From<&'hir Ty<'hir>> for Term<'hir> {
24732473
}
24742474
}
24752475

2476-
impl<'hir> From<&'hir AnonConst> for Term<'hir> {
2477-
fn from(c: &'hir AnonConst) -> Self {
2476+
impl<'hir> From<&'hir ConstArg<'hir>> for Term<'hir> {
2477+
fn from(c: &'hir ConstArg<'hir>) -> Self {
24782478
Term::Const(c)
24792479
}
24802480
}

compiler/rustc_hir/src/intravisit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,7 @@ pub fn walk_assoc_item_constraint<'v, V: Visitor<'v>>(
12901290
match constraint.kind {
12911291
AssocItemConstraintKind::Equality { ref term } => match term {
12921292
Term::Ty(ref ty) => try_visit!(visitor.visit_ty(ty)),
1293-
Term::Const(ref c) => try_visit!(visitor.visit_anon_const(c)),
1293+
Term::Const(ref c) => try_visit!(visitor.visit_const_arg(c)),
12941294
},
12951295
AssocItemConstraintKind::Bound { bounds } => {
12961296
walk_list!(visitor, visit_param_bound, bounds)

compiler/rustc_hir_analysis/src/collect/type_of.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
224224
.iter()
225225
.copied()
226226
.filter_map(AssocItemConstraint::ct)
227-
.position(|ct| ct.hir_id == hir_id)
227+
.position(|ct| ct.anon_const_hir_id() == hir_id)
228228
.map(|idx| (idx, seg))
229229
})
230230
}) else {

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -413,12 +413,19 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
413413
});
414414

415415
// Provide the resolved type of the associated constant to `type_of(AnonConst)`.
416-
if let Some(anon_const) = constraint.ct() {
417-
let ty = alias_term
418-
.map_bound(|alias| tcx.type_of(alias.def_id).instantiate(tcx, alias.args));
419-
let ty =
420-
check_assoc_const_binding_type(self, constraint.ident, ty, constraint.hir_id);
421-
tcx.feed_anon_const_type(anon_const.def_id, ty::EarlyBinder::bind(ty));
416+
if let Some(const_arg) = constraint.ct() {
417+
#[allow(irrefutable_let_patterns)] // FIXME
418+
if let hir::ConstArgKind::Anon(anon_const) = const_arg.kind {
419+
let ty = alias_term
420+
.map_bound(|alias| tcx.type_of(alias.def_id).instantiate(tcx, alias.args));
421+
let ty = check_assoc_const_binding_type(
422+
self,
423+
constraint.ident,
424+
ty,
425+
constraint.hir_id,
426+
);
427+
tcx.feed_anon_const_type(anon_const.def_id, ty::EarlyBinder::bind(ty));
428+
}
422429
}
423430

424431
alias_term
@@ -435,7 +442,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
435442
hir::AssocItemConstraintKind::Equality { term } => {
436443
let term = match term {
437444
hir::Term::Ty(ty) => self.lower_ty(ty).into(),
438-
hir::Term::Const(ct) => ty::Const::from_anon_const(tcx, ct.def_id).into(),
445+
hir::Term::Const(ct) => {
446+
ty::Const::from_const_arg(tcx, ct, ty::FeedConstTy::No).into()
447+
}
439448
};
440449

441450
// Find any late-bound regions declared in `ty` that are not

compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
340340
{
341341
let span = match term {
342342
hir::Term::Ty(ty) => ty.span,
343-
hir::Term::Const(ct) => tcx.def_span(ct.def_id),
343+
hir::Term::Const(ct) => ct.span(),
344344
};
345345
(span, Some(ident.span), assoc_item.kind, assoc_kind)
346346
} else {
@@ -1296,8 +1296,7 @@ pub fn prohibit_assoc_item_constraint(
12961296
hir::AssocItemConstraintKind::Equality { term: hir::Term::Const(c) },
12971297
GenericParamDefKind::Const { .. },
12981298
) => {
1299-
let span = tcx.hir().span(c.hir_id);
1300-
suggest_direct_use(&mut err, span);
1299+
suggest_direct_use(&mut err, c.span());
13011300
}
13021301
(hir::AssocItemConstraintKind::Bound { bounds }, _) => {
13031302
// Suggest `impl<T: Bound> Trait<T> for Foo` when finding

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
911911
let term: ty::Term<'_> = match term {
912912
hir::Term::Ty(ty) => self.lower_ty(ty).into(),
913913
hir::Term::Const(ct) => {
914-
ty::Const::from_anon_const(tcx, ct.def_id).into()
914+
ty::Const::from_const_arg(tcx, ct, ty::FeedConstTy::No)
915+
.into()
915916
}
916917
};
917918
// FIXME(#97583): This isn't syntactically well-formed!

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1726,7 +1726,7 @@ impl<'a> State<'a> {
17261726
self.word_space("=");
17271727
match term {
17281728
Term::Ty(ty) => self.print_type(ty),
1729-
Term::Const(ref c) => self.print_anon_const(c),
1729+
Term::Const(ref c) => self.print_const_arg(c),
17301730
}
17311731
}
17321732
hir::AssocItemConstraintKind::Bound { bounds } => {

src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ fn clean_hir_term<'tcx>(term: &hir::Term<'tcx>, cx: &mut DocContext<'tcx>) -> Te
433433
match term {
434434
hir::Term::Ty(ty) => Term::Type(clean_ty(ty, cx)),
435435
hir::Term::Const(c) => Term::Constant(clean_middle_const(
436-
ty::Binder::dummy(ty::Const::from_anon_const(cx.tcx, c.def_id)),
436+
ty::Binder::dummy(ty::Const::from_const_arg(cx.tcx, c, ty::FeedConstTy::No)),
437437
cx,
438438
)),
439439
}

0 commit comments

Comments
 (0)