mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 15:23:46 +00:00
Display negative trait implementations correctly in rustdoc
Added doc test
This commit is contained in:
parent
a0f86de497
commit
eb086505b8
@ -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,
|
||||
|
@ -2082,6 +2082,21 @@ impl Clean<Mutability> for ast::Mutability {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Show, Clone, RustcEncodable, RustcDecodable, PartialEq, Copy)]
|
||||
pub enum ImplPolarity {
|
||||
Positive,
|
||||
Negative,
|
||||
}
|
||||
|
||||
impl Clean<ImplPolarity> 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<Item>,
|
||||
pub derived: bool,
|
||||
pub polarity: Option<ImplPolarity>,
|
||||
}
|
||||
|
||||
fn detect_derived<M: AttrMetaMethods>(attrs: &[M]) -> bool {
|
||||
@ -2115,6 +2131,7 @@ impl Clean<Item> for doctree::Impl {
|
||||
}
|
||||
}).collect(),
|
||||
derived: detect_derived(self.attrs.as_slice()),
|
||||
polarity: Some(self.polarity.clean(cx)),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
@ -2085,6 +2085,10 @@ fn render_impl(w: &mut fmt::Formatter, i: &Impl) -> fmt::Result {
|
||||
try!(write!(w, "<h3 class='impl'>{}<code>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 => {}
|
||||
|
6
src/test/run-make/rustdoc-negative-impl/Makefile
Normal file
6
src/test/run-make/rustdoc-negative-impl/Makefile
Normal file
@ -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
|
||||
|
22
src/test/run-make/rustdoc-negative-impl/foo.rs
Normal file
22
src/test/run-make/rustdoc-negative-impl/foo.rs
Normal file
@ -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 <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)]
|
||||
|
||||
// @matches foo/struct.Alpha.html '//pre' "pub struct Alpha"
|
||||
pub struct Alpha;
|
||||
// @matches foo/struct.Bravo.html '//pre' "pub struct Bravo<B>"
|
||||
pub struct Bravo<B>;
|
||||
|
||||
// @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<B> !.*Send.* for .*Bravo.*<B>"
|
||||
impl<B> !Send for Bravo<B> {}
|
Loading…
Reference in New Issue
Block a user