Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 7 additions & 1 deletion compiler/rustc_next_trait_solver/src/canonical/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,13 @@ 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() {

@BoxyUwU BoxyUwU Jul 22, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

was there an example that required this? the fixme above about "should deal with all placeholders created inside of the query directly" is actually what -Zassumptions-on-binders is implementing so ideally this would actually be wholly unnecessary under -Zassumptions-on-binders 🤔

If this change isn't necessary for the replace_bound_vars fix can we drop it from this PR so I can r+ it :3

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.

yeah, there wasn't a separate example requiring this btw. i added it defensively since compute_query_response_instantiation_values also creates universes, but it isn't part of the replace_bound_vars failure path.

imo you're right, this bookkeeping doesn't belong here under -Zassumptions-on-binders. i've dropped it, and fyi the issue-157840 ui test still passes. ltm if you think the remaining fix needs anything else :)

delegate.insert_placeholder_assumptions(
new_universe,
Some(rustc_type_ir::region_constraint::Assumptions::empty()),
);
}
}

let var_values = response.value.var_values();
Expand Down
24 changes: 23 additions & 1 deletion compiler/rustc_next_trait_solver/src/placeholder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ where
IndexMap<ty::PlaceholderType<I>, ty::BoundTy<I>>,
IndexMap<ty::PlaceholderConst<I>, ty::BoundConst<I>>,
) {
let old_universes = universe_indices.clone();
let mut replacer = BoundVarReplacer {
infcx,
mapped_regions: Default::default(),
Expand All @@ -57,8 +58,29 @@ where
};

let value = value.fold_with(&mut replacer);
let BoundVarReplacer {
mapped_regions,
mapped_types,
mapped_consts,
universe_indices,
infcx: _,
current_index: _,
} = replacer;

if infcx.cx().assumptions_on_binders() {
for (old, new) in old_universes.into_iter().zip(universe_indices.iter()) {
if let (None, Some(new)) = (old, new) {
// FIXME(-Zassumptions-on-binders): `replace_bound_vars` does not have enough
// context to compute placeholder assumptions for the binders it enters.
infcx.insert_placeholder_assumptions(
*new,
Some(rustc_type_ir::region_constraint::Assumptions::empty()),
);
}
}
}

(value, replacer.mapped_regions, replacer.mapped_types, replacer.mapped_consts)
(value, mapped_regions, mapped_types, mapped_consts)
}

fn universe_for(&mut self, debruijn: ty::DebruijnIndex) -> ty::UniverseIndex {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//@ compile-flags: -Znext-solver=globally -Zassumptions-on-binders

trait Trait<T> {}

trait Proj<'a> {
type Assoc;
}

fn foo<'a, T>()
where
T: Proj<'a, Assoc = fn(<T as Proj>::Assoc)>,
(): Trait<<T as Proj<'a>>::Assoc>,
//~^ ERROR the trait bound `(): Trait<fn(for<'a> fn(<T as Proj<'a>>::Assoc))>` is not satisfied
{
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0277]: the trait bound `(): Trait<fn(for<'a> fn(<T as Proj<'a>>::Assoc))>` is not satisfied
--> $DIR/placeholder-assumptions-issue-157840.rs:12:9
|
LL | (): Trait<<T as Proj<'a>>::Assoc>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait<fn(for<'a> fn(<T as Proj<'a>>::Assoc))>` is not implemented for `()`
|
help: consider extending the `where` clause, but there might be an alternative better way to express this requirement
|
LL | (): Trait<<T as Proj<'a>>::Assoc>, (): Trait<fn(for<'a> fn(<T as Proj<'a>>::Assoc))>
| +++++++++++++++++++++++++++++++++++++++++++++++++

error: aborting due to 1 previous error

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