1
Fork 0

Rollup merge of #110566 - compiler-errors:bad-projection-term, r=cjgillot,BoxyUwU

Don't create projection ty for const projection

Fixes #110549
This commit is contained in:
Matthias Krüger 2023-04-24 07:53:24 +02:00 committed by GitHub
commit 8aab707131
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 8 deletions

View file

@ -1272,14 +1272,29 @@ fn project<'cx, 'tcx>(
ProjectionCandidateSet::Single(candidate) => {
Ok(Projected::Progress(confirm_candidate(selcx, obligation, candidate)))
}
ProjectionCandidateSet::None => Ok(Projected::NoProgress(
// FIXME(associated_const_generics): this may need to change in the future?
// need to investigate whether or not this is fine.
selcx
.tcx()
.mk_projection(obligation.predicate.def_id, obligation.predicate.substs)
.into(),
)),
ProjectionCandidateSet::None => {
let tcx = selcx.tcx();
let term = match tcx.def_kind(obligation.predicate.def_id) {
DefKind::AssocTy | DefKind::ImplTraitPlaceholder => tcx
.mk_projection(obligation.predicate.def_id, obligation.predicate.substs)
.into(),
DefKind::AssocConst => tcx
.mk_const(
ty::ConstKind::Unevaluated(ty::UnevaluatedConst::new(
obligation.predicate.def_id,
obligation.predicate.substs,
)),
tcx.type_of(obligation.predicate.def_id)
.subst(tcx, obligation.predicate.substs),
)
.into(),
kind => {
bug!("unknown projection def-id: {}", kind.descr(obligation.predicate.def_id))
}
};
Ok(Projected::NoProgress(term))
}
// Error occurred while trying to processing impls.
ProjectionCandidateSet::Error(e) => Err(ProjectionError::TraitSelectionError(e)),
// Inherent ambiguity that prevents us from even enumerating the