1
Fork 0

Also in the new solver

This commit is contained in:
Michael Goulet 2025-01-03 05:22:14 +00:00
parent 2d602ea793
commit 7143ef6550
10 changed files with 57 additions and 23 deletions

View file

@ -95,7 +95,10 @@ pub trait SolverDelegate: Deref<Target = <Self as SolverDelegate>::Infcx> + Size
goal_trait_ref: ty::TraitRef<Self::Interner>,
trait_assoc_def_id: <Self::Interner as Interner>::DefId,
impl_def_id: <Self::Interner as Interner>::DefId,
) -> Result<Option<<Self::Interner as Interner>::DefId>, NoSolution>;
) -> Result<
Option<<Self::Interner as Interner>::DefId>,
<Self::Interner as Interner>::ErrorGuaranteed,
>;
fn is_transmutable(
&self,

View file

@ -950,7 +950,7 @@ where
goal_trait_ref: ty::TraitRef<I>,
trait_assoc_def_id: I::DefId,
impl_def_id: I::DefId,
) -> Result<Option<I::DefId>, NoSolution> {
) -> Result<Option<I::DefId>, I::ErrorGuaranteed> {
self.delegate.fetch_eligible_assoc_item(goal_trait_ref, trait_assoc_def_id, impl_def_id)
}

View file

@ -244,20 +244,7 @@ where
.map(|pred| goal.with(cx, pred)),
);
// In case the associated item is hidden due to specialization, we have to
// return ambiguity this would otherwise be incomplete, resulting in
// unsoundness during coherence (#105782).
let Some(target_item_def_id) = ecx.fetch_eligible_assoc_item(
goal_trait_ref,
goal.predicate.def_id(),
impl_def_id,
)?
else {
return ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS);
};
let error_response = |ecx: &mut EvalCtxt<'_, D>, msg: &str| {
let guar = cx.delay_bug(msg);
let error_response = |ecx: &mut EvalCtxt<'_, D>, guar| {
let error_term = match goal.predicate.alias.kind(cx) {
ty::AliasTermKind::ProjectionTy => Ty::new_error(cx, guar).into(),
ty::AliasTermKind::ProjectionConst => Const::new_error(cx, guar).into(),
@ -267,8 +254,24 @@ where
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
};
// In case the associated item is hidden due to specialization, we have to
// return ambiguity this would otherwise be incomplete, resulting in
// unsoundness during coherence (#105782).
let target_item_def_id = match ecx.fetch_eligible_assoc_item(
goal_trait_ref,
goal.predicate.def_id(),
impl_def_id,
) {
Ok(Some(target_item_def_id)) => target_item_def_id,
Ok(None) => {
return ecx
.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS);
}
Err(guar) => return error_response(ecx, guar),
};
if !cx.has_item_definition(target_item_def_id) {
return error_response(ecx, "missing item");
return error_response(ecx, cx.delay_bug("missing item"));
}
let target_container_def_id = cx.parent(target_item_def_id);
@ -292,7 +295,10 @@ where
)?;
if !cx.check_args_compatible(target_item_def_id, target_args) {
return error_response(ecx, "associated item has mismatched arguments");
return error_response(
ecx,
cx.delay_bug("associated item has mismatched arguments"),
);
}
// Finally we construct the actual value of the associated type.

View file

@ -190,9 +190,8 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate<
goal_trait_ref: ty::TraitRef<'tcx>,
trait_assoc_def_id: DefId,
impl_def_id: DefId,
) -> Result<Option<DefId>, NoSolution> {
let node_item = specialization_graph::assoc_def(self.tcx, impl_def_id, trait_assoc_def_id)
.map_err(|ErrorGuaranteed { .. }| NoSolution)?;
) -> Result<Option<DefId>, ErrorGuaranteed> {
let node_item = specialization_graph::assoc_def(self.tcx, impl_def_id, trait_assoc_def_id)?;
let eligible = if node_item.is_final() {
// Non-specializable items are always projectable.

View file

@ -1,5 +1,5 @@
error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
--> $DIR/unconstrained-projection-normalization-2.rs:10:6
--> $DIR/unconstrained-projection-normalization-2.rs:14:6
|
LL | impl<T: ?Sized> Every for Thing {
| ^ unconstrained type parameter

View file

@ -0,0 +1,9 @@
error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
--> $DIR/unconstrained-projection-normalization-2.rs:14:6
|
LL | impl<T: ?Sized> Every for Thing {
| ^ unconstrained type parameter
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0207`.

View file

@ -2,6 +2,10 @@
// an associated type in an impl with unconstrained non-lifetime params.
// (This time in a function signature)
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver
struct Thing;
pub trait Every {

View file

@ -1,5 +1,5 @@
error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
--> $DIR/unconstrained-projection-normalization.rs:9:6
--> $DIR/unconstrained-projection-normalization.rs:13:6
|
LL | impl<T: ?Sized> Every for Thing {
| ^ unconstrained type parameter

View file

@ -0,0 +1,9 @@
error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
--> $DIR/unconstrained-projection-normalization.rs:13:6
|
LL | impl<T: ?Sized> Every for Thing {
| ^ unconstrained type parameter
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0207`.

View file

@ -1,6 +1,10 @@
// Make sure we don't ICE in `normalize_erasing_regions` when normalizing
// an associated type in an impl with unconstrained non-lifetime params.
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver
struct Thing;
pub trait Every {