Skip to content

Commit eb08650

Browse files
committed
Display negative trait implementations correctly in rustdoc
Added doc test
1 parent a0f86de commit eb08650

File tree

5 files changed

+51
-0
lines changed

5 files changed

+51
-0
lines changed

src/librustdoc/clean/inline.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ fn build_impl(cx: &DocContext, tcx: &ty::ctxt,
317317
}
318318
}
319319
}).collect();
320+
let polarity = csearch::get_impl_polarity(tcx, did);
320321
return Some(clean::Item {
321322
inner: clean::ImplItem(clean::Impl {
322323
derived: clean::detect_derived(attrs.as_slice()),
@@ -329,6 +330,7 @@ fn build_impl(cx: &DocContext, tcx: &ty::ctxt,
329330
for_: ty.ty.clean(cx),
330331
generics: (&ty.generics, subst::TypeSpace).clean(cx),
331332
items: trait_items,
333+
polarity: polarity.map(|p| { p.clean(cx) }),
332334
}),
333335
source: clean::Span::empty(),
334336
name: None,

src/librustdoc/clean/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,13 +2082,29 @@ impl Clean<Mutability> for ast::Mutability {
20822082
}
20832083
}
20842084

2085+
#[derive(Show, Clone, RustcEncodable, RustcDecodable, PartialEq, Copy)]
2086+
pub enum ImplPolarity {
2087+
Positive,
2088+
Negative,
2089+
}
2090+
2091+
impl Clean<ImplPolarity> for ast::ImplPolarity {
2092+
fn clean(&self, _: &DocContext) -> ImplPolarity {
2093+
match self {
2094+
&ast::ImplPolarity::Positive => ImplPolarity::Positive,
2095+
&ast::ImplPolarity::Negative => ImplPolarity::Negative,
2096+
}
2097+
}
2098+
}
2099+
20852100
#[derive(Clone, RustcEncodable, RustcDecodable)]
20862101
pub struct Impl {
20872102
pub generics: Generics,
20882103
pub trait_: Option<Type>,
20892104
pub for_: Type,
20902105
pub items: Vec<Item>,
20912106
pub derived: bool,
2107+
pub polarity: Option<ImplPolarity>,
20922108
}
20932109

20942110
fn detect_derived<M: AttrMetaMethods>(attrs: &[M]) -> bool {
@@ -2115,6 +2131,7 @@ impl Clean<Item> for doctree::Impl {
21152131
}
21162132
}).collect(),
21172133
derived: detect_derived(self.attrs.as_slice()),
2134+
polarity: Some(self.polarity.clean(cx)),
21182135
}),
21192136
}
21202137
}

src/librustdoc/html/render.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,6 +2085,10 @@ fn render_impl(w: &mut fmt::Formatter, i: &Impl) -> fmt::Result {
20852085
try!(write!(w, "<h3 class='impl'>{}<code>impl{} ",
20862086
ConciseStability(&i.stability),
20872087
i.impl_.generics));
2088+
match i.impl_.polarity {
2089+
Some(clean::ImplPolarity::Negative) => try!(write!(w, "!")),
2090+
_ => {}
2091+
}
20882092
match i.impl_.trait_ {
20892093
Some(ref ty) => try!(write!(w, "{} for ", *ty)),
20902094
None => {}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-include ../tools.mk
2+
3+
all: foo.rs
4+
$(HOST_RPATH_ENV) $(RUSTDOC) -w html -o $(TMPDIR)/doc foo.rs
5+
$(HTMLDOCCK) $(TMPDIR)/doc foo.rs
6+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2014 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+
// @matches foo/struct.Alpha.html '//pre' "pub struct Alpha"
14+
pub struct Alpha;
15+
// @matches foo/struct.Bravo.html '//pre' "pub struct Bravo<B>"
16+
pub struct Bravo<B>;
17+
18+
// @matches foo/struct.Alpha.html '//*[@class="impl"]//code' "impl !.*Send.* for .*Alpha"
19+
impl !Send for Alpha {}
20+
21+
// @matches foo/struct.Bravo.html '//*[@class="impl"]//code' "impl<B> !.*Send.* for .*Bravo.*<B>"
22+
impl<B> !Send for Bravo<B> {}

0 commit comments

Comments
 (0)