Implement overflow for infinite implied lifetime bounds
This commit is contained in:
parent
e643f59f6d
commit
268c56e144
3 changed files with 36 additions and 4 deletions
|
@ -24,8 +24,8 @@ pub(super) fn infer_predicates(
|
||||||
|
|
||||||
// If new predicates were added then we need to re-calculate
|
// If new predicates were added then we need to re-calculate
|
||||||
// all crates since there could be new implied predicates.
|
// all crates since there could be new implied predicates.
|
||||||
loop {
|
for i in 0.. {
|
||||||
let mut predicates_added = false;
|
let mut predicates_added = vec![];
|
||||||
|
|
||||||
// Visit all the crates and infer predicates
|
// Visit all the crates and infer predicates
|
||||||
for id in tcx.hir_free_items() {
|
for id in tcx.hir_free_items() {
|
||||||
|
@ -83,14 +83,27 @@ pub(super) fn infer_predicates(
|
||||||
.get(&item_did.to_def_id())
|
.get(&item_did.to_def_id())
|
||||||
.map_or(0, |p| p.as_ref().skip_binder().len());
|
.map_or(0, |p| p.as_ref().skip_binder().len());
|
||||||
if item_required_predicates.len() > item_predicates_len {
|
if item_required_predicates.len() > item_predicates_len {
|
||||||
predicates_added = true;
|
predicates_added.push(item_did);
|
||||||
global_inferred_outlives
|
global_inferred_outlives
|
||||||
.insert(item_did.to_def_id(), ty::EarlyBinder::bind(item_required_predicates));
|
.insert(item_did.to_def_id(), ty::EarlyBinder::bind(item_required_predicates));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !predicates_added {
|
if predicates_added.is_empty() {
|
||||||
|
// We've reached a fixed point.
|
||||||
break;
|
break;
|
||||||
|
} else if !tcx.recursion_limit().value_within_limit(i) {
|
||||||
|
let msg = if let &[id] = &predicates_added[..] {
|
||||||
|
format!("overflow computing implied lifetime bounds for `{}`", tcx.def_path_str(id),)
|
||||||
|
} else {
|
||||||
|
"overflow computing implied lifetime bounds".to_string()
|
||||||
|
};
|
||||||
|
tcx.dcx()
|
||||||
|
.struct_span_fatal(
|
||||||
|
predicates_added.iter().map(|id| tcx.def_span(*id)).collect::<Vec<_>>(),
|
||||||
|
msg,
|
||||||
|
)
|
||||||
|
.emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
11
tests/ui/implied-bounds/overflow.rs
Normal file
11
tests/ui/implied-bounds/overflow.rs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
trait Tailed<'a>: 'a {
|
||||||
|
type Tail: Tailed<'a>;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct List<'a, T: Tailed<'a>> {
|
||||||
|
//~^ ERROR overflow computing implied lifetime bounds for `List`
|
||||||
|
next: Box<List<'a, T::Tail>>,
|
||||||
|
node: &'a T,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
8
tests/ui/implied-bounds/overflow.stderr
Normal file
8
tests/ui/implied-bounds/overflow.stderr
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
error: overflow computing implied lifetime bounds for `List`
|
||||||
|
--> $DIR/overflow.rs:5:1
|
||||||
|
|
|
||||||
|
LL | struct List<'a, T: Tailed<'a>> {
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue