-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #101106 - aDotInTheVoid:rdj-stripped-mod, r=Guillaume…
…Gomez Rustdoc-Json: Retain Stripped Modules when they are imported, not when they have items Fixes #101103 Fixes #100973 r? `@GuillaumeGomez`
- Loading branch information
Showing
12 changed files
with
113 additions
and
13 deletions.
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
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 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,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 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 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,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 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