Repository navigation
rustdoc: Improve ItemKind - #162916
rustdoc: Improve ItemKind#162916fmease wants to merge 8 commits into
ItemKind#162916Conversation
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
[WIP] rustdoc: Improve `ItemKind`
75c7db0 to
b15adfe
Compare
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (77d2154): comparison URL. Overall result: ❌✅ regressions and improvements - please read:Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. Next, please: If you can, justify the regressions found in this try perf run in writing along with @bors rollup=never rustc-perf Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary -0.8%, secondary 1.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary 1.6%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 500.132s -> 501.928s (0.36%) |
This comment has been minimized.
This comment has been minimized.
0da05b0 to
9cf241e
Compare
9cf241e to
628da35
Compare
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
[WIP] rustdoc: Improve `ItemKind`
628da35 to
9502ff1
Compare
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (cd705f8): comparison URL. Overall result: ❌✅ regressions and improvements - please read:Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. Next, please: If you can, justify the regressions found in this try perf run in writing along with @bors rollup=never rustc-perf Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary -1.9%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary -3.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 494.96s -> 488.165s (-1.37%) |
|
rustbot has assigned @lolbinarycat. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
f11bbf4 to
f5b1c33
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
f5b1c33 to
04fa31d
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
04fa31d to
2173417
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This prepares for the removal of their common suffix `Item`. It makes it trivial to mechanically mass rename them later, glob imports would render the endeavor a lot more brittle. The convention to go out of one's way to avoid enum namespacing (i.e., suffixing or prefixing the variants & glob importing them everywhere) is incredibly dated. It pollutes the module scope, it's annoying since one has to remember to add (here) suffix `Item` to new variants & referencing the variant names requires more to type compared to a function-local (here) `use clean::ItemKind::*;` for a `match` for example (although in most cases we won't glob import anyway, so that point isn't super relevant).
2173417 to
c4269d7
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. |
c4269d7 to
588b522
Compare
This comment has been minimized.
This comment has been minimized.
588b522 to
cbb4616
Compare
Moreover, rename `Function` to `Fn`, `ForeignFunction` to `ForeignFn`, `*Method` to `*AssocFn`, `*Type` to `*Ty`, `Constant` to `Const` & `Macro` to `DeclMacro`. Re. `Method`: In Rust, the term "method" specificially refers to associated functions that have a receiver / `self` parameter but this variant represents associated functions in general. Re. `Function` -> `Fn`: Since I don't want to name the "associated" variant `AssocFunction` (too lengthy) but `AssocFn`, so I'm changing the free variant, too, to have a more consistent naming scheme. `Macro` -> `DeclMacro`: To differentiate it from `ProcMacro`.
…ssocConst` I had to modify several HTML rendering routines because parameter `parent: ItemType` of fn `render_assoc_item` didn't always refer to the parent container (impl vs trait) since it was actually misused to control the styling (!), namely the indentation & the look of the where-clause, but now with `ProvidedAssocConst` & `ImplAssocConst` merged I needed to know the actual container to determine `AssocConstValue`. `render_assoc_item` previously only used the `parent` param to determine the indentation & `assoc_method` used it to determine the indentation & the style of the where-clause (see enum `Ending`; complete misnomer!). That led to `item_trait` (for rendering trait pages) literally passing `ItemType::Impl` for the "docs section" (as contrasted with the "code block") to avoid indenting it. To untangle this, I forced the callers of `render_assoc_item` to specify the indentation & the where-clause styling via new parameters. *Moreover*, as alluded to above, only `assoc_method` made the where-clause styling (`Ending`) dependent on the context, not however `assoc_const` or `assoc_ty`! I've fixed that here to avoid making the parameter list of `render_assoc_item` even longer & since it makes them consistent (thereby fixing the remaining issues reported in RUST-112901).
This comment has been minimized.
This comment has been minimized.
cbb4616 to
a87ac7e
Compare
There was a problem hiding this comment.
did line-by-line review of everything except the tests and rustdoc-json stuff. big fan of the changes so far! i always thought that enum was a bit of a mess, and this is a huge step towards cleaning it up (the main thing that's still a bit messy is DeclMacro vs ProcMacro, but that can be addressed in a followup).
will review the rest later, but for now, here's my comments.
| ProcMacro(ProcMacro), | ||
| Primitive(PrimitiveType), | ||
| Const(Box<Constant>), | ||
| AssocConst(Box<AssocConst>), |
There was a problem hiding this comment.
Do we want the inner type to always have the same name as the enum variant, for consistancy? Function is a reasonable exception b/c of the Fn trait, but there's no reason this shouldn't be Primative, Const, and DeclMacro, right?
| AssocFnWithoutBody = 12, | ||
| AssocFnWithBody = 13, |
There was a problem hiding this comment.
| AssocFnWithoutBody = 12, | |
| AssocFnWithBody = 13, | |
| AssocFnWithoutBody = 12, // "tymethod" in urls | |
| AssocFnWithBody = 13, // "method" in urls |
| let kind = match &self.kind { | ||
| ItemKind::StrippedItem(k) => k, | ||
| ItemKind::Stripped(k) => k, | ||
| _ => &self.kind, | ||
| }; |
There was a problem hiding this comment.
this exact logic, either in the form of a match or if let, comes up enough that it might be worth factoring out into a utility method. not sure about the name, unstripped_kind maybe?
| | ItemKind::AssocTy(clean::AssocTy { ty: Some(_), .. }) | ||
| if cache.parent_stack.last().is_some_and(|parent| parent.is_trait_impl()) => | ||
| { | ||
| // skip associated items in trait impls |
There was a problem hiding this comment.
| // skip associated items in trait impls | |
| // skip associated items (besides methods) in trait impls |
unrelated to the refactor, but this behavior is a bit arbitrary, it means std::collections::btree_map::IterMut::next shows up in search results but std::collections::btree_map::IterMut::Item doesn't
| pub(crate) type_: Type, | ||
| pub(crate) struct TyAlias { | ||
| pub(crate) generics: Generics, | ||
| pub(crate) ty: Type, |
There was a problem hiding this comment.
assuming the value of the new field ty is equivalent to self.item_type.unwrap_or(self.type_), correct?
| @@ -772,16 +766,7 @@ impl Item { | |||
|
|
|||
| /// Returns true if this a macro declared with the `macro` keyword or with `macro_rules!. | |||
There was a problem hiding this comment.
| /// Returns true if this a macro declared with the `macro` keyword or with `macro_rules!. | |
| /// Returns true if this a macro declared with the `macro` keyword or with `macro_rules!`, unless | |
| /// it was defined with only `derive()` branches or only `attr()` branches. |
| pub(crate) struct Function { | ||
| pub(crate) generics: Generics, | ||
| pub(crate) decl: FnDecl, | ||
| } |
There was a problem hiding this comment.
did you swap the order of these fields? it's hard to tell because the diff is very confused here.
| let kind = match &item.kind { | ||
| clean::StrippedItem(item) => item, | ||
| ItemKind::Stripped(item) => item, | ||
| kind => kind, |
There was a problem hiding this comment.
another instance of this common pattern that could be factored out
| Ok(()) | ||
| } | ||
|
|
||
| fn should_render_item( |
There was a problem hiding this comment.
| fn should_render_item_in_deref_methods( |
old name made this function sound way more general than it actually is.
| let req_assoc_fns = filter_items(&t.items, |m| m.is_assoc_fn_without_body(), "tymethod"); | ||
| let prov_assoc_fns = filter_items(&t.items, |m| m.is_assoc_fn_with_body(), "method"); |
There was a problem hiding this comment.
I think these should still have method in the name, as traits can't have non-method functions and I don't believe there are currently any plans to change that.
View all comments
Fixes the absolutely hideous & messy
ItemKindrepresentations for associated items:RequiredAssocConstItem,ProvidedAssocConstItem&ImplAssocConstIteminto new singleAssocConstRequiredMethodItem&MethodIteminto new singleAssocFnRequiredAssocTypeItem&AssocTypeIteminto new singleAssocTyNote that I'm responsible for some of these: In PR #95316 from 2022 I introduced
TyAssocTypeItem(RequiredAssocTypeItemon main) &TyAssocConstItem(RequiredAssocConstItemon main) because I wanted to be consistent with the preexistingTyMethod<->Methodsplit.The latter is far more egregious because it unnecessarily leaks into user-observable parts of the generated docs (search filter
tymethod, URL fragmenttymethod.f.html) (to be fixed at some point). Thankfully in said PR we changed the approach and didn't make the split user-observable for assoc consts & types.As the reviewer of PR #134321 I'm also responsible for the
ProvidedAssocConstItem<->ImplAssocConstItemsplit which I deemed acceptable as a temporary solution.Addresses #112901 (comment) & thereby fixes #112901.
(No LLM was or will be used by me during the entire creation process of this PR)