Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions compiler/rustc_trait_selection/src/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions tests/ui/associated-consts/projection-unspecified-but-bounded.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#![feature(associated_const_equality)]

// Issue 110549

pub trait TraitWAssocConst {
const A: usize;
}

fn foo<T: TraitWAssocConst<A = 32>>() {}

fn bar<T: TraitWAssocConst>() {
foo::<T>();
//~^ ERROR type mismatch resolving `<T as TraitWAssocConst>::A == 32`
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error[E0271]: type mismatch resolving `<T as TraitWAssocConst>::A == 32`
--> $DIR/projection-unspecified-but-bounded.rs:12:11
|
LL | foo::<T>();
| ^ expected `32`, found `<T as TraitWAssocConst>::A`
|
= note: expected constant `32`
found constant `<T as TraitWAssocConst>::A`
note: required by a bound in `foo`
--> $DIR/projection-unspecified-but-bounded.rs:9:28
|
LL | fn foo<T: TraitWAssocConst<A = 32>>() {}
| ^^^^^^ required by this bound in `foo`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0271`.