unconstrained region vars: do not ICE ICE baby
This commit is contained in:
parent
8cfaf70c32
commit
98fa0c93ee
3 changed files with 53 additions and 9 deletions
|
@ -57,16 +57,12 @@ impl<'a, 'tcx: 'a> InferCtxtExt<'a, 'tcx> for InferCtxt<'tcx> {
|
||||||
let ty = OpportunisticRegionResolver::new(self).fold_ty(ty);
|
let ty = OpportunisticRegionResolver::new(self).fold_ty(ty);
|
||||||
|
|
||||||
// We do not expect existential variables in implied bounds.
|
// We do not expect existential variables in implied bounds.
|
||||||
// We may however encounter unconstrained lifetime variables in invalid
|
// We may however encounter unconstrained lifetime variables
|
||||||
// code. See #110161 for context.
|
// in very rare cases.
|
||||||
|
//
|
||||||
|
// See `ui/implied-bounds/implied-bounds-unconstrained-2.rs` for
|
||||||
|
// an example.
|
||||||
assert!(!ty.has_non_region_infer());
|
assert!(!ty.has_non_region_infer());
|
||||||
if ty.has_infer() {
|
|
||||||
self.tcx.sess.delay_span_bug(
|
|
||||||
self.tcx.def_span(body_id),
|
|
||||||
"skipped implied_outlives_bounds due to unconstrained lifetimes",
|
|
||||||
);
|
|
||||||
return vec![];
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut canonical_var_values = OriginalQueryValues::default();
|
let mut canonical_var_values = OriginalQueryValues::default();
|
||||||
let canonical_ty =
|
let canonical_ty =
|
||||||
|
|
28
tests/ui/implied-bounds/implied-bounds-unconstrained-1.rs
Normal file
28
tests/ui/implied-bounds/implied-bounds-unconstrained-1.rs
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
// check-pass
|
||||||
|
|
||||||
|
// Regression test for #112832.
|
||||||
|
pub trait QueryDb {
|
||||||
|
type Db;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct QueryTable<Q, DB> {
|
||||||
|
db: DB,
|
||||||
|
storage: Q,
|
||||||
|
}
|
||||||
|
|
||||||
|
// We normalize `<Q as QueryDb>::Db` to `<Q as AsyncQueryFunction<'d>>::SendDb`
|
||||||
|
// using the where-bound. 'd is an unconstrained region variable which previously
|
||||||
|
// triggered an assert.
|
||||||
|
impl<Q> QueryTable<Q, <Q as QueryDb>::Db> where Q: for<'d> AsyncQueryFunction<'d> {}
|
||||||
|
|
||||||
|
pub trait AsyncQueryFunction<'d>: QueryDb<Db = <Self as AsyncQueryFunction<'d>>::SendDb> {
|
||||||
|
type SendDb: 'd;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait QueryStorageOpsAsync<Q>
|
||||||
|
where
|
||||||
|
Q: for<'d> AsyncQueryFunction<'d>,
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
20
tests/ui/implied-bounds/implied-bounds-unconstrained-2.rs
Normal file
20
tests/ui/implied-bounds/implied-bounds-unconstrained-2.rs
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
// check-pass
|
||||||
|
|
||||||
|
// Another minimized regression test for #112832.
|
||||||
|
trait Trait {
|
||||||
|
type Assoc;
|
||||||
|
}
|
||||||
|
|
||||||
|
trait Sub<'a>: Trait<Assoc = <Self as Sub<'a>>::SubAssoc> {
|
||||||
|
type SubAssoc;
|
||||||
|
}
|
||||||
|
|
||||||
|
// By using the where-clause we normalize `<T as Trait>::Assoc` to
|
||||||
|
// `<T as Sub<'a>>::SubAssoc` where `'a` is an unconstrained region
|
||||||
|
// variable.
|
||||||
|
fn foo<T>(x: <T as Trait>::Assoc)
|
||||||
|
where
|
||||||
|
for<'a> T: Sub<'a>,
|
||||||
|
{}
|
||||||
|
|
||||||
|
fn main() {}
|
Loading…
Add table
Add a link
Reference in a new issue