Skip to content

Commit 9707b31

Browse files
committed
Rollup merge of #47672 - ollie27:rustdoc_auto_traits, r=GuillaumeGomez
rustdoc: Show when traits are auto traits
2 parents 9735864 + 04a8847 commit 9707b31

File tree

7 files changed

+54
-2
lines changed

7 files changed

+54
-2
lines changed

src/librustdoc/clean/inline.rs

+2
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,14 @@ pub fn build_external_trait(cx: &DocContext, did: DefId) -> clean::Trait {
146146
let generics = filter_non_trait_generics(did, generics);
147147
let (generics, supertrait_bounds) = separate_supertrait_bounds(generics);
148148
let is_spotlight = load_attrs(cx, did).has_doc_flag("spotlight");
149+
let is_auto = cx.tcx.trait_is_auto(did);
149150
clean::Trait {
150151
unsafety: cx.tcx.trait_def(did).unsafety,
151152
generics,
152153
items: trait_items,
153154
bounds: supertrait_bounds,
154155
is_spotlight,
156+
is_auto,
155157
}
156158
}
157159

src/librustdoc/clean/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1523,6 +1523,7 @@ pub struct Trait {
15231523
pub generics: Generics,
15241524
pub bounds: Vec<TyParamBound>,
15251525
pub is_spotlight: bool,
1526+
pub is_auto: bool,
15261527
}
15271528

15281529
impl Clean<Item> for doctree::Trait {
@@ -1543,11 +1544,21 @@ impl Clean<Item> for doctree::Trait {
15431544
generics: self.generics.clean(cx),
15441545
bounds: self.bounds.clean(cx),
15451546
is_spotlight: is_spotlight,
1547+
is_auto: self.is_auto.clean(cx),
15461548
}),
15471549
}
15481550
}
15491551
}
15501552

1553+
impl Clean<bool> for hir::IsAuto {
1554+
fn clean(&self, _: &DocContext) -> bool {
1555+
match *self {
1556+
hir::IsAuto::Yes => true,
1557+
hir::IsAuto::No => false,
1558+
}
1559+
}
1560+
}
1561+
15511562
impl Clean<Type> for hir::TraitRef {
15521563
fn clean(&self, cx: &DocContext) -> Type {
15531564
resolve_type(cx, self.path.clean(cx), self.ref_id)

src/librustdoc/doctree.rs

+1
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ pub struct Constant {
196196
}
197197

198198
pub struct Trait {
199+
pub is_auto: hir::IsAuto,
199200
pub unsafety: hir::Unsafety,
200201
pub name: Name,
201202
pub items: hir::HirVec<hir::TraitItem>,

src/librustdoc/html/render.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2339,9 +2339,10 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
23392339
// Output the trait definition
23402340
write!(w, "<pre class='rust trait'>")?;
23412341
render_attributes(w, it)?;
2342-
write!(w, "{}{}trait {}{}{}",
2342+
write!(w, "{}{}{}trait {}{}{}",
23432343
VisSpace(&it.visibility),
23442344
UnsafetySpace(t.unsafety),
2345+
if t.is_auto { "auto " } else { "" },
23452346
it.name.as_ref().unwrap(),
23462347
t.generics,
23472348
bounds)?;

src/librustdoc/visit_ast.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -494,11 +494,12 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
494494
};
495495
om.constants.push(s);
496496
},
497-
hir::ItemTrait(_, unsafety, ref gen, ref b, ref item_ids) => {
497+
hir::ItemTrait(is_auto, unsafety, ref gen, ref b, ref item_ids) => {
498498
let items = item_ids.iter()
499499
.map(|ti| self.cx.tcx.hir.trait_item(ti.id).clone())
500500
.collect();
501501
let t = Trait {
502+
is_auto,
502503
unsafety,
503504
name,
504505
items,

src/test/rustdoc/auto-traits.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// aux-build:auto-traits.rs
12+
13+
#![feature(optin_builtin_traits)]
14+
15+
#![crate_name = "foo"]
16+
17+
extern crate auto_traits;
18+
19+
// @has 'foo/trait.Foo.html' '//pre' 'pub unsafe auto trait Foo'
20+
pub unsafe auto trait Foo {}
21+
22+
// @has 'foo/trait.Bar.html' '//pre' 'pub unsafe auto trait Bar'
23+
pub use auto_traits::Bar;
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(optin_builtin_traits)]
12+
13+
pub unsafe auto trait Bar {}

0 commit comments

Comments
 (0)