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
21 changes: 15 additions & 6 deletions compiler/rustc_type_ir/src/region_constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -978,11 +978,14 @@ pub fn regions_outlived_by_placeholder<I: Interner>(
}

/// The largest universe a variable or placeholder was from in `t`
pub fn max_universe<Infcx: InferCtxtLike<Interner = I>, I: Interner, T: TypeVisitable<I>>(
pub fn max_universe<Infcx: InferCtxtLike<Interner = I>, I: Interner, T: TypeFoldable<I>>(
infcx: &Infcx,
t: T,
) -> UniverseIndex {
let mut visitor = MaxUniverse::new(infcx);
// `max_universe` is also used while rewriting constraints to lower universes,
// so do not rely on callers having already resolved non-region infer vars.
let t = infcx.resolve_vars_if_possible(t);
t.visit_with(&mut visitor);
visitor.max_universe()
}
Expand Down Expand Up @@ -1036,11 +1039,17 @@ impl<'a, Infcx: InferCtxtLike<Interner = I>, I: Interner> TypeVisitor<I>
fn visit_region(&mut self, r: I::Region) {
match r.kind() {
RegionKind::RePlaceholder(p) => self.max_universe = self.max_universe.max(p.universe),
RegionKind::ReVar(var) => {
let u = self.infcx.universe_of_lt(var).unwrap();
debug!("var {var:?} in universe {u:?}");
self.max_universe = self.max_universe.max(u);
}
RegionKind::ReVar(var) => match self.infcx.opportunistic_resolve_lt_var(var).kind() {
RegionKind::RePlaceholder(p) => {
self.max_universe = self.max_universe.max(p.universe)
}
RegionKind::ReVar(var) => {
let u = self.infcx.universe_of_lt(var).unwrap();
debug!("var {var:?} in universe {u:?}");
self.max_universe = self.max_universe.max(u);
}
_ => (),
},
_ => (),
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//@ compile-flags: -Zassumptions-on-binders -Znext-solver=globally

// Regression test for an ICE in the `MaxUniverse` region visitor. When computing
// the max universe of a region constraint, a `ReVar` term could already have been
// unified with another region. `universe_of_lt` returns `None` for such a resolved
// variable, so the visitor used to `unwrap()` `None` and panic.
//
// The missing `T` in `check` is intentional. It makes HIR ty lowering emit an
// error while still leaving behind the region constraint that used to ICE.

#![feature(min_generic_const_args, inherent_associated_types, generic_const_items)]

struct Parent<'a> {
a: &'a str,
}

impl<'a> Parent<'a> {
type const CT<T: 'a>: usize = 0;
}

fn check()
where
[(); Parent::CT::<T>]:,

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.

does adding the generic parameter T to check and introducing the lifetime 'a to check (and using it) cause this test to stop testing what it should? also is it possible to get a test case that doesn't depend on inherent_associated_types, the combo of mGCA and IATs is fairly brittle and likely to change significantly in the short future which will probably make this test stop testing anything 😅

//~^ ERROR cannot find type `T` in this scope
{
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0425]: cannot find type `T` in this scope
--> $DIR/resolved-region-var-max-universe.rs:23:23
|
LL | [(); Parent::CT::<T>]:,
| ^ not found in this scope
|
help: you might be missing a type parameter
|
LL | fn check<T>()
| +++

error: aborting due to 1 previous error

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