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
27 changes: 20 additions & 7 deletions compiler/rustc_type_ir/src/region_constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,15 @@ fn rewrite_type_outlives_constraints_in_universe_for_eager_placeholder_handling<
escaping_outlives,
I::BoundVarKinds::from_vars(infcx.cx(), bound_vars),
);
candidates.push(RegionConstraint::AliasTyOutlivesViaEnv(bound_outlives));
let candidate = RegionConstraint::AliasTyOutlivesViaEnv(bound_outlives);
if max_universe(infcx, candidate.clone()) < u {
candidates.push(candidate);
} else {
// `PlaceholderReplacer` only folds regions. A non-lifetime binder can leave
// a placeholder type in `u`, so this type-outlives constraint cannot be
// handled by the region-outlives-only eager placeholder machinery.
candidates.push(Ambiguity);
}
}

let assumptions = match assumptions {
Expand Down Expand Up @@ -885,12 +893,17 @@ fn rewrite_type_outlives_constraints_in_universe_for_eager_placeholder_handling<

// while we did skip the binder, bound vars aren't in any universe so
// this can't be an escaping bound var
candidates.extend(
regions_outliving(escaping_r, assumptions, infcx.cx())
.filter(|r2| max_universe(infcx, *r2) < u)
.map(|r2| AliasTyOutlivesViaEnv(bound_alias.map_bound(|alias| (alias, r2))))
.collect::<Vec<_>>(),
);
for r2 in regions_outliving(escaping_r, assumptions, infcx.cx())
.filter(|r2| max_universe(infcx, *r2) < u)
{
let candidate =
AliasTyOutlivesViaEnv(bound_alias.map_bound(|alias| (alias, r2)));
if max_universe(infcx, candidate.clone()) < u {
candidates.push(candidate);
} else {
candidates.push(Ambiguity);
}
}
}

// I'm not convinced our handling here is *complete* so for now
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//@ compile-flags: -Znext-solver -Zassumptions-on-binders

// Regression test for #157778.
//
// A non-lifetime binder (`for<T>`) introduces a placeholder *type* in universe `u`. The
// resulting alias-outlives constraint `<!T as Trait>::Assoc: 'r` stays in `u` because the
// region-only rewrite (`PlaceholderReplacer` only folds regions) cannot pull a type
// placeholder out of `u`. This used to trip an `assert!(max_universe < u)` and ICE in
// `pull_region_outlives_constraints_out_of_universe`. The assumptions-on-binders machinery
// is region-outlives-only, so we now report ambiguity instead of panicking.

#![feature(non_lifetime_binders)]

trait Trait {
type Assoc;
type Ref //~ ERROR cannot satisfy `<T as Trait>::Assoc: 'static`
where
for<T> T: Trait<Assoc: 'static>;
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error[E0284]: type annotations needed: cannot satisfy `<T as Trait>::Assoc: 'static`
--> $DIR/non_lifetime_binder_alias_outlives.rs:16:5
|
LL | / type Ref
LL | | where
LL | | for<T> T: Trait<Assoc: 'static>;
| |________________________________________^ cannot satisfy `<T as Trait>::Assoc: 'static`
|
note: required by a bound in `Trait::Ref`
--> $DIR/non_lifetime_binder_alias_outlives.rs:18:32
|
LL | type Ref
| --- required by a bound in this associated type
LL | where
LL | for<T> T: Trait<Assoc: 'static>;
| ^^^^^^^ required by this bound in `Trait::Ref`

error: aborting due to 1 previous error

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