Skip to content

Commit 580bd6e

Browse files
authored
Rollup merge of rust-lang#141390 - compiler-errors:poly-select-new-solver, r=lcnr
Don't allow `poly_select` in new solver I added a `poly_select` call in rust-lang#140519, but this causes an ICE since the new solver doesn't properly handle the "instantiate binder -> recanonicalize" step in the proof tree visitor. While we could fix the select visitor to look at the next step in proof tree, it's not really necessary. Instead, let's enforce that all callees call the non-higher-ranked `select` function in the new solver. Fixes rust-lang#141322 r? lcnr
2 parents abba164 + 16b6ffe commit 580bd6e

File tree

6 files changed

+69
-10
lines changed

6 files changed

+69
-10
lines changed

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,11 +1501,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
15011501
return None;
15021502
};
15031503

1504-
let Ok(Some(ImplSource::UserDefined(impl_data))) = SelectionContext::new(self)
1505-
.poly_select(&obligation.with(
1506-
self.tcx,
1507-
predicate.kind().rebind(proj.projection_term.trait_ref(self.tcx)),
1508-
))
1504+
let trait_ref = self.enter_forall_and_leak_universe(
1505+
predicate.kind().rebind(proj.projection_term.trait_ref(self.tcx)),
1506+
);
1507+
let Ok(Some(ImplSource::UserDefined(impl_data))) =
1508+
SelectionContext::new(self).select(&obligation.with(self.tcx, trait_ref))
15091509
else {
15101510
return None;
15111511
};

compiler/rustc_trait_selection/src/solve/select.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_infer::traits::solve::inspect::ProbeKind;
55
use rustc_infer::traits::solve::{CandidateSource, Certainty, Goal};
66
use rustc_infer::traits::{
77
BuiltinImplSource, ImplSource, ImplSourceUserDefinedData, Obligation, ObligationCause,
8-
PolyTraitObligation, Selection, SelectionError, SelectionResult,
8+
Selection, SelectionError, SelectionResult, TraitObligation,
99
};
1010
use rustc_macros::extension;
1111
use rustc_middle::{bug, span_bug};
@@ -17,7 +17,7 @@ use crate::solve::inspect::{self, ProofTreeInferCtxtExt};
1717
impl<'tcx> InferCtxt<'tcx> {
1818
fn select_in_new_trait_solver(
1919
&self,
20-
obligation: &PolyTraitObligation<'tcx>,
20+
obligation: &TraitObligation<'tcx>,
2121
) -> SelectionResult<'tcx, Selection<'tcx>> {
2222
assert!(self.next_trait_solver());
2323

compiler/rustc_trait_selection/src/traits/select/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
265265
&mut self,
266266
obligation: &PolyTraitObligation<'tcx>,
267267
) -> SelectionResult<'tcx, Selection<'tcx>> {
268-
if self.infcx.next_trait_solver() {
269-
return self.infcx.select_in_new_trait_solver(obligation);
270-
}
268+
assert!(!self.infcx.next_trait_solver());
271269

272270
let candidate = match self.select_from_obligation(obligation) {
273271
Err(SelectionError::Overflow(OverflowError::Canonical)) => {
@@ -299,6 +297,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
299297
&mut self,
300298
obligation: &TraitObligation<'tcx>,
301299
) -> SelectionResult<'tcx, Selection<'tcx>> {
300+
if self.infcx.next_trait_solver() {
301+
return self.infcx.select_in_new_trait_solver(obligation);
302+
}
303+
302304
self.poly_select(&Obligation {
303305
cause: obligation.cause.clone(),
304306
param_env: obligation.param_env,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/hr-projection-mismatch.rs:20:5
3+
|
4+
LL | wrap::<_, Thing>();
5+
| ^^^^^^^^^^^^^^^^ one type is more general than the other
6+
|
7+
= note: expected reference `&'a _`
8+
found reference `&_`
9+
10+
error: aborting due to 1 previous error
11+
12+
For more information about this error, try `rustc --explain E0308`.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0271]: type mismatch resolving `<Thing as Trait<'a>>::Assoc == &i32`
2+
--> $DIR/hr-projection-mismatch.rs:20:15
3+
|
4+
LL | wrap::<_, Thing>();
5+
| ^^^^^ type mismatch resolving `<Thing as Trait<'a>>::Assoc == &i32`
6+
|
7+
note: types differ
8+
--> $DIR/hr-projection-mismatch.rs:14:18
9+
|
10+
LL | type Assoc = &'a i32;
11+
| ^^^^^^^
12+
note: required by a bound in `wrap`
13+
--> $DIR/hr-projection-mismatch.rs:17:33
14+
|
15+
LL | fn wrap<T, U: for<'a> Trait<'a, Assoc = T>>() {}
16+
| ^^^^^^^^^ required by this bound in `wrap`
17+
18+
error: aborting due to 1 previous error
19+
20+
For more information about this error, try `rustc --explain E0271`.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//@ revisions: current next
2+
//@ ignore-compare-mode-next-solver (explicit revisions)
3+
//@[next] compile-flags: -Znext-solver
4+
5+
// Regression test for <https://github.com/rust-lang/rust/issues/141322>.
6+
7+
trait Trait<'a> {
8+
type Assoc;
9+
}
10+
11+
struct Thing;
12+
13+
impl<'a> Trait<'a> for Thing {
14+
type Assoc = &'a i32;
15+
}
16+
17+
fn wrap<T, U: for<'a> Trait<'a, Assoc = T>>() {}
18+
19+
fn foo() {
20+
wrap::<_, Thing>();
21+
//[next]~^ ERROR type mismatch resolving `<Thing as Trait<'a>>::Assoc == &i32
22+
//[current]~^^ ERROR mismatched types
23+
}
24+
25+
fn main() {}

0 commit comments

Comments
 (0)