-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Fix deprecated attribute intra-doc link not resolved in the right location on reexported item #151120
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
base: main
Are you sure you want to change the base?
Fix deprecated attribute intra-doc link not resolved in the right location on reexported item #151120
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1e34590 to
46ded94
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Rebased on |
|
Reviewing this now, I've verified that the new regression test does in fact crash current |
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.
Two small potential improvements, otherwise the code looks good!
| let item_id = if let Some(inline_stmt_id) = item.inline_stmt_id | ||
| && !item.span(tcx).is_none_or(|item_span| item_span.inner().contains(*span)) | ||
| { | ||
| inline_stmt_id.to_def_id() | ||
| } else { | ||
| item.item_id.expect_def_id() | ||
| }; | ||
| insert_links(item_id, note) |
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.
| let item_id = if let Some(inline_stmt_id) = item.inline_stmt_id | |
| && !item.span(tcx).is_none_or(|item_span| item_span.inner().contains(*span)) | |
| { | |
| inline_stmt_id.to_def_id() | |
| } else { | |
| item.item_id.expect_def_id() | |
| }; | |
| insert_links(item_id, note) | |
| // when resolving an intra-doc link inside a deprecation note | |
| // that is on an inlined `use` statement, we need to use the `def_id` of | |
| // the `use` statement, not the inlined item. | |
| // <https://github.com/rust-lang/rust/pull/151120> | |
| let item_id = if let Some(inline_stmt_id) = item.inline_stmt_id | |
| && item.span(tcx).is_some_and(|item_span| !item_span.inner().contains(*span)) | |
| { | |
| inline_stmt_id.to_def_id() | |
| } else { | |
| item.item_id.expect_def_id() | |
| }; | |
| insert_links(item_id, note) |
- I think moving the negation inwards makes the condition easier to reason about
- This is a weird edge case so I think it's good to give a comment. yes git blame exists but if a refactor happens between now and when this needs to be re-investigated, it might not be very helpful (it doesn't have to be this exact comment, feel free to write your own if you think you can do better, i left out the macro hazard for brevity).
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.
Agreed for the comment, however if the span is None, or doesn't contain the attribute, then we should use the use span, which means my original condition was wrong too, the ! should have been for the contains, not the whole thing. ^^'
|
@rustbot author |
…ocation on reexported item
46ded94 to
c341745
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
|
Added comment and fixed condition. |
|
The new condition has a different behavior than the old one, and from the equivalent one I suggested. was this intentional? why? |
|
yes it's intentional, explained it in my comment. ;) |
|
Could we please expedite the review of this PR? Our toolchain builders have been blocked for a week due to the issue reported here: rust-lang/rust#151028. We would greatly appreciate your help in getting this landed. |
Fixes #151028.
Follow-up of #150721.
So when we resolve an intra-doc link, its current context (the module from which we resolve in short) is very important. However, when we use an intra-doc link in a
#[deprecated]attribute on a reexported item, we were using the context of the reexported item and not of theuseitself. Meaning that if you have an intra-doc linkstd::mem::dropon an item from another crate (let's saycore), then the import will simply fail since there is nostddependency.Now comes the not so funny fix: at this point, we don't know anymore where the attribute came from (ie, from the reexport or from the reexported item) since we already merged the attribute at this point. The solution I found to go around this problem is to check if the item span contains the attribute, and if not, then we use the
inline_stmt_idas context instead of the item's ID. I'm not super happy and I'm sure we'll find corner cases in the future (like with macros), however there are a few things that mitigate this fix:inline_stmt_idas context and be fine, but I guess we'll see when get there.Hopefully this explanation made sense. :)
cc @folkertdev
r? @lolbinarycat