-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Rustdoc-Json: Retain Stripped Modules when they are imported, not when they have items #101106
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
2 commits
Select commit
Hold shift + click to select a range
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,38 @@ | ||
use rustc_data_structures::fx::FxHashSet; | ||
use rustc_hir::def_id::DefId; | ||
|
||
use crate::{ | ||
clean::{self, Import, ImportSource, Item}, | ||
fold::DocFolder, | ||
}; | ||
|
||
/// Get the id's of all items that are `pub use`d in the crate. | ||
/// | ||
/// We need this to know if a stripped module is `pub use mod::*`, to decide | ||
/// if it needs to be kept in the index, despite being stripped. | ||
/// | ||
/// See [#100973](https://github.com/rust-lang/rust/issues/100973) and | ||
/// [#101103](https://github.com/rust-lang/rust/issues/101103) for times when | ||
/// this information is needed. | ||
pub(crate) fn get_imports(krate: clean::Crate) -> (clean::Crate, FxHashSet<DefId>) { | ||
let mut finder = ImportFinder { imported: FxHashSet::default() }; | ||
let krate = finder.fold_crate(krate); | ||
(krate, finder.imported) | ||
} | ||
|
||
struct ImportFinder { | ||
imported: FxHashSet<DefId>, | ||
} | ||
|
||
impl DocFolder for ImportFinder { | ||
fn fold_item(&mut self, i: Item) -> Option<Item> { | ||
match *i.kind { | ||
clean::ImportItem(Import { source: ImportSource { did: Some(did), .. }, .. }) => { | ||
self.imported.insert(did); | ||
Some(i) | ||
} | ||
|
||
_ => Some(self.fold_item_recur(i)), | ||
} | ||
} | ||
} |
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,28 @@ | ||
// Regression test for https://github.com/rust-lang/rust/issues/100973 | ||
|
||
#![feature(no_core)] | ||
#![no_core] | ||
|
||
// @set m1 = "$.index[*][?(@.name == 'm1' && @.kind == 'module')].id" | ||
// @is "$.index[*][?(@.name == 'm1' && @.kind == 'module')].inner.items" [] | ||
// @is "$.index[*][?(@.name == 'm1' && @.kind == 'module')].inner.is_stripped" true | ||
mod m1 { | ||
pub fn f() {} | ||
} | ||
// @set m2 = "$.index[*][?(@.name == 'm2' && @.kind == 'module')].id" | ||
// @is "$.index[*][?(@.name == 'm2' && @.kind == 'module')].inner.items" [] | ||
// @is "$.index[*][?(@.name == 'm2' && @.kind == 'module')].inner.is_stripped" true | ||
mod m2 { | ||
pub fn f(_: u8) {} | ||
} | ||
|
||
// @set m1_use = "$.index[*][?(@.inner.name=='m1')].id" | ||
// @is "$.index[*][?(@.inner.name=='m1')].inner.id" $m1 | ||
// @is "$.index[*][?(@.inner.name=='m1')].inner.glob" true | ||
pub use m1::*; | ||
// @set m2_use = "$.index[*][?(@.inner.name=='m2')].id" | ||
// @is "$.index[*][?(@.inner.name=='m2')].inner.id" $m2 | ||
// @is "$.index[*][?(@.inner.name=='m2')].inner.glob" true | ||
pub use m2::*; | ||
|
||
// @ismany "$.index[*][?(@.inner.is_crate==true)].inner.items[*]" $m1_use $m2_use |
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,8 @@ | ||
// Regression test for https://github.com/rust-lang/rust/issues/100973 | ||
|
||
// @is "$.index[*][?(@.name=='m1' && @.kind == 'module')].inner.is_stripped" true | ||
// @set m1 = "$.index[*][?(@.name=='m1')].id" | ||
mod m1 {} | ||
|
||
// @is "$.index[*][?(@.inner.name=='m1' && @.kind=='import')].inner.id" $m1 | ||
pub use m1::*; |
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,14 @@ | ||
// Regression test for https://github.com/rust-lang/rust/issues/101103 | ||
|
||
#![feature(no_core)] | ||
#![no_core] | ||
|
||
mod m1 { | ||
pub fn x() {} | ||
} | ||
|
||
pub use m1::x; | ||
|
||
// @has "$.index[*][?(@.name=='x' && @.kind=='function')]" | ||
// @has "$.index[*][?(@.kind=='import' && @.inner.name=='x')].inner.source" '"m1::x"' | ||
// @!has "$.index[*][?(@.name=='m1')]" |
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
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.
Uh oh!
There was an error while loading. Please reload this page.