Skip to content

Don't allow poly_select in new solver #141390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -1503,11 +1503,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
return None;
};

let Ok(Some(ImplSource::UserDefined(impl_data))) = SelectionContext::new(self)
.poly_select(&obligation.with(
self.tcx,
predicate.kind().rebind(proj.projection_term.trait_ref(self.tcx)),
))
let trait_ref = self.enter_forall_and_leak_universe(
predicate.kind().rebind(proj.projection_term.trait_ref(self.tcx)),
);
let Ok(Some(ImplSource::UserDefined(impl_data))) =
SelectionContext::new(self).select(&obligation.with(self.tcx, trait_ref))
else {
return None;
};
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_trait_selection/src/solve/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rustc_infer::traits::solve::inspect::ProbeKind;
use rustc_infer::traits::solve::{CandidateSource, Certainty, Goal};
use rustc_infer::traits::{
BuiltinImplSource, ImplSource, ImplSourceUserDefinedData, Obligation, ObligationCause,
PolyTraitObligation, Selection, SelectionError, SelectionResult,
Selection, SelectionError, SelectionResult, TraitObligation,
};
use rustc_macros::extension;
use rustc_middle::{bug, span_bug};
Expand All @@ -17,7 +17,7 @@ use crate::solve::inspect::{self, ProofTreeInferCtxtExt};
impl<'tcx> InferCtxt<'tcx> {
fn select_in_new_trait_solver(
&self,
obligation: &PolyTraitObligation<'tcx>,
obligation: &TraitObligation<'tcx>,
) -> SelectionResult<'tcx, Selection<'tcx>> {
assert!(self.next_trait_solver());

Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
&mut self,
obligation: &PolyTraitObligation<'tcx>,
) -> SelectionResult<'tcx, Selection<'tcx>> {
if self.infcx.next_trait_solver() {
return self.infcx.select_in_new_trait_solver(obligation);
}
assert!(!self.infcx.next_trait_solver());

let candidate = match self.select_from_obligation(obligation) {
Err(SelectionError::Overflow(OverflowError::Canonical)) => {
Expand Down Expand Up @@ -299,6 +297,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
&mut self,
obligation: &TraitObligation<'tcx>,
) -> SelectionResult<'tcx, Selection<'tcx>> {
if self.infcx.next_trait_solver() {
return self.infcx.select_in_new_trait_solver(obligation);
}

self.poly_select(&Obligation {
cause: obligation.cause.clone(),
param_env: obligation.param_env,
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/mismatched_types/hr-projection-mismatch.current.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0308]: mismatched types
--> $DIR/hr-projection-mismatch.rs:20:5
|
LL | wrap::<_, Thing>();
| ^^^^^^^^^^^^^^^^ one type is more general than the other
|
= note: expected reference `&'a _`
found reference `&_`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.
20 changes: 20 additions & 0 deletions tests/ui/mismatched_types/hr-projection-mismatch.next.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error[E0271]: type mismatch resolving `<Thing as Trait<'a>>::Assoc == &i32`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird error message lol

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but unrelated, probably would be nice to have a leak-check specific error message or sth.

--> $DIR/hr-projection-mismatch.rs:20:15
|
LL | wrap::<_, Thing>();
| ^^^^^ type mismatch resolving `<Thing as Trait<'a>>::Assoc == &i32`
|
note: types differ
--> $DIR/hr-projection-mismatch.rs:14:18
|
LL | type Assoc = &'a i32;
| ^^^^^^^
note: required by a bound in `wrap`
--> $DIR/hr-projection-mismatch.rs:17:33
|
LL | fn wrap<T, U: for<'a> Trait<'a, Assoc = T>>() {}
| ^^^^^^^^^ required by this bound in `wrap`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0271`.
25 changes: 25 additions & 0 deletions tests/ui/mismatched_types/hr-projection-mismatch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver

// Regression test for <https://github.com/rust-lang/rust/issues/141322>.

trait Trait<'a> {
type Assoc;
}

struct Thing;

impl<'a> Trait<'a> for Thing {
type Assoc = &'a i32;
}

fn wrap<T, U: for<'a> Trait<'a, Assoc = T>>() {}

fn foo() {
wrap::<_, Thing>();
//[next]~^ ERROR type mismatch resolving `<Thing as Trait<'a>>::Assoc == &i32
//[current]~^^ ERROR mismatched types
}

fn main() {}
Loading