-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
rustdoc: Confusing intra-doc handling of Self
in enum
#82209
Comments
Yeah, this definitely seems like a bug. I have to use
|
But also I agree that this seems like a misfeature, I'd be ok with getting rid of it. To do that, just delete |
Yes, I think so. No one noticed this breaking for 12 weeks and |
Hi, I don't know if anyone is already planning to work on it, but if not, would it be a good first issue? I'm still new to the language but I'd like to start contributing. |
Yes, this should be a good first issue. You can claim it with |
Thanks! I'll have a look at it. @rustbot claim |
I've taken a deeper look at the issue, and at the doc on contributions to Rust. Correct me if I'm wrong, but I think I'm supposed to start with making a failing test case. I made a #![deny(broken_intra_doc_links)]
pub enum Foo {
Bar {
abc: i32,
/// [Self::Bar::abc]
xyz: i32,
},
} I'm not sure about the |
@lucas-deangelis yes, that looks fine. I have a couple nits but they can wait until you make a PR to review, that test is enough to show what's going wrong. |
Thanks! I'll start working on the fix now. |
Assigning |
I've tried removing |
Hmm, if that doesn't fix it the bug might be in the
You could try extending rust/src/librustdoc/passes/collect_intra_doc_links.rs Lines 837 to 845 in 15598a8
DefKind::Ctor or DefKind::Variant ?
|
This alone doesn't seem to fix it, however I've found that after adding rust/src/librustdoc/passes/collect_intra_doc_links.rs Lines 1016 to 1026 in 15598a8
The problem here seems to be that |
Did you try matching both |
This is my naive attempt: } else if matches!(
self.cx.tcx.def_kind(item.def_id),
DefKind::AssocConst
| DefKind::AssocFn
| DefKind::AssocTy
| DefKind::Variant
| DefKind::Field
| DefKind::Ctor(_, _)
) {
self.cx.tcx.parent(item.def_id) I didn't add |
What you wrote is what I meant :) I meant match either Does your attempt work? |
Nice, thanks for confirming.
My attempt doesn't work. Right now I'm looking at |
@lucas-deangelis all the "preprocessing" of the link (turning
|
Aha, I bet this is the issue: rust/src/librustdoc/passes/collect_intra_doc_links.rs Lines 837 to 845 in a8486b6
For fields in enum variants, the parent is the variant, not the enum. |
Thanks for the clarification.
So if I understand correctly, if we encounter a variant, we should return the parent of the parent of |
If you encounter a field that's in a variant. Basically make the check recursive (since fields may not be in a variant, e.g. |
Thanks, I'll try that. |
I think I'm making some progress. I added a new condition to check if we encounter a field that's in a variant before the else if (matches!(self.cx.tcx.def_kind(item.def_id), DefKind::Field) && matches!(self.cx.tcx.def_kind(self.cx.tcx.parent(item.def_id).unwrap()), DefKind::Variant)) {
self.cx.tcx.parent(item.def_id).and_then(|item_id| self.cx.tcx.parent(item_id))
} else if matches!(
self.cx.tcx.def_kind(item.def_id),
DefKind::AssocConst
| DefKind::AssocFn
| DefKind::AssocTy
| DefKind::Field
| DefKind::Variant
) { I'll have to find a way to handle the call to error: unresolved link to `Foo::Bar::abc`
--> rust/src/test/rustdoc/issue-82209.rs:5:14
|
5 | /// [Self::Bar::abc]
| ^^^^^^^^^^^^^^ the enum `Foo` has no variant or associated item named `abc`
| Am I correct in assuming that this is now an error in the link resolution? |
Hmm, is this still with the calls to |
It was, and now with it back it works. Thanks. Should I make a pull request now? |
That would be great, thanks! |
…jyn514 Fix intra-doc handling of `Self` in enum Fixes rust-lang#82209
…jyn514 Fix intra-doc handling of `Self` in enum Fixes rust-lang#82209
And it's merged! Thank you @jyn514 and @camelid for the help on the issue, @hellow554 for some of the initial work and @Dylan-DPC for the rollups. |
You're very welcome! Thank you for tackling the fix :) |
This code works fine:
But this code's intra-doc link doesn't resolve:
Doesn't
Self
usually only refer to types, not enum variants? (Barring the proposed RFC to make enum variant types.)The text was updated successfully, but these errors were encountered: