Skip to content

Commit 14fb329

Browse files
committed
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
2 parents f774bce + c62a8c5 commit 14fb329

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/librustdoc/html/render.rs

+12
Original file line numberDiff line numberDiff line change
@@ -762,17 +762,29 @@ fn write_shared(cx: &Context,
762762
}
763763
};
764764

765+
let mut have_impls = false;
765766
let mut implementors = format!(r#"implementors["{}"] = ["#, krate.name);
766767
for imp in imps {
767768
// If the trait and implementation are in the same crate, then
768769
// there's no need to emit information about it (there's inlining
769770
// going on). If they're in different crates then the crate defining
770771
// the trait will be interested in our implementation.
771772
if imp.def_id.krate == did.krate { continue }
773+
// If the implementation is from another crate then that crate
774+
// should add it.
775+
if !imp.def_id.is_local() { continue }
776+
have_impls = true;
772777
write!(implementors, "{},", as_json(&imp.impl_.to_string())).unwrap();
773778
}
774779
implementors.push_str("];");
775780

781+
// Only create a js file if we have impls to add to it. If the trait is
782+
// documented locally though we always create the file to avoid dead
783+
// links.
784+
if !have_impls && !cache.paths.contains_key(&did) {
785+
continue;
786+
}
787+
776788
let mut mydst = dst.clone();
777789
for part in &remote_path[..remote_path.len() - 1] {
778790
mydst.push(part);

src/test/rustdoc/issue-43701.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![crate_name = "foo"]
12+
13+
pub use std::vec::Vec;
14+
15+
// @!has implementors/core/clone/trait.Clone.js

0 commit comments

Comments
 (0)