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
Original file line number Diff line number Diff line change
Expand Up @@ -890,9 +890,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
}

if let Ok(Some(ImplSource::UserDefined(impl_data))) =
self.enter_forall(trait_ref, |trait_ref_for_select| {
SelectionContext::new(self).select(&obligation.with(self.tcx, trait_ref_for_select))
})
SelectionContext::new(self).poly_select(&obligation.with(self.tcx, trait_ref))
{
let impl_did = impl_data.impl_def_id;
let trait_did = trait_ref.def_id();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6022,19 +6022,12 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
{
self.probe(|_| {
let ocx = ObligationCtxt::new(self);
self.enter_forall(pred, |pred| {
let pred = ocx.normalize(
&ObligationCause::dummy(),
param_env,
Unnormalized::new_wip(pred),
);
ocx.register_obligation(Obligation::new(
self.tcx,
ObligationCause::dummy(),
param_env,
pred,
));
});
ocx.register_obligation(Obligation::new(
self.tcx,
ObligationCause::dummy(),
param_env,
pred,
));
if !ocx.try_evaluate_obligations().no_errors() {
// encountered errors.
return;
Expand Down
6 changes: 3 additions & 3 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,
Selection, SelectionError, SelectionResult, TraitObligation,
PolyTraitObligation, Selection, SelectionError, SelectionResult,
};
use rustc_macros::extension;
use rustc_middle::{bug, span_bug};
Expand All @@ -16,10 +16,10 @@ use crate::solve::inspect::{self, InferCtxtProofTreeExt};

#[extension(pub trait InferCtxtSelectExt<'tcx>)]
impl<'tcx> InferCtxt<'tcx> {
/// Do not use this directly. This is called from [`crate::traits::SelectionContext::select`].
/// Do not use this directly. This is called from [`crate::traits::SelectionContext::poly_select`].
fn select_in_new_trait_solver(
&self,
obligation: &TraitObligation<'tcx>,
obligation: &PolyTraitObligation<'tcx>,
) -> SelectionResult<'tcx, Selection<'tcx>> {
assert!(self.next_trait_solver());

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

let candidate = match self.select_from_obligation(obligation) {
Err(SelectionError::Overflow(OverflowError::Canonical)) => {
Expand Down Expand Up @@ -292,10 +294,6 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ LL | call(f, ());
|
= note: expected a closure with signature `for<'a> fn(<_ as ATC<'a>>::Type)`
found a closure with signature `fn(())`
note: this is a known limitation of the trait solver that will be lifted in the future
--> $DIR/issue-62529-3.rs:25:14
|
LL | call(f, ());
| -----^-----
| | |
| | the trait solver is unable to infer the generic types that should be inferred from this argument
| add turbofish arguments to this call to specify the types manually, even if it's redundant

@sjwang05 sjwang05 Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is kind of a diagnostics regression, since before, we called ocx.normalize on the obligation before registering it, whereas now it doesn't seem like we can handle the unnormalized <Self as ATC<'a>>::Type inside the binder if it's not normalized beforehand.

View changes since the review

note: required by a bound in `call`
--> $DIR/issue-62529-3.rs:9:36
|
Expand Down
16 changes: 0 additions & 16 deletions tests/ui/mismatched_types/closure-mismatch.next.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ LL | baz(|_| ());
= help: the trait `for<'a> FnOnce(&'a ())` is not implemented for closure `{closure@$DIR/closure-mismatch.rs:12:9: 12:12}`
= note: expected a closure with signature `for<'a> fn(&'a ())`
found a closure with signature `fn(&())`
note: this is a known limitation of the trait solver that will be lifted in the future
--> $DIR/closure-mismatch.rs:12:9
|
LL | baz(|_| ());
| ----^^^----
| | |
| | the trait solver is unable to infer the generic types that should be inferred from this argument
| add turbofish arguments to this call to specify the types manually, even if it's redundant
note: required for `{closure@$DIR/closure-mismatch.rs:12:9: 12:12}` to implement `Foo`
--> $DIR/closure-mismatch.rs:7:18
|
Expand All @@ -41,14 +33,6 @@ LL | baz(|x| ());
= help: the trait `for<'a> FnOnce(&'a ())` is not implemented for closure `{closure@$DIR/closure-mismatch.rs:16:9: 16:12}`
= note: expected a closure with signature `for<'a> fn(&'a ())`
found a closure with signature `fn(&())`
note: this is a known limitation of the trait solver that will be lifted in the future
--> $DIR/closure-mismatch.rs:16:9
|
LL | baz(|x| ());
| ----^^^----
| | |
| | the trait solver is unable to infer the generic types that should be inferred from this argument
| add turbofish arguments to this call to specify the types manually, even if it's redundant
note: required for `{closure@$DIR/closure-mismatch.rs:16:9: 16:12}` to implement `Foo`
--> $DIR/closure-mismatch.rs:7:18
|
Expand Down
28 changes: 28 additions & 0 deletions tests/ui/traits/non_lifetime_binders/universe-error-host-effect.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//@ compile-flags: -Znext-solver

#![feature(const_trait_impl, non_lifetime_binders, sized_hierarchy)]
#![allow(incomplete_features)]

use std::marker::PointeeSized;

const trait Other<U: PointeeSized, V: PointeeSized>: PointeeSized {}

trait Guard {}

const impl<X: PointeeSized> Other<X, i32> for X {}

impl<X: PointeeSized> Other<u8, u32> for X where u8: Guard {}
//~^ ERROR the trait bound `u8: Guard` is not satisfied

fn foo<U: PointeeSized, V: PointeeSized>()
where
for<T> T: const Other<U, V>,
{
}

fn bar() {
foo::<_, _>();
//~^ ERROR the trait bound `u8: Guard` is not satisfied
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
error[E0277]: the trait bound `u8: Guard` is not satisfied
--> $DIR/universe-error-host-effect.rs:14:50
|
LL | impl<X: PointeeSized> Other<u8, u32> for X where u8: Guard {}
| ^^^^^^^^^ the trait `Guard` is not implemented for `u8`
|
help: this trait has no implementations, consider adding one
--> $DIR/universe-error-host-effect.rs:10:1
|
LL | trait Guard {}
| ^^^^^^^^^^^
help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
|
LL + #![feature(trivial_bounds)]
|

error[E0277]: the trait bound `u8: Guard` is not satisfied
--> $DIR/universe-error-host-effect.rs:24:11
|
LL | foo::<_, _>();
| ^ the trait `Guard` is not implemented for `u8`
|
help: this trait has no implementations, consider adding one
--> $DIR/universe-error-host-effect.rs:10:1
|
LL | trait Guard {}
| ^^^^^^^^^^^
note: required for `T` to implement `Other<u8, u32>`
--> $DIR/universe-error-host-effect.rs:14:23
|
LL | impl<X: PointeeSized> Other<u8, u32> for X where u8: Guard {}
| ^^^^^^^^^^^^^^ ^ ----- unsatisfied trait bound introduced here
note: required by a bound in `foo`
--> $DIR/universe-error-host-effect.rs:19:15
|
LL | fn foo<U: PointeeSized, V: PointeeSized>()
| --- required by a bound in this function
LL | where
LL | for<T> T: const Other<U, V>,
| ^^^^^^^^^^^^^^^^^ required by this bound in `foo`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0277`.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0277]: the trait bound `T: Other<_>` is not satisfied
--> $DIR/universe-error1.rs:16:11
--> $DIR/universe-error1.rs:20:11
|
LL | foo::<_>();
| ^ the trait `Other<_>` is not implemented for `T`
|
note: required by a bound in `foo`
--> $DIR/universe-error1.rs:13:15
--> $DIR/universe-error1.rs:17:15
|
LL | fn foo<U: PointeeSized>()
| --- required by a bound in this function
Expand Down
18 changes: 18 additions & 0 deletions tests/ui/traits/non_lifetime_binders/universe-error1.next.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error[E0277]: the trait bound `T: Other<_>` is not satisfied
--> $DIR/universe-error1.rs:20:11
|
LL | foo::<_>();
| ^ the trait `Other<_>` is not implemented for `T`
|
note: required by a bound in `foo`
--> $DIR/universe-error1.rs:17:15
|
LL | fn foo<U: PointeeSized>()
| --- required by a bound in this function
LL | where
LL | for<T> T: Other<U> {}
| ^^^^^^^^ required by this bound in `foo`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.
4 changes: 4 additions & 0 deletions tests/ui/traits/non_lifetime_binders/universe-error1.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver

#![feature(sized_hierarchy)]
#![feature(non_lifetime_binders)]

Expand Down
Loading