-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement overflow for infinite implied lifetime bounds #138676
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,8 +24,8 @@ pub(super) fn infer_predicates( | |
|
||
// If new predicates were added then we need to re-calculate | ||
// all crates since there could be new implied predicates. | ||
loop { | ||
let mut predicates_added = false; | ||
for i in 0.. { | ||
let mut predicates_added: Option<Vec<_>> = None; | ||
|
||
// Visit all the crates and infer predicates | ||
for id in tcx.hir_free_items() { | ||
|
@@ -83,13 +83,34 @@ pub(super) fn infer_predicates( | |
.get(&item_did.to_def_id()) | ||
.map_or(0, |p| p.as_ref().skip_binder().len()); | ||
if item_required_predicates.len() > item_predicates_len { | ||
predicates_added = true; | ||
predicates_added.get_or_insert_default().push(item_did); | ||
global_inferred_outlives | ||
.insert(item_did.to_def_id(), ty::EarlyBinder::bind(item_required_predicates)); | ||
} | ||
} | ||
|
||
if !predicates_added { | ||
if let Some(ids) = predicates_added { | ||
if !tcx.recursion_limit().value_within_limit(i) { | ||
let msg = if let &[id] = &ids[..] { | ||
format!( | ||
"overflow computing implied lifetime bounds for `{}`", | ||
tcx.def_path_str(id), | ||
) | ||
} else { | ||
"overflow computing implied lifetime bounds".to_string() | ||
}; | ||
tcx.dcx() | ||
.struct_span_err( | ||
ids.iter().map(|id| tcx.def_span(*id)).collect::<Vec<_>>(), | ||
msg, | ||
) | ||
.emit(); | ||
for id in ids { | ||
global_inferred_outlives.shift_remove(&id.to_def_id()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that seems suboptimal 🤔 what happens if u don't remove the added implied bounds here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hangs in both the old and need solvers due to RECURSION_LIMIT deep types having to be normalized There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ill put a comment but it's necessary im p sure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes sense, we get very deep assoc items. I feel like we can also have cycles of length 2 in which case we still get a hang as we don't remove the implied bounds for the other cycle participant? 🤔 vibes, but maybe just fatal error? 😁 |
||
} | ||
break; | ||
} | ||
} else { | ||
break; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
trait Tailed<'a>: 'a { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pls add doc comment/link to issue |
||
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() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just use a
Vec
with.is_empty()
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 tru