Skip to content

Commit 7143ef6

Browse files
Also in the new solver
1 parent 2d602ea commit 7143ef6

10 files changed

+57
-23
lines changed

Diff for: compiler/rustc_next_trait_solver/src/delegate.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ pub trait SolverDelegate: Deref<Target = <Self as SolverDelegate>::Infcx> + Size
9595
goal_trait_ref: ty::TraitRef<Self::Interner>,
9696
trait_assoc_def_id: <Self::Interner as Interner>::DefId,
9797
impl_def_id: <Self::Interner as Interner>::DefId,
98-
) -> Result<Option<<Self::Interner as Interner>::DefId>, NoSolution>;
98+
) -> Result<
99+
Option<<Self::Interner as Interner>::DefId>,
100+
<Self::Interner as Interner>::ErrorGuaranteed,
101+
>;
99102

100103
fn is_transmutable(
101104
&self,

Diff for: compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ where
950950
goal_trait_ref: ty::TraitRef<I>,
951951
trait_assoc_def_id: I::DefId,
952952
impl_def_id: I::DefId,
953-
) -> Result<Option<I::DefId>, NoSolution> {
953+
) -> Result<Option<I::DefId>, I::ErrorGuaranteed> {
954954
self.delegate.fetch_eligible_assoc_item(goal_trait_ref, trait_assoc_def_id, impl_def_id)
955955
}
956956

Diff for: compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs

+22-16
Original file line numberDiff line numberDiff line change
@@ -244,20 +244,7 @@ where
244244
.map(|pred| goal.with(cx, pred)),
245245
);
246246

247-
// In case the associated item is hidden due to specialization, we have to
248-
// return ambiguity this would otherwise be incomplete, resulting in
249-
// unsoundness during coherence (#105782).
250-
let Some(target_item_def_id) = ecx.fetch_eligible_assoc_item(
251-
goal_trait_ref,
252-
goal.predicate.def_id(),
253-
impl_def_id,
254-
)?
255-
else {
256-
return ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS);
257-
};
258-
259-
let error_response = |ecx: &mut EvalCtxt<'_, D>, msg: &str| {
260-
let guar = cx.delay_bug(msg);
247+
let error_response = |ecx: &mut EvalCtxt<'_, D>, guar| {
261248
let error_term = match goal.predicate.alias.kind(cx) {
262249
ty::AliasTermKind::ProjectionTy => Ty::new_error(cx, guar).into(),
263250
ty::AliasTermKind::ProjectionConst => Const::new_error(cx, guar).into(),
@@ -267,8 +254,24 @@ where
267254
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
268255
};
269256

257+
// In case the associated item is hidden due to specialization, we have to
258+
// return ambiguity this would otherwise be incomplete, resulting in
259+
// unsoundness during coherence (#105782).
260+
let target_item_def_id = match ecx.fetch_eligible_assoc_item(
261+
goal_trait_ref,
262+
goal.predicate.def_id(),
263+
impl_def_id,
264+
) {
265+
Ok(Some(target_item_def_id)) => target_item_def_id,
266+
Ok(None) => {
267+
return ecx
268+
.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS);
269+
}
270+
Err(guar) => return error_response(ecx, guar),
271+
};
272+
270273
if !cx.has_item_definition(target_item_def_id) {
271-
return error_response(ecx, "missing item");
274+
return error_response(ecx, cx.delay_bug("missing item"));
272275
}
273276

274277
let target_container_def_id = cx.parent(target_item_def_id);
@@ -292,7 +295,10 @@ where
292295
)?;
293296

294297
if !cx.check_args_compatible(target_item_def_id, target_args) {
295-
return error_response(ecx, "associated item has mismatched arguments");
298+
return error_response(
299+
ecx,
300+
cx.delay_bug("associated item has mismatched arguments"),
301+
);
296302
}
297303

298304
// Finally we construct the actual value of the associated type.

Diff for: compiler/rustc_trait_selection/src/solve/delegate.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,8 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate<
190190
goal_trait_ref: ty::TraitRef<'tcx>,
191191
trait_assoc_def_id: DefId,
192192
impl_def_id: DefId,
193-
) -> Result<Option<DefId>, NoSolution> {
194-
let node_item = specialization_graph::assoc_def(self.tcx, impl_def_id, trait_assoc_def_id)
195-
.map_err(|ErrorGuaranteed { .. }| NoSolution)?;
193+
) -> Result<Option<DefId>, ErrorGuaranteed> {
194+
let node_item = specialization_graph::assoc_def(self.tcx, impl_def_id, trait_assoc_def_id)?;
196195

197196
let eligible = if node_item.is_final() {
198197
// Non-specializable items are always projectable.

Diff for: tests/ui/traits/unconstrained-projection-normalization-2.stderr renamed to tests/ui/traits/unconstrained-projection-normalization-2.current.stderr

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

Diff for: tests/ui/traits/unconstrained-projection-normalization-2.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// an associated type in an impl with unconstrained non-lifetime params.
33
// (This time in a function signature)
44

5+
//@ revisions: current next
6+
//@ ignore-compare-mode-next-solver (explicit revisions)
7+
//@[next] compile-flags: -Znext-solver
8+
59
struct Thing;
610

711
pub trait Every {

Diff for: tests/ui/traits/unconstrained-projection-normalization.stderr renamed to tests/ui/traits/unconstrained-projection-normalization.current.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
2-
--> $DIR/unconstrained-projection-normalization.rs:9:6
2+
--> $DIR/unconstrained-projection-normalization.rs:13:6
33
|
44
LL | impl<T: ?Sized> Every for Thing {
55
| ^ unconstrained type parameter
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
2+
--> $DIR/unconstrained-projection-normalization.rs:13:6
3+
|
4+
LL | impl<T: ?Sized> Every for Thing {
5+
| ^ unconstrained type parameter
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0207`.

Diff for: tests/ui/traits/unconstrained-projection-normalization.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Make sure we don't ICE in `normalize_erasing_regions` when normalizing
22
// an associated type in an impl with unconstrained non-lifetime params.
33

4+
//@ revisions: current next
5+
//@ ignore-compare-mode-next-solver (explicit revisions)
6+
//@[next] compile-flags: -Znext-solver
7+
48
struct Thing;
59

610
pub trait Every {

0 commit comments

Comments
 (0)