rustdoc: Show when traits are auto traits
This commit is contained in:
parent
fdc18b3067
commit
04a884726a
7 changed files with 54 additions and 2 deletions
|
@ -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 = filter_non_trait_generics(did, generics);
|
||||||
let (generics, supertrait_bounds) = separate_supertrait_bounds(generics);
|
let (generics, supertrait_bounds) = separate_supertrait_bounds(generics);
|
||||||
let is_spotlight = load_attrs(cx, did).has_doc_flag("spotlight");
|
let is_spotlight = load_attrs(cx, did).has_doc_flag("spotlight");
|
||||||
|
let is_auto = cx.tcx.trait_is_auto(did);
|
||||||
clean::Trait {
|
clean::Trait {
|
||||||
unsafety: cx.tcx.trait_def(did).unsafety,
|
unsafety: cx.tcx.trait_def(did).unsafety,
|
||||||
generics,
|
generics,
|
||||||
items: trait_items,
|
items: trait_items,
|
||||||
bounds: supertrait_bounds,
|
bounds: supertrait_bounds,
|
||||||
is_spotlight,
|
is_spotlight,
|
||||||
|
is_auto,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1523,6 +1523,7 @@ pub struct Trait {
|
||||||
pub generics: Generics,
|
pub generics: Generics,
|
||||||
pub bounds: Vec<TyParamBound>,
|
pub bounds: Vec<TyParamBound>,
|
||||||
pub is_spotlight: bool,
|
pub is_spotlight: bool,
|
||||||
|
pub is_auto: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clean<Item> for doctree::Trait {
|
impl Clean<Item> for doctree::Trait {
|
||||||
|
@ -1543,11 +1544,21 @@ impl Clean<Item> for doctree::Trait {
|
||||||
generics: self.generics.clean(cx),
|
generics: self.generics.clean(cx),
|
||||||
bounds: self.bounds.clean(cx),
|
bounds: self.bounds.clean(cx),
|
||||||
is_spotlight: is_spotlight,
|
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 {
|
impl Clean<Type> for hir::TraitRef {
|
||||||
fn clean(&self, cx: &DocContext) -> Type {
|
fn clean(&self, cx: &DocContext) -> Type {
|
||||||
resolve_type(cx, self.path.clean(cx), self.ref_id)
|
resolve_type(cx, self.path.clean(cx), self.ref_id)
|
||||||
|
|
|
@ -196,6 +196,7 @@ pub struct Constant {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Trait {
|
pub struct Trait {
|
||||||
|
pub is_auto: hir::IsAuto,
|
||||||
pub unsafety: hir::Unsafety,
|
pub unsafety: hir::Unsafety,
|
||||||
pub name: Name,
|
pub name: Name,
|
||||||
pub items: hir::HirVec<hir::TraitItem>,
|
pub items: hir::HirVec<hir::TraitItem>,
|
||||||
|
|
|
@ -2339,9 +2339,10 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
||||||
// Output the trait definition
|
// Output the trait definition
|
||||||
write!(w, "<pre class='rust trait'>")?;
|
write!(w, "<pre class='rust trait'>")?;
|
||||||
render_attributes(w, it)?;
|
render_attributes(w, it)?;
|
||||||
write!(w, "{}{}trait {}{}{}",
|
write!(w, "{}{}{}trait {}{}{}",
|
||||||
VisSpace(&it.visibility),
|
VisSpace(&it.visibility),
|
||||||
UnsafetySpace(t.unsafety),
|
UnsafetySpace(t.unsafety),
|
||||||
|
if t.is_auto { "auto " } else { "" },
|
||||||
it.name.as_ref().unwrap(),
|
it.name.as_ref().unwrap(),
|
||||||
t.generics,
|
t.generics,
|
||||||
bounds)?;
|
bounds)?;
|
||||||
|
|
|
@ -494,11 +494,12 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||||
};
|
};
|
||||||
om.constants.push(s);
|
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()
|
let items = item_ids.iter()
|
||||||
.map(|ti| self.cx.tcx.hir.trait_item(ti.id).clone())
|
.map(|ti| self.cx.tcx.hir.trait_item(ti.id).clone())
|
||||||
.collect();
|
.collect();
|
||||||
let t = Trait {
|
let t = Trait {
|
||||||
|
is_auto,
|
||||||
unsafety,
|
unsafety,
|
||||||
name,
|
name,
|
||||||
items,
|
items,
|
||||||
|
|
23
src/test/rustdoc/auto-traits.rs
Normal file
23
src/test/rustdoc/auto-traits.rs
Normal 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;
|
13
src/test/rustdoc/auxiliary/auto-traits.rs
Normal file
13
src/test/rustdoc/auxiliary/auto-traits.rs
Normal 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 {}
|
Loading…
Add table
Add a link
Reference in a new issue