]> git.lizzy.rs Git - rust.git/commitdiff
rustdoc: Only link to local inlined foreign items
authorAlex Crichton <alex@alexcrichton.com>
Tue, 27 May 2014 04:51:59 +0000 (21:51 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 28 May 2014 02:33:57 +0000 (19:33 -0700)
This commit alters rustdoc to keep a hash set of known inlined items which is a
whitelist for generating URLs to.

Closes #14438

src/librustdoc/clean/inline.rs
src/librustdoc/core.rs
src/librustdoc/html/format.rs
src/librustdoc/html/render.rs
src/librustdoc/test.rs

index c434087dd2b6ce92370270cac87a0b8b71bfee8e..2f096346c9bef6b4de5a0140d3cdc03b01b7e0bf 100644 (file)
@@ -85,6 +85,7 @@ fn try_inline_def(cx: &core::DocContext,
         _ => return None,
     };
     let fqn = csearch::get_item_path(tcx, did);
+    cx.inlined.borrow_mut().get_mut_ref().insert(did);
     ret.push(clean::Item {
         source: clean::Span::empty(),
         name: Some(fqn.last().unwrap().to_str().to_string()),
index 7bc4693215a8cbeb03459645a058eba6d5c1ac59..27e39e1235c67ff44d7dc91acd2b2fcf460107c5 100644 (file)
@@ -41,6 +41,7 @@ pub struct DocContext {
     pub external_paths: ExternalPaths,
     pub external_traits: RefCell<Option<HashMap<ast::DefId, clean::Trait>>>,
     pub external_typarams: RefCell<Option<HashMap<ast::DefId, String>>>,
+    pub inlined: RefCell<Option<HashSet<ast::DefId>>>,
 }
 
 impl DocContext {
@@ -58,6 +59,7 @@ pub struct CrateAnalysis {
     pub external_paths: ExternalPaths,
     pub external_traits: RefCell<Option<HashMap<ast::DefId, clean::Trait>>>,
     pub external_typarams: RefCell<Option<HashMap<ast::DefId, String>>>,
+    pub inlined: RefCell<Option<HashSet<ast::DefId>>>,
 }
 
 /// Parses, resolves, and typechecks the given crate
@@ -111,12 +113,14 @@ fn get_ast_and_resolve(cpath: &Path, libs: HashSet<Path>, cfgs: Vec<String>)
         external_traits: RefCell::new(Some(HashMap::new())),
         external_typarams: RefCell::new(Some(HashMap::new())),
         external_paths: RefCell::new(Some(HashMap::new())),
+        inlined: RefCell::new(Some(HashSet::new())),
     }, CrateAnalysis {
         exported_items: exported_items,
         public_items: public_items,
         external_paths: RefCell::new(None),
         external_traits: RefCell::new(None),
         external_typarams: RefCell::new(None),
+        inlined: RefCell::new(None),
     })
 }
 
@@ -138,5 +142,7 @@ pub fn run_core(libs: HashSet<Path>, cfgs: Vec<String>, path: &Path)
     *analysis.external_traits.borrow_mut() = map;
     let map = ctxt.external_typarams.borrow_mut().take();
     *analysis.external_typarams.borrow_mut() = map;
+    let map = ctxt.inlined.borrow_mut().take();
+    *analysis.inlined.borrow_mut() = map;
     (krate, analysis)
 }
index c1b5b8af07af614ff8fc0da27b899b9350ec5f57..e3221177afe66684aa3f6401b91f1637a6966d6f 100644 (file)
@@ -150,7 +150,7 @@ fn resolved_path(w: &mut fmt::Formatter, did: ast::DefId, p: &clean::Path,
                  print_all: bool) -> fmt::Result {
     path(w, p, print_all,
         |cache, loc| {
-            if ast_util::is_local(did) || cache.paths.contains_key(&did) {
+            if ast_util::is_local(did) || cache.inlined.contains(&did) {
                 Some(("../".repeat(loc.len())).to_string())
             } else {
                 match *cache.extern_locations.get(&did.krate) {
index a23aefe03e813af9eca58140f79099c8635dad04..f5c7352b9c2e6080aab7bf1bfa1e74ad26db2fd0 100644 (file)
@@ -159,6 +159,9 @@ pub struct Cache {
     /// Cache of where external crate documentation can be found.
     pub extern_locations: HashMap<ast::CrateNum, ExternalLocation>,
 
+    /// Set of definitions which have been inlined from external crates.
+    pub inlined: HashSet<ast::DefId>,
+
     // Private fields only used when initially crawling a crate to build a cache
 
     stack: Vec<String>,
@@ -287,6 +290,9 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
         typarams: analysis.as_ref().map(|a| {
             a.external_typarams.borrow_mut().take_unwrap()
         }).unwrap_or(HashMap::new()),
+        inlined: analysis.as_ref().map(|a| {
+            a.inlined.borrow_mut().take_unwrap()
+        }).unwrap_or(HashSet::new()),
     };
     cache.stack.push(krate.name.clone());
     krate = cache.fold_crate(krate);
index 4023010537e7296aab09907baf5553b8bff5d2b6..a7abbe0360f94d09e78741a8a3daf506bdcc0f50 100644 (file)
@@ -78,6 +78,7 @@ pub fn run(input: &str,
         external_paths: RefCell::new(Some(HashMap::new())),
         external_traits: RefCell::new(None),
         external_typarams: RefCell::new(None),
+        inlined: RefCell::new(None),
     };
     super::ctxtkey.replace(Some(ctx));