Skip to content

Commit a89875f

Browse files
authored
Unrolled build for rust-lang#138676
Rollup merge of rust-lang#138676 - compiler-errors:overflow-implied-bounds, r=lcnr Implement overflow for infinite implied lifetime bounds Not a great error message, but better than a hang Fixes rust-lang#138665 Fixes rust-lang#102966 Fixes rust-lang#115407 r? lcnr
2 parents e5fefc3 + 268c56e commit a89875f

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ pub(super) fn infer_predicates(
2424

2525
// If new predicates were added then we need to re-calculate
2626
// all crates since there could be new implied predicates.
27-
loop {
28-
let mut predicates_added = false;
27+
for i in 0.. {
28+
let mut predicates_added = vec![];
2929

3030
// Visit all the crates and infer predicates
3131
for id in tcx.hir_free_items() {
@@ -83,14 +83,27 @@ pub(super) fn infer_predicates(
8383
.get(&item_did.to_def_id())
8484
.map_or(0, |p| p.as_ref().skip_binder().len());
8585
if item_required_predicates.len() > item_predicates_len {
86-
predicates_added = true;
86+
predicates_added.push(item_did);
8787
global_inferred_outlives
8888
.insert(item_did.to_def_id(), ty::EarlyBinder::bind(item_required_predicates));
8989
}
9090
}
9191

92-
if !predicates_added {
92+
if predicates_added.is_empty() {
93+
// We've reached a fixed point.
9394
break;
95+
} else if !tcx.recursion_limit().value_within_limit(i) {
96+
let msg = if let &[id] = &predicates_added[..] {
97+
format!("overflow computing implied lifetime bounds for `{}`", tcx.def_path_str(id),)
98+
} else {
99+
"overflow computing implied lifetime bounds".to_string()
100+
};
101+
tcx.dcx()
102+
.struct_span_fatal(
103+
predicates_added.iter().map(|id| tcx.def_span(*id)).collect::<Vec<_>>(),
104+
msg,
105+
)
106+
.emit();
94107
}
95108
}
96109

tests/ui/implied-bounds/overflow.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
trait Tailed<'a>: 'a {
2+
type Tail: Tailed<'a>;
3+
}
4+
5+
struct List<'a, T: Tailed<'a>> {
6+
//~^ ERROR overflow computing implied lifetime bounds for `List`
7+
next: Box<List<'a, T::Tail>>,
8+
node: &'a T,
9+
}
10+
11+
fn main() {}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: overflow computing implied lifetime bounds for `List`
2+
--> $DIR/overflow.rs:5:1
3+
|
4+
LL | struct List<'a, T: Tailed<'a>> {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to 1 previous error
8+

0 commit comments

Comments
 (0)