Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

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()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 tru


// Visit all the crates and infer predicates
for id in tcx.hir_free_items() {
Expand Down Expand Up @@ -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());
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Member Author

Choose a reason for hiding this comment

The 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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ill put a comment but it's necessary im p sure

Copy link
Contributor

Choose a reason for hiding this comment

The 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;
}
}
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/implied-bounds/overflow.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
trait Tailed<'a>: 'a {
Copy link
Contributor

Choose a reason for hiding this comment

The 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() {}
8 changes: 8 additions & 0 deletions tests/ui/implied-bounds/overflow.stderr
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

Loading