-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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: Fix ICE with doc(hidden)
on tuple variant fields
#88639
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
Generates from pub enum FooEnum {
HiddenTupleItem(#[doc(hidden)] ()),
MultipleHidden(#[doc(hidden)] (), #[doc(hidden)] ()),
MixedHiddenTupleItemLast((), #[doc(hidden)] ()),
MixedHiddenTupleItemFirst(#[doc(hidden)] (), ()),
NotHiddenTupleItem1(()),
NotHiddenTupleItem2((), ()),
} I don't like how the Variants are shown, preferably I'd have it as |
@@ -944,13 +944,17 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni | |||
fn print_tuple_struct_fields(w: &mut Buffer, cx: &Context<'_>, s: &[clean::Item]) { | |||
for (i, ty) in s | |||
.iter() | |||
.map(|f| if let clean::StructFieldItem(ref ty) = *f.kind { ty } else { unreachable!() }) | |||
.map(|f| if let clean::StructFieldItem(ref ty) = *f.kind { Some(ty) } else { None }) |
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.
It should be possible at this stage, it means that the clean::Item
was badly created... Can you find out where a non-StructFieldItem
was added please?
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.
Do you mean it shouldn't be possible to create a clean::Item
with StructFieldItem
kind?
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 meant that a tuple item (when creating a new one) should only have StructFieldItem
and discard everything else. (In clean/mod.rs
iirc, sorry, not on computer at the moment)
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.
The kind we end up with is
StrippedItem(StructFieldItem(Tuple([])))
my brief look into how the render works suggests to me that this is correct, and that it just needs to be handled.
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.
Isn't there the same issue with:
pub enum Foo {
Bar {
x: u32,
#[doc(hidden)]
y: u8,
}
}
?
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.
Also, please add a regression test to ensure that this doesn't panic anymore in the future. But otherwise it looks like a great start, thanks! EDIT: In |
This comment has been minimized.
This comment has been minimized.
I'm trying to figure out how I'd do HTML checking with would // @!has issue_88600/enum.FooEnum.html '//*[@id="variant.HiddenTupleItem.field.0"]' etc. be enough? |
Also check that the other fields are present, but otherwise seems good. |
eaeed12
to
650adfc
Compare
Fixed :D Seems like // @!has issue_88600/enum.FooEnum.html '//*[@id="variant.HiddenTupleItem.field.0"]' doesn't actually work, need to specify a pattern to not match. |
I don't think this is a good idea. Enum fields are always public, they shouldn't be hidden from documentation. This should only fix the ICE, but not change the behavior (and actually I would suggest warning that doc(hidden) does nothing in that position as well). |
doc(hidden)
Also, @GuillaumeGomez please remember to check with the team before making changes in behavior like this, this is a feature we'd have to support into the future. |
Well that seems like a misfeature ... But I guess if it already existed that's fine. Have you tested this respects --document-hidden-items? |
That works just fine, I think that's because |
My bad, I thought it was something already supported. What should we do then? Opening an FCP or just discard it and do what I suggested here? |
@GuillaumeGomez oh no, I was just confused - I thought this was a no-op before. |
Perfect, back to reviewing then. ;) |
Looks good to me, thanks! r=me once CI pass. |
doc(hidden)
doc(hidden)
on tuple variant fields
It actually looks like rustdoc's behavior for this changed between stable and 2021-08-21. I don't think that change was intentional, so I'm wondering if we should revert the behavior change in this PR before it hits stable? |
It looks likely that the behavior changed in #87451. |
No worries! Ok, I'll fix the behaviour. I spent a good time trying to find out how to get the variant, but it's not wasted time, I now know more about the internals. Thanks for the help :) So in summary.
Ill add a doc-test to make sure the behaviour is consistent for both variants, I'll do this in a test called For documentation, the lint code I ended up with was fn check_doc_hidden(&self, meta: &NestedMetaItem, hir_id: HirId, target: Target) -> bool {
match target {
Target::Field => {
let parent_node_hir_id = self.tcx.hir().get_parent_node(hir_id);
let parent_node = self.tcx.hir().find(parent_node_hir_id);
if let Some(hir::Node::Variant(hir::Variant {
data: hir::VariantData::Tuple(..),
..
})) = parent_node
{
self.tcx.struct_span_lint_hir(
INVALID_DOC_ATTRIBUTES,
hir_id,
meta.span(),
|lint| {
lint.build("#[doc(hidden)] does nothing on enum variant fields").emit()
},
);
return false;
}
}
_ => {}
}
true
} |
1db6283
to
81709f2
Compare
81709f2
to
4b97a33
Compare
I'd want to make sure the |
this also renders them as `_`, which rustdoc previously did not.
4b97a33
to
4a915ac
Compare
Thanks! @bors: r+ |
📌 Commit 4a915ac has been approved by |
Accepted for backport to 1.56 beta. @rustbot label: +beta-accepted |
…aumeGomez rustdoc: Fix ICE with `doc(hidden)` on tuple variant fields Fixes rust-lang#88600. ```rust pub struct H; pub struct S; pub enum FooEnum { HiddenTupleItem(#[doc(hidden)] H), MultipleHidden(#[doc(hidden)] H, #[doc(hidden)] H), MixedHiddenFirst(#[doc(hidden)] H, S), MixedHiddenLast(S, #[doc(hidden)] H), HiddenStruct { #[doc(hidden)] h: H, s: S, }, } ``` Generates ![image](https://user-images.githubusercontent.com/1502855/132259152-382f9517-c2a0-41d8-acd0-64e5993931fc.png)
…arth Rollup of 15 pull requests Successful merges: - rust-lang#85200 (Ignore derived Clone and Debug implementations during dead code analysis) - rust-lang#86165 (Add proc_macro::Span::{before, after}.) - rust-lang#87088 (Fix stray notes when the source code is not available) - rust-lang#87441 (Emit suggestion when passing byte literal to format macro) - rust-lang#88546 (Emit proper errors when on missing closure braces) - rust-lang#88578 (fix(rustc): suggest `items` be borrowed in `for i in items[x..]`) - rust-lang#88632 (Fix issues with Markdown summary options) - rust-lang#88639 (rustdoc: Fix ICE with `doc(hidden)` on tuple variant fields) - rust-lang#88667 (Tweak `write_fmt` doc.) - rust-lang#88720 (Rustdoc coverage fields count) - rust-lang#88732 (RustWrapper: avoid deleted unclear attribute methods) - rust-lang#88742 (Fix table in docblocks) - rust-lang#88776 (Workaround blink/chromium grid layout limitation of 1000 rows) - rust-lang#88807 (Fix typo in docs for iterators) - rust-lang#88812 (Fix typo `option` -> `options`.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
[beta] backports - rustdoc: Fix ICE with `doc(hidden)` on tuple variant fields rust-lang#88639 - Fix 2021 `dyn` suggestion that used code as label rust-lang#88657 - Workaround blink/chromium grid layout limitation of 1000 rows rust-lang#88776 - Change scope of temporaries in match guards rust-lang#88678 - Add a regression test for rust-lang#88649 rust-lang#88691 - Revert anon union parsing rust-lang#88775 - Disable validate_maintainers. rust-lang#88977 Also drop stage0 rustfmt, because that's only supposed to be used on master. r? `@Mark-Simulacrum`
Fixes #88600.
Generates