diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index ccaefadc1fc..519292fa9e0 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -317,6 +317,7 @@ fn build_impl(cx: &DocContext, tcx: &ty::ctxt, } } }).collect(); + let polarity = csearch::get_impl_polarity(tcx, did); return Some(clean::Item { inner: clean::ImplItem(clean::Impl { derived: clean::detect_derived(attrs.as_slice()), @@ -329,6 +330,7 @@ fn build_impl(cx: &DocContext, tcx: &ty::ctxt, for_: ty.ty.clean(cx), generics: (&ty.generics, subst::TypeSpace).clean(cx), items: trait_items, + polarity: polarity.map(|p| { p.clean(cx) }), }), source: clean::Span::empty(), name: None, diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 7342c9f3e81..db945fe9a7b 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2082,6 +2082,21 @@ impl Clean for ast::Mutability { } } +#[derive(Show, Clone, RustcEncodable, RustcDecodable, PartialEq, Copy)] +pub enum ImplPolarity { + Positive, + Negative, +} + +impl Clean for ast::ImplPolarity { + fn clean(&self, _: &DocContext) -> ImplPolarity { + match self { + &ast::ImplPolarity::Positive => ImplPolarity::Positive, + &ast::ImplPolarity::Negative => ImplPolarity::Negative, + } + } +} + #[derive(Clone, RustcEncodable, RustcDecodable)] pub struct Impl { pub generics: Generics, @@ -2089,6 +2104,7 @@ pub struct Impl { pub for_: Type, pub items: Vec, pub derived: bool, + pub polarity: Option, } fn detect_derived(attrs: &[M]) -> bool { @@ -2115,6 +2131,7 @@ impl Clean for doctree::Impl { } }).collect(), derived: detect_derived(self.attrs.as_slice()), + polarity: Some(self.polarity.clean(cx)), }), } } diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index ab9700d966a..9e94db33171 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -2085,6 +2085,10 @@ fn render_impl(w: &mut fmt::Formatter, i: &Impl) -> fmt::Result { try!(write!(w, "

{}impl{} ", ConciseStability(&i.stability), i.impl_.generics)); + match i.impl_.polarity { + Some(clean::ImplPolarity::Negative) => try!(write!(w, "!")), + _ => {} + } match i.impl_.trait_ { Some(ref ty) => try!(write!(w, "{} for ", *ty)), None => {} diff --git a/src/test/run-make/rustdoc-negative-impl/Makefile b/src/test/run-make/rustdoc-negative-impl/Makefile new file mode 100644 index 00000000000..1316ee256e1 --- /dev/null +++ b/src/test/run-make/rustdoc-negative-impl/Makefile @@ -0,0 +1,6 @@ +-include ../tools.mk + +all: foo.rs + $(HOST_RPATH_ENV) $(RUSTDOC) -w html -o $(TMPDIR)/doc foo.rs + $(HTMLDOCCK) $(TMPDIR)/doc foo.rs + diff --git a/src/test/run-make/rustdoc-negative-impl/foo.rs b/src/test/run-make/rustdoc-negative-impl/foo.rs new file mode 100644 index 00000000000..eaa3af86563 --- /dev/null +++ b/src/test/run-make/rustdoc-negative-impl/foo.rs @@ -0,0 +1,22 @@ +// Copyright 2014 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(optin_builtin_traits)] + +// @matches foo/struct.Alpha.html '//pre' "pub struct Alpha" +pub struct Alpha; +// @matches foo/struct.Bravo.html '//pre' "pub struct Bravo" +pub struct Bravo; + +// @matches foo/struct.Alpha.html '//*[@class="impl"]//code' "impl !.*Send.* for .*Alpha" +impl !Send for Alpha {} + +// @matches foo/struct.Bravo.html '//*[@class="impl"]//code' "impl !.*Send.* for .*Bravo.*" +impl !Send for Bravo {}