Skip to content

Commit 61d4817

Browse files
lcnrMark-Simulacrum
authored andcommitted
unconstrained region vars: do not ICE ICE baby
1 parent 5680fa1 commit 61d4817

File tree

3 files changed

+53
-9
lines changed

3 files changed

+53
-9
lines changed

Diff for: compiler/rustc_trait_selection/src/traits/outlives_bounds.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,12 @@ impl<'a, 'tcx: 'a> InferCtxtExt<'a, 'tcx> for InferCtxt<'tcx> {
5757
let ty = OpportunisticRegionResolver::new(self).fold_ty(ty);
5858

5959
// We do not expect existential variables in implied bounds.
60-
// We may however encounter unconstrained lifetime variables in invalid
61-
// code. See #110161 for context.
60+
// We may however encounter unconstrained lifetime variables
61+
// in very rare cases.
62+
//
63+
// See `ui/implied-bounds/implied-bounds-unconstrained-2.rs` for
64+
// an example.
6265
assert!(!ty.has_non_region_infer());
63-
if ty.has_infer() {
64-
self.tcx.sess.delay_span_bug(
65-
self.tcx.def_span(body_id),
66-
"skipped implied_outlives_bounds due to unconstrained lifetimes",
67-
);
68-
return vec![];
69-
}
7066

7167
let mut canonical_var_values = OriginalQueryValues::default();
7268
let canonical_ty =
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// check-pass
2+
3+
// Regression test for #112832.
4+
pub trait QueryDb {
5+
type Db;
6+
}
7+
8+
pub struct QueryTable<Q, DB> {
9+
db: DB,
10+
storage: Q,
11+
}
12+
13+
// We normalize `<Q as QueryDb>::Db` to `<Q as AsyncQueryFunction<'d>>::SendDb`
14+
// using the where-bound. 'd is an unconstrained region variable which previously
15+
// triggered an assert.
16+
impl<Q> QueryTable<Q, <Q as QueryDb>::Db> where Q: for<'d> AsyncQueryFunction<'d> {}
17+
18+
pub trait AsyncQueryFunction<'d>: QueryDb<Db = <Self as AsyncQueryFunction<'d>>::SendDb> {
19+
type SendDb: 'd;
20+
}
21+
22+
pub trait QueryStorageOpsAsync<Q>
23+
where
24+
Q: for<'d> AsyncQueryFunction<'d>,
25+
{
26+
}
27+
28+
fn main() {}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// check-pass
2+
3+
// Another minimized regression test for #112832.
4+
trait Trait {
5+
type Assoc;
6+
}
7+
8+
trait Sub<'a>: Trait<Assoc = <Self as Sub<'a>>::SubAssoc> {
9+
type SubAssoc;
10+
}
11+
12+
// By using the where-clause we normalize `<T as Trait>::Assoc` to
13+
// `<T as Sub<'a>>::SubAssoc` where `'a` is an unconstrained region
14+
// variable.
15+
fn foo<T>(x: <T as Trait>::Assoc)
16+
where
17+
for<'a> T: Sub<'a>,
18+
{}
19+
20+
fn main() {}

0 commit comments

Comments
 (0)