Skip to content

apply_member_constraints: fix placeholder check #142071

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions compiler/rustc_borrowck/src/handle_placeholders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ impl RegionTracker {
self.max_nameable_universe
}

pub(crate) fn max_placeholder_universe_reached(self) -> UniverseIndex {
self.max_placeholder_universe_reached
}

fn merge_min_max_seen(&mut self, other: &Self) {
self.max_placeholder_universe_reached = std::cmp::max(
self.max_placeholder_universe_reached,
Expand Down
9 changes: 8 additions & 1 deletion compiler/rustc_borrowck/src/region_infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {

// If the member region lives in a higher universe, we currently choose
// the most conservative option by leaving it unchanged.
if !self.max_nameable_universe(scc).is_root() {
if !self.max_placeholder_universe_reached(scc).is_root() {
return;
}

Expand Down Expand Up @@ -1376,6 +1376,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
self.scc_annotations[scc].max_nameable_universe()
}

pub(crate) fn max_placeholder_universe_reached(
&self,
scc: ConstraintSccIndex,
) -> UniverseIndex {
self.scc_annotations[scc].max_placeholder_universe_reached()
}

/// Checks the final value for the free region `fr` to see if it
/// grew too large. In particular, examine what `end(X)` points
/// wound up in `fr`'s final value; for each `end(X)` where `X !=
Expand Down
29 changes: 29 additions & 0 deletions tests/ui/nll/member-constraints/non-root-universe-existential-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//@ check-pass
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver

trait Proj<'a> {
type Assoc;
}

impl<'a, 'b, F: FnOnce() -> &'b ()> Proj<'a> for F {
type Assoc = ();
}

fn is_proj<F: for<'a> Proj<'a>>(f: F) {}

fn define<'a>() -> impl Sized + use<'a> {
// This defines the RPIT to `&'unconstrained_b ()`, an inference
// variable which is in a higher universe as gets created inside
// of the binder of `F: for<'a> Proj<'a>`. This previously caused
// us to not apply member constraints.
//
// This was unnecessary. It is totally acceptable for member regions
// to be able to name placeholders from higher universes, as long as
// they don't actually do so.
is_proj(define::<'a>);
&()
}

fn main() {}
31 changes: 31 additions & 0 deletions tests/ui/nll/member-constraints/non-root-universe-existential-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//@ check-pass

// Unlike `non-root-universe-existential-1.rs` this previously
// compiled as it simnply didn't define the hidden type of
// `impl Iterator` when projecting through it. We will do so
// with the new solver. Further minimizing this is challenging.

struct Type(Vec<Type>);
enum TypeTreeValueIter<'a, T> {
Once(T),
Ref(&'a ()),
}

impl<'a, T> Iterator for TypeTreeValueIter<'a, T> {
type Item = T;

fn next(&mut self) -> Option<Self::Item> {
loop {}
}
}

fn item<I: Iterator<Item: Iterator>>(x: I) -> <I::Item as Iterator>::Item {
loop {}
}

fn get_type_tree_values<'a>(ty: &'a Type) -> impl Iterator<Item = &'a Type> {
let _: &'a Type = item(std::iter::once(ty).map(get_type_tree_values));
TypeTreeValueIter::<'a, &'a Type>::Once(ty)
}

fn main() {}
Loading