Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc: inline all the impls #33133

Merged
merged 3 commits into from
Apr 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 3 additions & 18 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ fn try_inline_def(cx: &DocContext, tcx: &TyCtxt,
let inner = match def {
Def::Trait(did) => {
record_extern_fqn(cx, did, clean::TypeTrait);
ret.extend(build_impls(cx, tcx, did));
clean::TraitItem(build_external_trait(cx, tcx, did))
}
Def::Fn(did) => {
Expand Down Expand Up @@ -247,12 +248,10 @@ pub fn build_impls(cx: &DocContext,
// Primarily, the impls will be used to populate the documentation for this
// type being inlined, but impls can also be used when generating
// documentation for primitives (no way to find those specifically).
if !cx.all_crate_impls.borrow_mut().contains_key(&did.krate) {
let mut impls = Vec::new();
if cx.populated_crate_impls.borrow_mut().insert(did.krate) {
for item in tcx.sess.cstore.crate_top_level_items(did.krate) {
populate_impls(cx, tcx, item.def, &mut impls);
}
cx.all_crate_impls.borrow_mut().insert(did.krate, impls);

fn populate_impls(cx: &DocContext, tcx: &TyCtxt,
def: cstore::DefLike,
Expand All @@ -269,21 +268,7 @@ pub fn build_impls(cx: &DocContext,
}
}

let mut candidates = cx.all_crate_impls.borrow_mut();
let candidates = candidates.get_mut(&did.krate).unwrap();
for i in (0..candidates.len()).rev() {
let remove = match candidates[i].inner {
clean::ImplItem(ref i) => {
i.for_.def_id() == Some(did) || i.for_.primitive_type().is_some()
}
_ => continue,
};
if remove {
impls.push(candidates.swap_remove(i));
}
}

return impls;
impls
}

pub fn build_impl(cx: &DocContext,
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use syntax::feature_gate::UnstableFeatures;
use syntax::parse::token;

use std::cell::{RefCell, Cell};
use std::collections::HashMap;
use std::collections::{HashMap, HashSet};
use std::rc::Rc;

use visit_ast::RustdocVisitor;
Expand All @@ -54,7 +54,7 @@ pub struct DocContext<'a, 'tcx: 'a> {
pub map: &'a hir_map::Map<'tcx>,
pub maybe_typed: MaybeTyped<'a, 'tcx>,
pub input: Input,
pub all_crate_impls: RefCell<HashMap<ast::CrateNum, Vec<clean::Item>>>,
pub populated_crate_impls: RefCell<HashSet<ast::CrateNum>>,
pub deref_trait_did: Cell<Option<DefId>>,
// Note that external items for which `doc(hidden)` applies to are shown as
// non-reachable while local items aren't. This is because we're reusing
Expand Down Expand Up @@ -189,7 +189,7 @@ pub fn run_core(search_paths: SearchPaths,
map: &tcx.map,
maybe_typed: Typed(tcx),
input: input,
all_crate_impls: RefCell::new(HashMap::new()),
populated_crate_impls: RefCell::new(HashSet::new()),
deref_trait_did: Cell::new(None),
access_levels: RefCell::new(access_levels),
external_traits: RefCell::new(HashMap::new()),
Expand Down
8 changes: 5 additions & 3 deletions src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,17 +291,19 @@ impl fmt::Display for clean::Path {

pub fn href(did: DefId) -> Option<(String, ItemType, Vec<String>)> {
let cache = cache();
if !did.is_local() && !cache.access_levels.is_doc_reachable(did) {
return None
}

let loc = CURRENT_LOCATION_KEY.with(|l| l.borrow().clone());
let &(ref fqp, shortty) = match cache.paths.get(&did) {
Some(p) => p,
None => return None,
};

let mut url = if did.is_local() || cache.inlined.contains(&did) {
repeat("../").take(loc.len()).collect::<String>()
} else {
if !cache.access_levels.is_doc_reachable(did) {
return None
}
match cache.extern_locations[&did.krate] {
(_, render::Remote(ref s)) => s.to_string(),
(_, render::Local) => repeat("../").take(loc.len()).collect(),
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

use std::cell::{RefCell, Cell};
use std::collections::HashMap;
use std::collections::{HashMap, HashSet};
use std::env;
use std::ffi::OsString;
use std::io::prelude::*;
Expand Down Expand Up @@ -111,7 +111,7 @@ pub fn run(input: &str,
maybe_typed: core::NotTyped(&sess),
input: input,
external_traits: RefCell::new(HashMap::new()),
all_crate_impls: RefCell::new(HashMap::new()),
populated_crate_impls: RefCell::new(HashSet::new()),
deref_trait_did: Cell::new(None),
access_levels: Default::default(),
renderinfo: Default::default(),
Expand Down
17 changes: 17 additions & 0 deletions src/test/auxiliary/issue-33113.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2016 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="bar"]

pub trait Bar {}
pub struct Foo;

impl<'a> Bar for &'a char {}
impl Bar for Foo {}
14 changes: 14 additions & 0 deletions src/test/auxiliary/rustdoc-hidden.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2016 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.

#[doc(hidden)]
pub struct Foo;

pub struct Bar;
24 changes: 24 additions & 0 deletions src/test/auxiliary/rustdoc-trait-object-impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2016 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.

use std::fmt;

pub trait Bar {}

impl<'a> Bar + 'a {
pub fn bar(&self) -> usize { 42 }
}

impl<'a> fmt::Debug for Bar + 'a {
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
Ok(())
}
}

22 changes: 22 additions & 0 deletions src/test/rustdoc/inline_cross/inline_hidden.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2016 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.

// aux-build:rustdoc-hidden.rs
// build-aux-docs
// ignore-cross-compile

extern crate rustdoc_hidden;

#[doc(no_inline)]
pub use rustdoc_hidden::Foo;

// @has inline_hidden/fn.foo.html
// @!has - '//a/@title' 'Foo'
pub fn foo(_: Foo) {}
22 changes: 22 additions & 0 deletions src/test/rustdoc/inline_cross/issue-32881.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2016 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.

// aux-build:rustdoc-trait-object-impl.rs
// build-aux-docs
// ignore-cross-compile

extern crate rustdoc_trait_object_impl;

// @has issue_32881/trait.Bar.html
// @has - '//code' "impl<'a> Bar"
// @has - '//code' "impl<'a> Debug for Bar"

pub use rustdoc_trait_object_impl::Bar;

20 changes: 20 additions & 0 deletions src/test/rustdoc/inline_cross/issue-33113.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2016 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.

// aux-build:issue-33113.rs
// build-aux-docs
// ignore-cross-compile

extern crate bar;

// @has issue_33113/trait.Bar.html
// @has - '//code' "for &'a char"
// @has - '//code' "for Foo"
pub use bar::Bar;