Skip to content

Commit dca7f01

Browse files
committed
Remove, now unnecessary, workaround
This used to be done to avoid inlining impls referencing private items, but is now unnecessary since we actually check that impls do not reference non-doc-reachable items.
1 parent cc615b2 commit dca7f01

File tree

7 files changed

+90
-23
lines changed

7 files changed

+90
-23
lines changed

src/librustdoc/clean/inline.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,10 @@ pub fn build_impls(cx: &DocContext,
248248
// Primarily, the impls will be used to populate the documentation for this
249249
// type being inlined, but impls can also be used when generating
250250
// documentation for primitives (no way to find those specifically).
251-
if !cx.all_crate_impls.borrow_mut().contains_key(&did.krate) {
252-
let mut impls = Vec::new();
251+
if cx.populated_crate_impls.borrow_mut().insert(did.krate) {
253252
for item in tcx.sess.cstore.crate_top_level_items(did.krate) {
254253
populate_impls(cx, tcx, item.def, &mut impls);
255254
}
256-
cx.all_crate_impls.borrow_mut().insert(did.krate, impls);
257255

258256
fn populate_impls(cx: &DocContext, tcx: &TyCtxt,
259257
def: cstore::DefLike,
@@ -270,21 +268,7 @@ pub fn build_impls(cx: &DocContext,
270268
}
271269
}
272270

273-
let mut candidates = cx.all_crate_impls.borrow_mut();
274-
let candidates = candidates.get_mut(&did.krate).unwrap();
275-
for i in (0..candidates.len()).rev() {
276-
let remove = match candidates[i].inner {
277-
clean::ImplItem(ref i) => {
278-
i.for_.def_id() == Some(did) || i.for_.primitive_type().is_some()
279-
}
280-
_ => continue,
281-
};
282-
if remove {
283-
impls.push(candidates.swap_remove(i));
284-
}
285-
}
286-
287-
return impls;
271+
impls
288272
}
289273

290274
pub fn build_impl(cx: &DocContext,

src/librustdoc/core.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use syntax::feature_gate::UnstableFeatures;
3030
use syntax::parse::token;
3131

3232
use std::cell::{RefCell, Cell};
33-
use std::collections::HashMap;
33+
use std::collections::{HashMap, HashSet};
3434
use std::rc::Rc;
3535

3636
use visit_ast::RustdocVisitor;
@@ -54,7 +54,7 @@ pub struct DocContext<'a, 'tcx: 'a> {
5454
pub map: &'a hir_map::Map<'tcx>,
5555
pub maybe_typed: MaybeTyped<'a, 'tcx>,
5656
pub input: Input,
57-
pub all_crate_impls: RefCell<HashMap<ast::CrateNum, Vec<clean::Item>>>,
57+
pub populated_crate_impls: RefCell<HashSet<ast::CrateNum>>,
5858
pub deref_trait_did: Cell<Option<DefId>>,
5959
// Note that external items for which `doc(hidden)` applies to are shown as
6060
// non-reachable while local items aren't. This is because we're reusing
@@ -189,7 +189,7 @@ pub fn run_core(search_paths: SearchPaths,
189189
map: &tcx.map,
190190
maybe_typed: Typed(tcx),
191191
input: input,
192-
all_crate_impls: RefCell::new(HashMap::new()),
192+
populated_crate_impls: RefCell::new(HashSet::new()),
193193
deref_trait_did: Cell::new(None),
194194
access_levels: RefCell::new(access_levels),
195195
external_traits: RefCell::new(HashMap::new()),

src/librustdoc/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use std::cell::{RefCell, Cell};
12-
use std::collections::HashMap;
12+
use std::collections::{HashMap, HashSet};
1313
use std::env;
1414
use std::ffi::OsString;
1515
use std::io::prelude::*;
@@ -111,7 +111,7 @@ pub fn run(input: &str,
111111
maybe_typed: core::NotTyped(&sess),
112112
input: input,
113113
external_traits: RefCell::new(HashMap::new()),
114-
all_crate_impls: RefCell::new(HashMap::new()),
114+
populated_crate_impls: RefCell::new(HashSet::new()),
115115
deref_trait_did: Cell::new(None),
116116
access_levels: Default::default(),
117117
renderinfo: Default::default(),

src/test/auxiliary/issue-33113.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2016 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="bar"]
12+
13+
pub trait Bar {}
14+
pub struct Foo;
15+
16+
impl<'a> Bar for &'a char {}
17+
impl Bar for Foo {}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2016 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+
use std::fmt;
12+
13+
pub trait Bar {}
14+
15+
impl<'a> Bar + 'a {
16+
pub fn bar(&self) -> usize { 42 }
17+
}
18+
19+
impl<'a> fmt::Debug for Bar + 'a {
20+
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
21+
Ok(())
22+
}
23+
}
24+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2016 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+
// aux-build:rustdoc-trait-object-impl.rs
12+
// build-aux-docs
13+
// ignore-cross-compile
14+
15+
extern crate rustdoc_trait_object_impl;
16+
17+
// @has issue_32881/trait.Bar.html
18+
// @has - '//code' "impl<'a> Bar"
19+
// @has - '//code' "impl<'a> Debug for Bar"
20+
21+
pub use rustdoc_trait_object_impl::Bar;
22+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2016 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+
// aux-build:issue-33113.rs
12+
// build-aux-docs
13+
// ignore-cross-compile
14+
15+
extern crate bar;
16+
17+
// @has issue_33113/trait.Bar.html
18+
// @has - '//code' "for &'a char"
19+
// @has - '//code' "for Foo"
20+
pub use bar::Bar;

0 commit comments

Comments
 (0)