Skip to content

Commit c4c9ddc

Browse files
committed
resolved merge conflicts
1 parent c28e303 commit c4c9ddc

2 files changed

Lines changed: 28 additions & 22 deletions

File tree

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -541,19 +541,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
541541
hir::AssocItemConstraintKind::Equality { term } => {
542542
let term = match term {
543543
hir::Term::Ty(ty) => self.lower_ty(ty).into(),
544-
hir::Term::Const(ct) => {
545-
let ty = projection_term.map_bound(|alias| {
546-
tcx.type_of(alias.def_id).instantiate(tcx, alias.args).skip_norm_wip()
547-
});
548-
let ty = check_assoc_const_binding_type(
549-
self,
544+
hir::Term::Const(ct) => self
545+
.lower_assoc_const_binding_rhs(
546+
ct,
550547
constraint.ident,
551-
ty,
552548
constraint.hir_id,
553-
);
554-
555-
self.lower_const_arg(ct, ty).into()
556-
}
549+
projection_term,
550+
)
551+
.into(),
557552
};
558553

559554
// Find any late-bound regions declared in `ty` that are not
@@ -853,6 +848,23 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
853848
let shifted_output = tcx.shift_bound_var_indices(num_bound_vars, output);
854849
Ok(ty::EarlyBinder::bind(shifted_output).instantiate(tcx, args).skip_norm_wip())
855850
}
851+
852+
/// Derives the expected type of an associated const,
853+
/// validates it, and lowers the RHS const arg against that type
854+
pub(crate) fn lower_assoc_const_binding_rhs(
855+
&self,
856+
ct: &'tcx hir::ConstArg<'tcx>,
857+
assoc_ident: Ident,
858+
constraint_hir_id: hir::HirId,
859+
projection_term: ty::Binder<'tcx, ty::AliasTerm<'tcx>>,
860+
) -> ty::Const<'tcx> {
861+
let tcx = self.tcx();
862+
let ty = projection_term.map_bound(|alias| {
863+
tcx.type_of(alias.def_id).instantiate(tcx, alias.args).skip_norm_wip()
864+
});
865+
let ty = check_assoc_const_binding_type(self, assoc_ident, ty, constraint_hir_id);
866+
self.lower_const_arg(ct, ty)
867+
}
856868
}
857869

858870
/// Detect and reject early-bound & escaping late-bound generic params in the type of assoc const bindings.

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,19 +1373,13 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
13731373

13741374
// FIXME(mgca): code duplication with other places we lower
13751375
// the rhs' of associated const bindings
1376-
let ty = projection_term.map_bound(|alias| {
1377-
tcx.type_of(alias.def_id)
1378-
.instantiate(tcx, alias.args)
1379-
.skip_norm_wip()
1380-
});
1381-
let ty = bounds::check_assoc_const_binding_type(
1382-
self,
1376+
self.lower_assoc_const_binding_rhs(
1377+
ct,
13831378
constraint.ident,
1384-
ty,
13851379
constraint.hir_id,
1386-
);
1387-
1388-
self.lower_const_arg(ct, ty).into()
1380+
projection_term,
1381+
)
1382+
.into()
13891383
}
13901384
};
13911385
if term.references_error() {

0 commit comments

Comments
 (0)