-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[rustdoc] If re-export is private, get the next item until a public one is found or expose the private item directly #113374
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
bors
merged 17 commits into
rust-lang:master
from
GuillaumeGomez:private-to-public-path
Jul 27, 2023
+344
−3
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ee7dba4
If re-export is private, get the next item until a public one is foun…
GuillaumeGomez d67a31f
Add regression test for #81141
GuillaumeGomez 078e902
Improve code readability
GuillaumeGomez 278d15c
Extend issue-81141-private-reexport-in-public-api test to cover more …
GuillaumeGomez 6b56e8e
Rename `first_not_private` into `first_non_private`
GuillaumeGomez 9fb6548
Correctly handle `super` and `::`
GuillaumeGomez 298cd36
Add test for private items
GuillaumeGomez d29afe2
Add support for `--document-hidden-items` in `first_non_private`
GuillaumeGomez 5859b44
Add test for `--document-hidden-items`
GuillaumeGomez 49ccde0
Re-add missing generics in `first_non_private`
GuillaumeGomez 95cea62
Add regression test for generics reexport of private import
GuillaumeGomez bc7d958
Remove needs for transmute
GuillaumeGomez 662c167
Revert "Remove needs for transmute"
GuillaumeGomez 988729d
Cache qpath first public result
GuillaumeGomez 1f828f0
Improve performance of `first_non_private`
GuillaumeGomez 51eb0c3
Fix regression for private in public
GuillaumeGomez 2461d0c
Remove transmute calls and caching for use paths
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
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 @@ | ||
pub struct Ident; |
13 changes: 13 additions & 0 deletions
13
tests/rustdoc/issue-81141-private-reexport-in-public-api-2.rs
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,13 @@ | ||
// edition:2015 | ||
|
||
#![crate_name = "foo"] | ||
|
||
use external::Public as Private; | ||
|
||
pub mod external { | ||
pub struct Public; | ||
|
||
// @has 'foo/external/fn.make.html' | ||
// @has - '//*[@class="rust item-decl"]/code' 'pub fn make() -> Public' | ||
pub fn make() -> ::Private { super::Private } | ||
} |
13 changes: 13 additions & 0 deletions
13
tests/rustdoc/issue-81141-private-reexport-in-public-api-generics.rs
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,13 @@ | ||
#![crate_name = "foo"] | ||
|
||
use crate::bar::Foo as Alias; | ||
|
||
pub mod bar { | ||
pub struct Foo<'a, T>(&'a T); | ||
} | ||
|
||
// @has "foo/fn.foo.html" | ||
// @has - '//*[@class="rust item-decl"]/code' "pub fn foo<'a, T>(f: Foo<'a, T>) -> Foo<'a, usize>" | ||
pub fn foo<'a, T>(f: Alias<'a, T>) -> Alias<'a, usize> { | ||
Alias(&0) | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/rustdoc/issue-81141-private-reexport-in-public-api-hidden.rs
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,16 @@ | ||
// compile-flags: -Z unstable-options --document-hidden-items | ||
|
||
#![crate_name = "foo"] | ||
|
||
#[doc(hidden)] | ||
pub use crate::bar::Bar as Alias; | ||
|
||
mod bar { | ||
pub struct Bar; | ||
} | ||
|
||
// @has 'foo/fn.bar.html' | ||
// @has - '//*[@class="rust item-decl"]/code' 'pub fn bar() -> Alias' | ||
pub fn bar() -> Alias { | ||
Alias | ||
} |
32 changes: 32 additions & 0 deletions
32
tests/rustdoc/issue-81141-private-reexport-in-public-api-private.rs
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,32 @@ | ||
// compile-flags: --document-private-items | ||
|
||
#![crate_name = "foo"] | ||
|
||
use crate::bar::Bar as Alias; | ||
pub(crate) use crate::bar::Bar as CrateAlias; | ||
|
||
mod bar { | ||
pub struct Bar; | ||
pub use self::Bar as Inner; | ||
} | ||
|
||
// It's a fully private re-export so it should not be displayed. | ||
// @has 'foo/fn.bar.html' | ||
// @has - '//*[@class="rust item-decl"]/code' 'pub fn bar() -> Bar' | ||
pub fn bar() -> Alias { | ||
Alias | ||
} | ||
|
||
// It's public re-export inside a private module so it should be visible. | ||
// @has 'foo/fn.bar2.html' | ||
// @has - '//*[@class="rust item-decl"]/code' 'pub fn bar2() -> Inner' | ||
pub fn bar2() -> crate::bar::Inner { | ||
Alias | ||
} | ||
|
||
// It's a non-public, so it doesn't appear in documentation so it should not be visible. | ||
// @has 'foo/fn.bar3.html' | ||
// @has - '//*[@class="rust item-decl"]/code' 'pub fn bar3() -> Bar' | ||
pub fn bar3() -> CrateAlias { | ||
Alias | ||
} |
124 changes: 124 additions & 0 deletions
124
tests/rustdoc/issue-81141-private-reexport-in-public-api.rs
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,124 @@ | ||
// This test ensures that if a private re-export is present in a public API, it'll be | ||
// replaced by the first public item in the re-export chain or by the private item. | ||
|
||
#![crate_name = "foo"] | ||
|
||
use crate::bar::Bar as Alias; | ||
|
||
pub use crate::bar::Bar as Whatever; | ||
use crate::Whatever as Whatever2; | ||
use crate::Whatever2 as Whatever3; | ||
pub use crate::bar::Inner as Whatever4; | ||
|
||
mod bar { | ||
pub struct Bar; | ||
pub use self::Bar as Inner; | ||
} | ||
|
||
// @has 'foo/fn.bar.html' | ||
// @has - '//*[@class="rust item-decl"]/code' 'pub fn bar() -> Bar' | ||
pub fn bar() -> Alias { | ||
Alias | ||
} | ||
|
||
// @has 'foo/fn.bar2.html' | ||
// @has - '//*[@class="rust item-decl"]/code' 'pub fn bar2() -> Whatever' | ||
pub fn bar2() -> Whatever3 { | ||
Whatever | ||
} | ||
|
||
// @has 'foo/fn.bar3.html' | ||
// @has - '//*[@class="rust item-decl"]/code' 'pub fn bar3() -> Whatever4' | ||
pub fn bar3() -> Whatever4 { | ||
Whatever | ||
} | ||
|
||
// @has 'foo/fn.bar4.html' | ||
// @has - '//*[@class="rust item-decl"]/code' 'pub fn bar4() -> Bar' | ||
pub fn bar4() -> crate::Alias { | ||
Alias | ||
} | ||
|
||
// @has 'foo/fn.bar5.html' | ||
// @has - '//*[@class="rust item-decl"]/code' 'pub fn bar5() -> Whatever' | ||
pub fn bar5() -> crate::Whatever3 { | ||
Whatever | ||
} | ||
|
||
// @has 'foo/fn.bar6.html' | ||
// @has - '//*[@class="rust item-decl"]/code' 'pub fn bar6() -> Whatever4' | ||
pub fn bar6() -> crate::Whatever4 { | ||
Whatever | ||
} | ||
|
||
|
||
// @has 'foo/fn.bar7.html' | ||
// @has - '//*[@class="rust item-decl"]/code' 'pub fn bar7() -> Bar' | ||
pub fn bar7() -> self::Alias { | ||
Alias | ||
} | ||
|
||
// @has 'foo/fn.bar8.html' | ||
// @has - '//*[@class="rust item-decl"]/code' 'pub fn bar8() -> Whatever' | ||
pub fn bar8() -> self::Whatever3 { | ||
Whatever | ||
} | ||
|
||
// @has 'foo/fn.bar9.html' | ||
// @has - '//*[@class="rust item-decl"]/code' 'pub fn bar9() -> Whatever4' | ||
pub fn bar9() -> self::Whatever4 { | ||
Whatever | ||
} | ||
|
||
mod nested { | ||
pub(crate) use crate::Alias; | ||
pub(crate) use crate::Whatever3; | ||
pub(crate) use crate::Whatever4; | ||
pub(crate) use crate::nested as nested2; | ||
} | ||
|
||
// @has 'foo/fn.bar10.html' | ||
// @has - '//*[@class="rust item-decl"]/code' 'pub fn bar10() -> Bar' | ||
pub fn bar10() -> nested::Alias { | ||
Alias | ||
} | ||
|
||
// @has 'foo/fn.bar11.html' | ||
// @has - '//*[@class="rust item-decl"]/code' 'pub fn bar11() -> Whatever' | ||
pub fn bar11() -> nested::Whatever3 { | ||
Whatever | ||
} | ||
|
||
// @has 'foo/fn.bar12.html' | ||
// @has - '//*[@class="rust item-decl"]/code' 'pub fn bar12() -> Whatever4' | ||
pub fn bar12() -> nested::Whatever4 { | ||
Whatever | ||
} | ||
|
||
// @has 'foo/fn.bar13.html' | ||
// @has - '//*[@class="rust item-decl"]/code' 'pub fn bar13() -> Bar' | ||
pub fn bar13() -> nested::nested2::Alias { | ||
Alias | ||
} | ||
|
||
// @has 'foo/fn.bar14.html' | ||
// @has - '//*[@class="rust item-decl"]/code' 'pub fn bar14() -> Whatever' | ||
pub fn bar14() -> nested::nested2::Whatever3 { | ||
Whatever | ||
} | ||
|
||
// @has 'foo/fn.bar15.html' | ||
// @has - '//*[@class="rust item-decl"]/code' 'pub fn bar15() -> Whatever4' | ||
pub fn bar15() -> nested::nested2::Whatever4 { | ||
Whatever | ||
} | ||
|
||
use external::Public as Private; | ||
|
||
pub mod external { | ||
pub struct Public; | ||
|
||
// @has 'foo/external/fn.make.html' | ||
// @has - '//*[@class="rust item-decl"]/code' 'pub fn make() -> Public' | ||
pub fn make() -> super::Private { super::Private } | ||
} |
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,13 @@ | ||
// Regression test for <https://github.com/rust-lang/rust/pull/113374> to | ||
// ensure it doesn't panic. | ||
|
||
mod generics { | ||
pub enum WherePredicate { | ||
EqPredicate, | ||
} | ||
} | ||
pub mod visit { | ||
use *; | ||
pub fn visit_where_predicate<V>(_visitor: &mut V, _i: &WherePredicate) {} | ||
} | ||
pub use generics::*; |
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.
Of course, we could at some point support
Ctor
but that's low priority. This would only be reachable with const generics (and const items if/once we render their body). E.g.Container<{ Alias }>
withuse Type::Ctor as Alias
.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.
For now it's something we exclude everywhere in rustdoc when looking for reexports. We can indeed add support for it later on.