-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Hide = _
as associated constant value inside impl blocks
#134321
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
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
57e1a47
Rename TyAssocConstItem -> RequiredAssocConstItem
dtolnay 044885c
Split AssocConstItem into ProvidedAssocConstItem and ImplAssocConstItem
dtolnay da89d10
Add test for rustdoc showing underscore as assoc const value
dtolnay 6bdfd12
Suppress `= _` on associated constants in impls
dtolnay ff65d62
Rename TyAssocTypeItem -> RequiredAssocTypeItem
dtolnay 7ee31eb
Rename TyMethodItem -> RequiredMethodItem
dtolnay 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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Hmm, having 3 variants for assoc consts is a bit excessive, I wish it was just
TraitAssocConst
&ImplAssocConst
at the maximum but that probably calls for a larger refactoring.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.
Yeah I gave this some thought before going with the current approach. From what I figured out (I haven't worked in this code before):
Before this PR,
AssocConstItem
andTyAssocConstItem
are separate variants because they must store different contents. The variant's data is eitherConstant
(which isGenerics
+ConstantKind
+Type
) or justGenerics
+Type
.In order to merge
ProvidedAssocConstItem
andRequiredAssocConstItem
into a singleTraitAssocConstItem
variant, either:Constant
needs to containOption<ConstantKind>
, which has a big blast radius because non-associated constants and paths (dyn Foo<K = 0>
) use this sameConstant
type in a context where not having a value doesn't make sense.or we need
TraitAssocConstItem
to store notConstant
but some otherConstantWithOptionalValue
type — which ends up being not less duplication than splittingProvidedAssocConstItem
vsRequiredAssocConstItem
.There is a more promising approach, which I gave up on but is still potentially salvageable. Notice this
parent
argument:rust/src/librustdoc/html/render/mod.rs
Lines 1068 to 1072 in 0aeaa5e
rust/src/librustdoc/html/render/mod.rs
Lines 1094 to 1103 in 0aeaa5e
When printing, associated constants are supposed to know whether they are inside of a
ItemType::Trait
as opposed to aItemType::Impl
. This would be perfect for deciding whether= _
needs to be shown (only when parent is trait, never when parent is impl).But this doesn't work because
parent
ends up being misused under the assumption that it's only relevant for indentation (?). See this call site, which is inside a function calleditem_trait
and is responsible for printing a trait and its contents. And yet it is passingItemType::Impl
as the value ofparent
, which does not make sense.rust/src/librustdoc/html/render/print_item.rs
Lines 820 to 827 in 0aeaa5e
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.
Oof, that's super odd. Thanks for the thorough investigation, I have to look into cleaning this up at some point!