Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
15 changes: 14 additions & 1 deletion compiler/rustc_next_trait_solver/src/canonical/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,20 @@ where
let prev_universe = delegate.universe();
let universes_created_in_query = response.max_universe.index();
for _ in 0..universes_created_in_query {
delegate.create_next_universe();
let new_universe = delegate.create_next_universe();
if delegate.cx().assumptions_on_binders() {
// FIXME(-Zassumptions-on-binders): Remove this temporary workaround once
// opaque types no longer escape query responses with query-created placeholders.
// Region constraints involving query-created placeholders were handled inside
// the query. However, the placeholders can still escape in other response
// fields, such as opaque type constraints. To avoid triggering
// assertions, we explicitly insert empty assumptions for the
// recreated universes here.
delegate.insert_placeholder_assumptions(
new_universe,
Some(rustc_type_ir::region_constraint::Assumptions::empty()),
);
}
}

let var_values = response.value.var_values();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//@ compile-flags: -Znext-solver=globally -Zassumptions-on-binders

#![feature(type_alias_impl_trait)]

// Regression test for #159889. Normalizing `FooAssoc<'a>` returns an opaque type constraint
// containing a query-created placeholder. Applying that response recreates its universe in the
// caller, where it must have an assumptions entry before eager placeholder handling visits it.
//
// Adding `impl Trait for ()` to this same shape still ICEs on nightly (same
// `assumptions` unwrap). A separately rewritten check-pass does not hit this path, so it is not
// a useful regression guard.

trait Trait {
type Assoc<'a>;
}

type Foo = impl for<'a> Trait<Assoc<'a> = FooAssoc<'a>>;
type FooAssoc<'a> = impl ?Sized;

#[define_opaque(Foo)]
fn foo() -> Foo {}
//~^ ERROR the trait bound `(): Trait` is not satisfied

@lcnr lcnr Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

does this test also work if you actually implement (): Trait seems preferable to me to have a check-pass test here 🤔

View changes since the review

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.

I restored the original test as the ICE regression guard and added a separate check-pass case with impl Trait for (), btw. fyi, removing the workaround locally makes the original test ICE again. I think keeping both tests separate is safer; idk if combining them is worth running into the opaque defining-use issue again. ltm if you see a cleaner way.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh, so the test with (): Trait does not ICE on nightly? In this case, please mention that in the comment of the actual regression test and I don't think we need to add the test where (): Trait does hold then.

I think that it's nicer to have tests to only encounter as few errors as possible, as the behavior of rustc gets a lot less predictable once a first error happens, which makes it easier to accidentally stop testing the underlying issue in the future.

But if the test actually needs (): Trait to not hold for the ICE to trigger, then keeping that as the only test makes sense to me

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.

ah, so that was me being unclear earlier, sorry. checked on nightly: same shape with impl Trait for () still ICEs (same unwrap). the check-pass was a different program that never hit that path, so it looked fine. dropped it and left a note on the regression test. ltm if that works

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

okay, so if it also ICEs with this impl, please add the impl so that the test doesn't have an error that's unrelated to the thing this is testing.

What do you mean with "A separately rewritten check-pass does not hit this path, so it is not a useful regression guard". Saying that does not feel like useful information to any future readers

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.

make sense, that comment was useless for future readers, my bad. removed it.

also added impl Trait for () (+ ?Sized) so we don't hit the unrelated Trait error. still ICEs on nightly with that shape, fyi. after the fix it just fails with the opaque "does not constrain" error instead, which imo is fine for a regression guard.

idk if we can make this check-pass without losing the ICE path, btw. every time I tried to make the defining use "real" enough it stopped ICEing. so I kept the minimal shape.

ltm if that looks good


fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0277]: the trait bound `(): Trait` is not satisfied
--> $DIR/canonical-response-placeholder-assumptions-issue-159889.rs:17:13
|
LL | fn foo() -> Foo {}
| ^^^ the trait `Trait` is not implemented for `()`
|
help: this trait has no implementations, consider adding one
--> $DIR/canonical-response-placeholder-assumptions-issue-159889.rs:9:1
|
LL | trait Trait {
| ^^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.
Loading