mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Rollup merge of #47672 - ollie27:rustdoc_auto_traits, r=GuillaumeGomez
rustdoc: Show when traits are auto traits
This commit is contained in:
commit
9707b31076
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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>,
|
||||
|
@ -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)?;
|
||||
|
@ -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,
|
||||
|
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…
Reference in New Issue
Block a user