-
Notifications
You must be signed in to change notification settings - Fork 13k
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: introduce glob shadowing rules to rustdoc #83872
Closed
Closed
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b83ad87
introduce glob shadowing rules to rustdoc
longfangsong 17b908e
Update src/librustdoc/doctree.rs
longfangsong 791c371
Update src/librustdoc/doctree.rs
longfangsong 29ebc1e
Update src/librustdoc/doctree.rs
longfangsong 8c031ca
Update src/librustdoc/doctree.rs
longfangsong 58bb799
Update src/test/rustdoc/glob-shadowing.rs
longfangsong 0005dc3
use `Item::name()` in `clean`
longfangsong 09cb285
apply some suggestions from code review
longfangsong 4b934bb
apply some suggestions from code review
longfangsong 6ad7e7e
apply some suggestions from code reviewing
longfangsong 8100884
take namespace into consideration when doing shadowing
longfangsong 981f38e
update test
longfangsong 4076106
Merge remote-tracking branch 'upstream/master'
longfangsong 7ee35c6
Pass tcx when push_item instead of store namespace
longfangsong f9df01a
Add some discription to the test file
longfangsong 06b0273
Handle two different glob re-exports
longfangsong 18f031f
Fix wrongly pushing down from_glob when visiting_mod_contents
longfangsong 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 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 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 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 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,86 @@ | ||
// @has 'glob_shadowing/index.html' | ||
// @count - '//tr[@class="module-item"]' 5 | ||
// @!has - '//tr[@class="module-item"]' 'sub1::describe' | ||
// @has - '//tr[@class="module-item"]' 'sub2::describe' | ||
|
||
// @!has - '//tr[@class="module-item"]' 'sub1::describe2' | ||
|
||
// @!has - '//tr[@class="module-item"]' 'sub1::prelude' | ||
// @has - '//tr[@class="module-item"]' 'mod::prelude' | ||
|
||
// @has - '//tr[@class="module-item"]' 'sub1::Foo (struct)' | ||
// @has - '//tr[@class="module-item"]' 'mod::Foo (function)' | ||
|
||
// @has - '//tr[@class="module-item"]' 'sub4::inner::X' | ||
|
||
// @has 'glob_shadowing/fn.describe.html' | ||
// @has - '//div[@class="docblock"]' 'sub2::describe' | ||
|
||
mod sub1 { | ||
// this should be shadowed by sub2::describe | ||
/// sub1::describe | ||
pub fn describe() -> &'static str { | ||
"sub1::describe" | ||
} | ||
|
||
// this should be shadowed by mod::prelude | ||
/// sub1::prelude | ||
pub mod prelude { | ||
} | ||
|
||
// this should *not* be shadowed, because sub1::Foo and mod::Foo are in different namespaces | ||
/// sub1::Foo (struct) | ||
pub struct Foo; | ||
|
||
// this should be shadowed, | ||
// because both sub1::describe2 and sub3::describe2 are from glob reexport | ||
/// sub1::describe2 | ||
pub fn describe2() -> &'static str { | ||
"sub1::describe2" | ||
} | ||
} | ||
|
||
mod sub2 { | ||
/// sub2::describe | ||
pub fn describe() -> &'static str { | ||
"sub2::describe" | ||
} | ||
} | ||
|
||
mod sub3 { | ||
// this should be shadowed | ||
// because both sub1::describe2 and sub3::describe2 are from glob reexport | ||
/// sub3::describe2 | ||
pub fn describe2() -> &'static str { | ||
"sub3::describe2" | ||
} | ||
} | ||
|
||
mod sub4 { | ||
// this should be shadowed by sub4::inner::X | ||
/// sub4::X | ||
pub const X: usize = 0; | ||
pub mod inner { | ||
pub use super::*; | ||
/// sub4::inner::X | ||
pub const X: usize = 1; | ||
} | ||
} | ||
|
||
/// mod::Foo (function) | ||
pub fn Foo() {} | ||
|
||
#[doc(inline)] | ||
pub use sub2::describe; | ||
longfangsong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#[doc(inline)] | ||
pub use sub1::*; | ||
|
||
longfangsong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#[doc(inline)] | ||
pub use sub3::*; | ||
|
||
#[doc(inline)] | ||
pub use sub4::inner::*; | ||
|
||
/// mod::prelude | ||
pub mod prelude {} |
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.
Is it possible for
new_item.name()
to be empty? And is it possible thatnew_item_ns
is empty?If both is not possible maybe we can remove this branch.
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 only situation I found which
new_item.name().is_empty()
isstd::prelude
(but IMO we don't need to care about it), remove this check seems won't affect the test result. But this comment mentioned some possible situation. @ollie27 can you give a more detailed example?On the other hand,
new_item_ns
can be empty in many situations like macro derives (a minimal example isDebug
insrc/test/rustdoc/wrapping.rs
). If we remove this check, then adding those items may cause panic on L88.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.
new_item.name
can be empty for impl blocks - or if it's not and it's using{{impl}}
or something, that's another bug, because impl blocks shouldn't use globbing logic, they don't have have a namespace.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.
So means in this case both checks are still necessary? Maybe we should leave a comment or it's not necessary?
And should the test includes these cases?