Rollup merge of #47672 - ollie27:rustdoc_auto_traits, r=GuillaumeGomez

rustdoc: Show when traits are auto traits
This commit is contained in:
kennytm 2018-01-23 17:03:47 +08:00
commit 9707b31076
No known key found for this signature in database
GPG Key ID: FEF6C8051D0E013C
7 changed files with 54 additions and 2 deletions

View File

@ -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,
}
}

View File

@ -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 {
@ -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)

View File

@ -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>,

View File

@ -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)?;

View File

@ -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,

View File

@ -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;

View File

@ -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 {}