Skip to content

Commit

Permalink
Rollup merge of rust-lang#47672 - ollie27:rustdoc_auto_traits, r=Guil…
Browse files Browse the repository at this point in the history
…laumeGomez

rustdoc: Show when traits are auto traits
  • Loading branch information
kennytm committed Jan 23, 2018
2 parents 9735864 + 04a8847 commit 9707b31
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,14 @@ pub fn build_external_trait(cx: &DocContext, did: DefId) -> clean::Trait {
let generics = filter_non_trait_generics(did, generics);
let (generics, supertrait_bounds) = separate_supertrait_bounds(generics);
let is_spotlight = load_attrs(cx, did).has_doc_flag("spotlight");
let is_auto = cx.tcx.trait_is_auto(did);
clean::Trait {
unsafety: cx.tcx.trait_def(did).unsafety,
generics,
items: trait_items,
bounds: supertrait_bounds,
is_spotlight,
is_auto,
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1523,6 +1523,7 @@ pub struct Trait {
pub generics: Generics,
pub bounds: Vec<TyParamBound>,
pub is_spotlight: bool,
pub is_auto: bool,
}

impl Clean<Item> for doctree::Trait {
Expand All @@ -1543,11 +1544,21 @@ impl Clean<Item> for doctree::Trait {
generics: self.generics.clean(cx),
bounds: self.bounds.clean(cx),
is_spotlight: is_spotlight,
is_auto: self.is_auto.clean(cx),
}),
}
}
}

impl Clean<bool> for hir::IsAuto {
fn clean(&self, _: &DocContext) -> bool {
match *self {
hir::IsAuto::Yes => true,
hir::IsAuto::No => false,
}
}
}

impl Clean<Type> for hir::TraitRef {
fn clean(&self, cx: &DocContext) -> Type {
resolve_type(cx, self.path.clean(cx), self.ref_id)
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/doctree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ pub struct Constant {
}

pub struct Trait {
pub is_auto: hir::IsAuto,
pub unsafety: hir::Unsafety,
pub name: Name,
pub items: hir::HirVec<hir::TraitItem>,
Expand Down
3 changes: 2 additions & 1 deletion src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2339,9 +2339,10 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
// Output the trait definition
write!(w, "<pre class='rust trait'>")?;
render_attributes(w, it)?;
write!(w, "{}{}trait {}{}{}",
write!(w, "{}{}{}trait {}{}{}",
VisSpace(&it.visibility),
UnsafetySpace(t.unsafety),
if t.is_auto { "auto " } else { "" },
it.name.as_ref().unwrap(),
t.generics,
bounds)?;
Expand Down
3 changes: 2 additions & 1 deletion src/librustdoc/visit_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,11 +494,12 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
};
om.constants.push(s);
},
hir::ItemTrait(_, unsafety, ref gen, ref b, ref item_ids) => {
hir::ItemTrait(is_auto, unsafety, ref gen, ref b, ref item_ids) => {
let items = item_ids.iter()
.map(|ti| self.cx.tcx.hir.trait_item(ti.id).clone())
.collect();
let t = Trait {
is_auto,
unsafety,
name,
items,
Expand Down
23 changes: 23 additions & 0 deletions src/test/rustdoc/auto-traits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2018 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:auto-traits.rs

#![feature(optin_builtin_traits)]

#![crate_name = "foo"]

extern crate auto_traits;

// @has 'foo/trait.Foo.html' '//pre' 'pub unsafe auto trait Foo'
pub unsafe auto trait Foo {}

// @has 'foo/trait.Bar.html' '//pre' 'pub unsafe auto trait Bar'
pub use auto_traits::Bar;
13 changes: 13 additions & 0 deletions src/test/rustdoc/auxiliary/auto-traits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2018 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.

#![feature(optin_builtin_traits)]

pub unsafe auto trait Bar {}

0 comments on commit 9707b31

Please sign in to comment.