Skip to content

Commit cde5bca

Browse files
Don't create projection ty for const projection
1 parent 915aa06 commit cde5bca

File tree

3 files changed

+56
-8
lines changed

3 files changed

+56
-8
lines changed

compiler/rustc_trait_selection/src/traits/project.rs

+23-8
Original file line numberDiff line numberDiff line change
@@ -1272,14 +1272,29 @@ fn project<'cx, 'tcx>(
12721272
ProjectionCandidateSet::Single(candidate) => {
12731273
Ok(Projected::Progress(confirm_candidate(selcx, obligation, candidate)))
12741274
}
1275-
ProjectionCandidateSet::None => Ok(Projected::NoProgress(
1276-
// FIXME(associated_const_generics): this may need to change in the future?
1277-
// need to investigate whether or not this is fine.
1278-
selcx
1279-
.tcx()
1280-
.mk_projection(obligation.predicate.def_id, obligation.predicate.substs)
1281-
.into(),
1282-
)),
1275+
ProjectionCandidateSet::None => {
1276+
let tcx = selcx.tcx();
1277+
let term = match tcx.def_kind(obligation.predicate.def_id) {
1278+
DefKind::AssocTy | DefKind::ImplTraitPlaceholder => tcx
1279+
.mk_projection(obligation.predicate.def_id, obligation.predicate.substs)
1280+
.into(),
1281+
DefKind::AssocConst => tcx
1282+
.mk_const(
1283+
ty::ConstKind::Unevaluated(ty::UnevaluatedConst::new(
1284+
obligation.predicate.def_id,
1285+
obligation.predicate.substs,
1286+
)),
1287+
tcx.type_of(obligation.predicate.def_id)
1288+
.subst(tcx, obligation.predicate.substs),
1289+
)
1290+
.into(),
1291+
kind => {
1292+
bug!("unknown projection def-id: {}", kind.descr(obligation.predicate.def_id))
1293+
}
1294+
};
1295+
1296+
Ok(Projected::NoProgress(term))
1297+
}
12831298
// Error occurred while trying to processing impls.
12841299
ProjectionCandidateSet::Error(e) => Err(ProjectionError::TraitSelectionError(e)),
12851300
// Inherent ambiguity that prevents us from even enumerating the
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![feature(associated_const_equality)]
2+
3+
// Issue 110549
4+
5+
pub trait TraitWAssocConst {
6+
const A: usize;
7+
}
8+
9+
fn foo<T: TraitWAssocConst<A = 32>>() {}
10+
11+
fn bar<T: TraitWAssocConst>() {
12+
foo::<T>();
13+
//~^ ERROR type mismatch resolving `<T as TraitWAssocConst>::A == 32`
14+
}
15+
16+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0271]: type mismatch resolving `<T as TraitWAssocConst>::A == 32`
2+
--> $DIR/projection-unspecified-but-bounded.rs:12:11
3+
|
4+
LL | foo::<T>();
5+
| ^ expected `32`, found `<T as TraitWAssocConst>::A`
6+
|
7+
= note: expected constant `32`
8+
found constant `<T as TraitWAssocConst>::A`
9+
note: required by a bound in `foo`
10+
--> $DIR/projection-unspecified-but-bounded.rs:9:28
11+
|
12+
LL | fn foo<T: TraitWAssocConst<A = 32>>() {}
13+
| ^^^^^^ required by this bound in `foo`
14+
15+
error: aborting due to previous error
16+
17+
For more information about this error, try `rustc --explain E0271`.

0 commit comments

Comments
 (0)