about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-08-12 22:09:34 +0000
committerbors <bors@rust-lang.org>2017-08-12 22:09:34 +0000
commit14fb329e0a691f04308d0a006d8e744595e8c8dc (patch)
treeaab2962f7e5f72adc8c5befca49139e25beb2cd9 /src
parentf774bced502cf190426f778001a342715acb1d47 (diff)
parentc62a8c5694b5f7fe4f4a27885aabdd85c6e8e821 (diff)
downloadrust-14fb329e0a691f04308d0a006d8e744595e8c8dc.tar.gz
rust-14fb329e0a691f04308d0a006d8e744595e8c8dc.zip
Auto merge of #43736 - ollie27:rustdoc_impls_js, r=QuietMisdreavus
rustdoc: Don't add external impls to implementors js

Otherwise impls from not documented crates appear.

Fixes #43701
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/html/render.rs12
-rw-r--r--src/test/rustdoc/issue-43701.rs15
2 files changed, 27 insertions, 0 deletions
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index 563c5618759..08e5045fb00 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -762,6 +762,7 @@ fn write_shared(cx: &Context,
             }
         };
 
+        let mut have_impls = false;
         let mut implementors = format!(r#"implementors["{}"] = ["#, krate.name);
         for imp in imps {
             // If the trait and implementation are in the same crate, then
@@ -769,10 +770,21 @@ fn write_shared(cx: &Context,
             // going on). If they're in different crates then the crate defining
             // the trait will be interested in our implementation.
             if imp.def_id.krate == did.krate { continue }
+            // If the implementation is from another crate then that crate
+            // should add it.
+            if !imp.def_id.is_local() { continue }
+            have_impls = true;
             write!(implementors, "{},", as_json(&imp.impl_.to_string())).unwrap();
         }
         implementors.push_str("];");
 
+        // Only create a js file if we have impls to add to it. If the trait is
+        // documented locally though we always create the file to avoid dead
+        // links.
+        if !have_impls && !cache.paths.contains_key(&did) {
+            continue;
+        }
+
         let mut mydst = dst.clone();
         for part in &remote_path[..remote_path.len() - 1] {
             mydst.push(part);
diff --git a/src/test/rustdoc/issue-43701.rs b/src/test/rustdoc/issue-43701.rs
new file mode 100644
index 00000000000..791d8319599
--- /dev/null
+++ b/src/test/rustdoc/issue-43701.rs
@@ -0,0 +1,15 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![crate_name = "foo"]
+
+pub use std::vec::Vec;
+
+// @!has implementors/core/clone/trait.Clone.js