Skip to content

Commit 7e049fe

Browse files
committed
auto merge of #14452 : alexcrichton/rust/issue-14438, r=huonw
This commit alters rustdoc to keep a hash set of known inlined items which is a whitelist for generating URLs to. Closes #14438
2 parents 1dea883 + 4ef535e commit 7e049fe

File tree

5 files changed

+15
-1
lines changed

5 files changed

+15
-1
lines changed

src/librustdoc/clean/inline.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ fn try_inline_def(cx: &core::DocContext,
8585
_ => return None,
8686
};
8787
let fqn = csearch::get_item_path(tcx, did);
88+
cx.inlined.borrow_mut().get_mut_ref().insert(did);
8889
ret.push(clean::Item {
8990
source: clean::Span::empty(),
9091
name: Some(fqn.last().unwrap().to_str().to_string()),

src/librustdoc/core.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ pub struct DocContext {
4141
pub external_paths: ExternalPaths,
4242
pub external_traits: RefCell<Option<HashMap<ast::DefId, clean::Trait>>>,
4343
pub external_typarams: RefCell<Option<HashMap<ast::DefId, String>>>,
44+
pub inlined: RefCell<Option<HashSet<ast::DefId>>>,
4445
}
4546

4647
impl DocContext {
@@ -58,6 +59,7 @@ pub struct CrateAnalysis {
5859
pub external_paths: ExternalPaths,
5960
pub external_traits: RefCell<Option<HashMap<ast::DefId, clean::Trait>>>,
6061
pub external_typarams: RefCell<Option<HashMap<ast::DefId, String>>>,
62+
pub inlined: RefCell<Option<HashSet<ast::DefId>>>,
6163
}
6264

6365
/// Parses, resolves, and typechecks the given crate
@@ -111,12 +113,14 @@ fn get_ast_and_resolve(cpath: &Path, libs: HashSet<Path>, cfgs: Vec<String>)
111113
external_traits: RefCell::new(Some(HashMap::new())),
112114
external_typarams: RefCell::new(Some(HashMap::new())),
113115
external_paths: RefCell::new(Some(HashMap::new())),
116+
inlined: RefCell::new(Some(HashSet::new())),
114117
}, CrateAnalysis {
115118
exported_items: exported_items,
116119
public_items: public_items,
117120
external_paths: RefCell::new(None),
118121
external_traits: RefCell::new(None),
119122
external_typarams: RefCell::new(None),
123+
inlined: RefCell::new(None),
120124
})
121125
}
122126

@@ -138,5 +142,7 @@ pub fn run_core(libs: HashSet<Path>, cfgs: Vec<String>, path: &Path)
138142
*analysis.external_traits.borrow_mut() = map;
139143
let map = ctxt.external_typarams.borrow_mut().take();
140144
*analysis.external_typarams.borrow_mut() = map;
145+
let map = ctxt.inlined.borrow_mut().take();
146+
*analysis.inlined.borrow_mut() = map;
141147
(krate, analysis)
142148
}

src/librustdoc/html/format.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ fn resolved_path(w: &mut fmt::Formatter, did: ast::DefId, p: &clean::Path,
150150
print_all: bool) -> fmt::Result {
151151
path(w, p, print_all,
152152
|cache, loc| {
153-
if ast_util::is_local(did) || cache.paths.contains_key(&did) {
153+
if ast_util::is_local(did) || cache.inlined.contains(&did) {
154154
Some(("../".repeat(loc.len())).to_string())
155155
} else {
156156
match *cache.extern_locations.get(&did.krate) {

src/librustdoc/html/render.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ pub struct Cache {
159159
/// Cache of where external crate documentation can be found.
160160
pub extern_locations: HashMap<ast::CrateNum, ExternalLocation>,
161161

162+
/// Set of definitions which have been inlined from external crates.
163+
pub inlined: HashSet<ast::DefId>,
164+
162165
// Private fields only used when initially crawling a crate to build a cache
163166

164167
stack: Vec<String>,
@@ -287,6 +290,9 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
287290
typarams: analysis.as_ref().map(|a| {
288291
a.external_typarams.borrow_mut().take_unwrap()
289292
}).unwrap_or(HashMap::new()),
293+
inlined: analysis.as_ref().map(|a| {
294+
a.inlined.borrow_mut().take_unwrap()
295+
}).unwrap_or(HashSet::new()),
290296
};
291297
cache.stack.push(krate.name.clone());
292298
krate = cache.fold_crate(krate);

src/librustdoc/test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ pub fn run(input: &str,
7878
external_paths: RefCell::new(Some(HashMap::new())),
7979
external_traits: RefCell::new(None),
8080
external_typarams: RefCell::new(None),
81+
inlined: RefCell::new(None),
8182
};
8283
super::ctxtkey.replace(Some(ctx));
8384

0 commit comments

Comments
 (0)