-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[rustdoc] Unify type aliases rendering with other ADT #140863
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
Merged
+376
−214
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5f857a9
Rename `clean::Enum::variants` method into `non_stripped_variants`
GuillaumeGomez 560aec1
Unify rendering of type aliases without ADT items
GuillaumeGomez 4194745
Split `Item::attributes` method into three
GuillaumeGomez eb9f054
Rename the `document_*` argument/field into `is_type_alias`
GuillaumeGomez 4f3dd7b
Tweak attribute rendering depending on wether or not it is a type alias
GuillaumeGomez 2b292d1
Add regression test for #140739
GuillaumeGomez 3646a09
Improve code
GuillaumeGomez ec97b0f
Update to new API
GuillaumeGomez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// This test ensures that the `repr` attribute is displayed in type aliases. | ||
// | ||
// Regression test for <https://github.com/rust-lang/rust/issues/140739>. | ||
|
||
#![crate_name = "foo"] | ||
|
||
/// bla | ||
#[repr(C)] | ||
pub struct Foo1; | ||
|
||
//@ has 'foo/type.Bar1.html' | ||
//@ has - '//*[@class="rust item-decl"]/code' '#[repr(C)]pub struct Bar1;' | ||
// Ensures that we see the doc comment of the type alias and not of the aliased type. | ||
//@ has - '//*[@class="toggle top-doc"]/*[@class="docblock"]' 'bar' | ||
/// bar | ||
pub type Bar1 = Foo1; | ||
|
||
/// bla | ||
#[repr(C)] | ||
pub union Foo2 { | ||
pub a: u8, | ||
} | ||
|
||
//@ has 'foo/type.Bar2.html' | ||
//@ matches - '//*[@class="rust item-decl"]' '#\[repr\(C\)\]\npub union Bar2 \{*' | ||
// Ensures that we see the doc comment of the type alias and not of the aliased type. | ||
//@ has - '//*[@class="toggle top-doc"]/*[@class="docblock"]' 'bar' | ||
/// bar | ||
pub type Bar2 = Foo2; | ||
|
||
/// bla | ||
#[repr(C)] | ||
pub enum Foo3 { | ||
A, | ||
} | ||
|
||
//@ has 'foo/type.Bar3.html' | ||
//@ matches - '//*[@class="rust item-decl"]' '#\[repr\(C\)\]pub enum Bar3 \{*' | ||
// Ensures that we see the doc comment of the type alias and not of the aliased type. | ||
//@ has - '//*[@class="toggle top-doc"]/*[@class="docblock"]' 'bar' | ||
/// bar | ||
pub type Bar3 = Foo3; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Wouldn't this make more sense as
has_stripped_variants
? Am I missing something?Ofc if we're doing that we should rename the other
has_stripped_entries
for consistency, I think that seems pretty in line with all the other refactoring going on here.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.
Maybe I'm the one who missed something. 😆
A type alias can be an alias of an enum, a union or a struct. Of these three, 2 have fields and one has variants. So in this case, neither "fields" nor "variants" can be used.
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.
ah, you're right. really it's the other
has_stripped_entries
that look odd, since in those cases we do actually know if its a field or variant. i guess it makes sense to keep the names the same, and i suppose the function body is simple enough it doesn't need a doc comment.