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
Improve errors for recursive type aliases #88121
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
r? @estebank (feel free to reassign, but I know you were involved with that issue) |
@@ -591,10 +591,14 @@ pub(crate) fn report_cycle<'a>( | |||
err.span_note(span, &format!("...which requires {}...", query.description)); | |||
} |
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.
I'm intrigued if the iteration above doesn't need to be reverted to be correct 🤔 (no need to address now)
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.
I'm ok with the approach. Do you want to try out to expand the query with the DefId
to see what the impact of that is code and perf wise?
I tried doing that but then realized that I'd need to execute a query (to get the I could move |
I tried doing that, but that requires moving a bunch of other things, like An alternative approach could be to just track a boolean that says whether something is a type alias or not; it's also somewhat hacky. Yet another approach could be to have a mini- |
Ok, that worked! I'll probably finish up and then push up my changes tomorrow or this weekend. |
2c7d13b
to
568eb9c
Compare
I'm working on getting it working for trait aliases too, and then I think this should be ready for review. |
This comment has been minimized.
This comment has been minimized.
Once we think the logic is finished, we should do a perf run as you suggested earlier. |
This comment has been minimized.
This comment has been minimized.
0e0788a
to
02529bb
Compare
02529bb
to
e9f6e4b
Compare
Rebased (just to keep this up to date). |
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.
r=me. The only thing I'd want us to have is the docstring on the new enum. Feel free to ignore the other drive by comments.
error[E0391]: cycle detected when computing the super predicates of `T1` | ||
--> $DIR/infinite-trait-alias-recursion.rs:3:1 | ||
| | ||
LL | trait T1 = T2; | ||
| ^^^^^^^^^^^^^^ |
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.
This should likely point at only T1
.
note: cycle used when collecting item types in top-level module | ||
--> $DIR/infinite-type-alias-mutual-recursion.rs:1:1 | ||
| | ||
LL | / type X1 = X2; | ||
LL | | | ||
LL | | type X2 = X3; | ||
LL | | type X3 = X1; | ||
LL | | | ||
LL | | fn main() {} | ||
| |____________^ |
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.
This reminds me, we need a way to talk about files without showing a snippet.
e9f6e4b
to
c3df832
Compare
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit c3df832 with merge fb1a092cc53518e43fa12776af7db523aa9bfecc... |
☀️ Try build successful - checks-actions |
Queued fb1a092cc53518e43fa12776af7db523aa9bfecc with parent dfd8472, future comparison URL. |
Finished benchmarking try commit (fb1a092cc53518e43fa12776af7db523aa9bfecc): comparison url. Summary: This benchmark run did not return any relevant changes. If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. @bors rollup=never |
Perf looks good, I just have one question, and then this should be ready to be merged! |
`tcx.def_kind()` could theoretically invoke another query, which could cause an infinite query loop. Accessing the HIR map directly makes that less likely to happen. I also changed it to use `as_local()` (`tcx.def_kind()` seems to implicitly call `expect_local()`) and `opt_def_kind()` to reduce the chance of panicking on valid code.
Ok, updated it to use the HIR map directly! |
@bors r+ |
📌 Commit d96234b has been approved by |
☀️ Test successful - checks-actions |
Fixes #17539.