Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 20 additions & 3 deletions compiler/rustc_type_ir/src/region_constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,10 @@ impl<'a, Infcx: InferCtxtLike<Interner = I>, I: Interner> TypeVisitor<I>
match t.kind() {
TyKind::Placeholder(p) => self.max_universe = self.max_universe.max(p.universe),
TyKind::Infer(InferTy::TyVar(inf)) => {
// Unlike `visit_region`, we don't resolve the variable first: callers
// computing assumptions bail on any non-region inference variable

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.

we use MaxUniverse when rewriting constraints to a lower universe which can happen on different terms than what we compute assumptions for (though there is significant overlap) 🤔 I would expect there to possibly be cases where we have unresolved type/const infer vars but im not sure.

I would honestly probably just put a resolve_vars_if_possible call in the max_universe function just to be safe and then say we do that here, instead of trying to rely on some kind of global reasoning for why stuff must be resolved

// before reaching here, so a type infer var is always unresolved and
// has a universe.
let u = self.infcx.universe_of_ty(inf).unwrap();
debug!("var {inf:?} in universe {u:?}");
self.max_universe = self.max_universe.max(u);
Expand All @@ -1025,6 +1029,8 @@ impl<'a, Infcx: InferCtxtLike<Interner = I>, I: Interner> TypeVisitor<I>
match c.kind() {
ConstKind::Placeholder(p) => self.max_universe = self.max_universe.max(p.universe),
ConstKind::Infer(rustc_type_ir::InferConst::Var(inf)) => {
// See the comment in `visit_ty`: a const infer var is always
// unresolved here, so unlike a region it needs no resolving first.
let u = self.infcx.universe_of_ct(inf).unwrap();
debug!("var {inf:?} in universe {u:?}");
self.max_universe = self.max_universe.max(u);
Expand All @@ -1037,9 +1043,20 @@ impl<'a, Infcx: InferCtxtLike<Interner = I>, I: Interner> TypeVisitor<I>
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);
// The variable may already have been unified with another region.
// `universe_of_lt` returns `None` for a resolved variable, so resolve
// it first and inspect whatever it points at.
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,26 @@
//@ 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. It now resolves the
// variable before inspecting its universe.

#![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/*<T>*/()
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:21:23
|
LL | [(); Parent::CT::<T>]:,
| ^ not found in this scope
|
help: you might be missing a type parameter
|
LL | fn check<T>/*<T>*/()
| +++

error: aborting due to 1 previous error

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