Skip to content

Commit 9d68820

Browse files
committed
---
yaml --- r: 209320 b: refs/heads/auto c: fe85342 h: refs/heads/master v: v3
1 parent adc1779 commit 9d68820

File tree

12 files changed

+128
-52
lines changed

12 files changed

+128
-52
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: 570a0435765864e2e51c8f953a645c544e9afdd4
13+
refs/heads/auto: fe85342ef6c04aeb35b0d0dbde82791f1a8721bb
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/librustdoc/clean/inline.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ fn build_type(cx: &DocContext, tcx: &ty::ctxt, did: ast::DefId) -> clean::ItemEn
217217
clean::TypedefItem(clean::Typedef {
218218
type_: t.ty.clean(cx),
219219
generics: (&t.generics, &predicates, subst::TypeSpace).clean(cx),
220-
})
220+
}, false)
221221
}
222222

223223
pub fn build_impls(cx: &DocContext, tcx: &ty::ctxt,
@@ -370,7 +370,7 @@ pub fn build_impl(cx: &DocContext,
370370
subst::ParamSpace::TypeSpace).clean(cx);
371371
Some(clean::Item {
372372
name: Some(assoc_ty.name.clean(cx)),
373-
inner: clean::TypedefItem(typedef),
373+
inner: clean::TypedefItem(typedef, true),
374374
source: clean::Span::empty(),
375375
attrs: vec![],
376376
visibility: None,

branches/auto/src/librustdoc/clean/mod.rs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ pub enum ItemEnum {
343343
EnumItem(Enum),
344344
FunctionItem(Function),
345345
ModuleItem(Module),
346-
TypedefItem(Typedef),
346+
TypedefItem(Typedef, bool /* is associated type */),
347347
StaticItem(Static),
348348
ConstantItem(Constant),
349349
TraitItem(Trait),
@@ -664,6 +664,7 @@ impl Clean<TyParamBound> for ty::BuiltinBound {
664664
path: path,
665665
typarams: None,
666666
did: did,
667+
is_generic: false,
667668
},
668669
lifetimes: vec![]
669670
}, ast::TraitBoundModifier::None)
@@ -706,7 +707,12 @@ impl<'tcx> Clean<TyParamBound> for ty::TraitRef<'tcx> {
706707
}
707708

708709
TraitBound(PolyTrait {
709-
trait_: ResolvedPath { path: path, typarams: None, did: self.def_id, },
710+
trait_: ResolvedPath {
711+
path: path,
712+
typarams: None,
713+
did: self.def_id,
714+
is_generic: false,
715+
},
710716
lifetimes: late_bounds
711717
}, ast::TraitBoundModifier::None)
712718
}
@@ -1286,7 +1292,7 @@ impl Clean<Item> for ast::ImplItem {
12861292
type_params: Vec::new(),
12871293
where_predicates: Vec::new()
12881294
},
1289-
}),
1295+
}, true),
12901296
ast::MacImplItem(_) => {
12911297
MacroItem(Macro {
12921298
source: self.span.to_src(cx),
@@ -1401,11 +1407,13 @@ pub struct PolyTrait {
14011407
/// it does not preserve mutability or boxes.
14021408
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Debug)]
14031409
pub enum Type {
1404-
/// structs/enums/traits (anything that'd be an ast::TyPath)
1410+
/// structs/enums/traits (most that'd be an ast::TyPath)
14051411
ResolvedPath {
14061412
path: Path,
14071413
typarams: Option<Vec<TyParamBound>>,
14081414
did: ast::DefId,
1415+
/// true if is a `T::Name` path for associated types
1416+
is_generic: bool,
14091417
},
14101418
/// For parameterized types, so the consumer of the JSON don't go
14111419
/// looking for types which don't exist anywhere.
@@ -1594,8 +1602,13 @@ impl Clean<Type> for ast::Ty {
15941602
TyObjectSum(ref lhs, ref bounds) => {
15951603
let lhs_ty = lhs.clean(cx);
15961604
match lhs_ty {
1597-
ResolvedPath { path, typarams: None, did } => {
1598-
ResolvedPath { path: path, typarams: Some(bounds.clean(cx)), did: did}
1605+
ResolvedPath { path, typarams: None, did, is_generic } => {
1606+
ResolvedPath {
1607+
path: path,
1608+
typarams: Some(bounds.clean(cx)),
1609+
did: did,
1610+
is_generic: is_generic,
1611+
}
15991612
}
16001613
_ => {
16011614
lhs_ty // shouldn't happen
@@ -1675,6 +1688,7 @@ impl<'tcx> Clean<Type> for ty::Ty<'tcx> {
16751688
path: path,
16761689
typarams: None,
16771690
did: did,
1691+
is_generic: false,
16781692
}
16791693
}
16801694
ty::ty_trait(box ty::TyTrait { ref principal, ref bounds }) => {
@@ -1689,6 +1703,7 @@ impl<'tcx> Clean<Type> for ty::Ty<'tcx> {
16891703
path: path,
16901704
typarams: Some(typarams),
16911705
did: did,
1706+
is_generic: false,
16921707
}
16931708
}
16941709
ty::ty_tup(ref t) => Tuple(t.clean(cx)),
@@ -2085,7 +2100,7 @@ impl Clean<Item> for doctree::Typedef {
20852100
inner: TypedefItem(Typedef {
20862101
type_: self.ty.clean(cx),
20872102
generics: self.gen.clean(cx),
2088-
}),
2103+
}, false),
20892104
}
20902105
}
20912106
}
@@ -2255,7 +2270,7 @@ fn build_deref_target_impls(cx: &DocContext,
22552270

22562271
for item in items {
22572272
let target = match item.inner {
2258-
TypedefItem(ref t) => &t.type_,
2273+
TypedefItem(ref t, true) => &t.type_,
22592274
_ => continue,
22602275
};
22612276
let primitive = match *target {
@@ -2580,10 +2595,7 @@ fn resolve_type(cx: &DocContext,
25802595
None => panic!("unresolved id not in defmap")
25812596
};
25822597

2583-
match def {
2584-
def::DefSelfTy(..) if path.segments.len() == 1 => {
2585-
return Generic(token::get_name(special_idents::type_self.name).to_string());
2586-
}
2598+
let is_generic = match def {
25872599
def::DefPrimTy(p) => match p {
25882600
ast::TyStr => return Primitive(Str),
25892601
ast::TyBool => return Primitive(Bool),
@@ -2601,13 +2613,14 @@ fn resolve_type(cx: &DocContext,
26012613
ast::TyFloat(ast::TyF32) => return Primitive(F32),
26022614
ast::TyFloat(ast::TyF64) => return Primitive(F64),
26032615
},
2604-
def::DefTyParam(_, _, _, n) => {
2605-
return Generic(token::get_name(n).to_string())
2616+
def::DefSelfTy(..) if path.segments.len() == 1 => {
2617+
return Generic(token::get_name(special_idents::type_self.name).to_string());
26062618
}
2607-
_ => {}
2619+
def::DefSelfTy(..) | def::DefTyParam(..) => true,
2620+
_ => false,
26082621
};
26092622
let did = register_def(&*cx, def);
2610-
ResolvedPath { path: path, typarams: None, did: did }
2623+
ResolvedPath { path: path, typarams: None, did: did, is_generic: is_generic }
26112624
}
26122625

26132626
fn register_def(cx: &DocContext, def: def::Def) -> ast::DefId {
@@ -2821,6 +2834,7 @@ fn lang_struct(cx: &DocContext, did: Option<ast::DefId>,
28212834
}
28222835
}],
28232836
},
2837+
is_generic: false,
28242838
}
28252839
}
28262840

branches/auto/src/librustdoc/html/format.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,9 @@ impl fmt::Display for clean::Type {
437437
clean::Generic(ref name) => {
438438
f.write_str(name)
439439
}
440-
clean::ResolvedPath{ did, ref typarams, ref path } => {
441-
// Paths like Self::Output should be rendered with all segments
442-
try!(resolved_path(f, did, path, path.segments[0].name == "Self"));
440+
clean::ResolvedPath{ did, ref typarams, ref path, is_generic } => {
441+
// Paths like T::Output and Self::Output should be rendered with all segments
442+
try!(resolved_path(f, did, path, is_generic));
443443
tybounds(f, typarams)
444444
}
445445
clean::Infer => write!(f, "_"),

branches/auto/src/librustdoc/html/render.rs

Lines changed: 49 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,20 @@ use std::sync::Arc;
5151

5252
use externalfiles::ExternalHtml;
5353

54-
use serialize::json;
55-
use serialize::json::ToJson;
56-
use syntax::abi;
57-
use syntax::ast;
58-
use syntax::ast_util;
59-
use syntax::attr;
54+
use serialize::json::{self, ToJson};
55+
use syntax::{abi, ast, ast_util, attr};
6056
use rustc::util::nodemap::NodeSet;
6157

62-
use clean;
58+
use clean::{self, SelfTy};
6359
use doctree;
6460
use fold::DocFolder;
6561
use html::escape::Escape;
6662
use html::format::{ConstnessSpace};
6763
use html::format::{TyParamBounds, WhereClause, href, AbiSpace};
6864
use html::format::{VisSpace, Method, UnsafetySpace, MutableSpace};
69-
use html::highlight;
7065
use html::item_type::ItemType;
71-
use html::layout;
72-
use html::markdown::Markdown;
73-
use html::markdown;
66+
use html::markdown::{self, Markdown};
67+
use html::{highlight, layout};
7468

7569
/// A pair of name and its optional document.
7670
pub type NameDoc = (String, Option<String>);
@@ -871,7 +865,7 @@ impl DocFolder for Cache {
871865
clean::StructItem(ref s) => self.generics(&s.generics),
872866
clean::EnumItem(ref e) => self.generics(&e.generics),
873867
clean::FunctionItem(ref f) => self.generics(&f.generics),
874-
clean::TypedefItem(ref t) => self.generics(&t.generics),
868+
clean::TypedefItem(ref t, _) => self.generics(&t.generics),
875869
clean::TraitItem(ref t) => self.generics(&t.generics),
876870
clean::ImplItem(ref i) => self.generics(&i.generics),
877871
clean::TyMethodItem(ref i) => self.generics(&i.generics),
@@ -937,6 +931,10 @@ impl DocFolder for Cache {
937931
((Some(*last), path), true)
938932
}
939933
}
934+
clean::TypedefItem(_, true) => {
935+
// skip associated types in impls
936+
((None, None), false)
937+
}
940938
_ => ((None, Some(&*self.stack)), false)
941939
};
942940
let hidden_field = match item.inner {
@@ -1498,7 +1496,7 @@ impl<'a> fmt::Display for Item<'a> {
14981496
clean::TraitItem(ref t) => item_trait(fmt, self.cx, self.item, t),
14991497
clean::StructItem(ref s) => item_struct(fmt, self.item, s),
15001498
clean::EnumItem(ref e) => item_enum(fmt, self.item, e),
1501-
clean::TypedefItem(ref t) => item_typedef(fmt, self.item, t),
1499+
clean::TypedefItem(ref t, _) => item_typedef(fmt, self.item, t),
15021500
clean::MacroItem(ref m) => item_macro(fmt, self.item, m),
15031501
clean::PrimitiveItem(ref p) => item_primitive(fmt, self.item, p),
15041502
clean::StaticItem(ref i) | clean::ForeignStaticItem(ref i) =>
@@ -2310,10 +2308,10 @@ fn render_deref_methods(w: &mut fmt::Formatter, impl_: &Impl) -> fmt::Result {
23102308
let deref_type = impl_.impl_.trait_.as_ref().unwrap();
23112309
let target = impl_.impl_.items.iter().filter_map(|item| {
23122310
match item.inner {
2313-
clean::TypedefItem(ref t) => Some(&t.type_),
2311+
clean::TypedefItem(ref t, true) => Some(&t.type_),
23142312
_ => None,
23152313
}
2316-
}).next().unwrap();
2314+
}).next().expect("Expected associated type binding");
23172315
let what = AssocItemRender::DerefFor { trait_: deref_type, type_: target };
23182316
match *target {
23192317
clean::ResolvedPath { did, .. } => render_assoc_items(w, did, what),
@@ -2329,6 +2327,9 @@ fn render_deref_methods(w: &mut fmt::Formatter, impl_: &Impl) -> fmt::Result {
23292327
}
23302328
}
23312329

2330+
// Render_header is false when we are rendering a `Deref` impl and true
2331+
// otherwise. If render_header is false, we will avoid rendering static
2332+
// methods, since they are not accessible for the type implementing `Deref`
23322333
fn render_impl(w: &mut fmt::Formatter, i: &Impl, link: AssocItemLink,
23332334
render_header: bool) -> fmt::Result {
23342335
if render_header {
@@ -2348,16 +2349,19 @@ fn render_impl(w: &mut fmt::Formatter, i: &Impl, link: AssocItemLink,
23482349
}
23492350

23502351
fn doctraititem(w: &mut fmt::Formatter, item: &clean::Item,
2351-
link: AssocItemLink) -> fmt::Result {
2352+
link: AssocItemLink, render_static: bool) -> fmt::Result {
23522353
match item.inner {
23532354
clean::MethodItem(..) | clean::TyMethodItem(..) => {
2354-
try!(write!(w, "<h4 id='method.{}' class='{}'><code>",
2355-
*item.name.as_ref().unwrap(),
2356-
shortty(item)));
2355+
// Only render when the method is not static or we allow static methods
2356+
if !is_static_method(item) || render_static {
2357+
try!(write!(w, "<h4 id='method.{}' class='{}'><code>",
2358+
*item.name.as_ref().unwrap(),
2359+
shortty(item)));
23572360
try!(render_assoc_item(w, item, link));
2358-
try!(write!(w, "</code></h4>\n"));
2361+
try!(write!(w, "</code></h4>\n"));
2362+
}
23592363
}
2360-
clean::TypedefItem(ref tydef) => {
2364+
clean::TypedefItem(ref tydef, _) => {
23612365
let name = item.name.as_ref().unwrap();
23622366
try!(write!(w, "<h4 id='assoc_type.{}' class='{}'><code>",
23632367
*name,
@@ -2389,30 +2393,44 @@ fn render_impl(w: &mut fmt::Formatter, i: &Impl, link: AssocItemLink,
23892393
}
23902394
_ => panic!("can't make docs for trait item with name {:?}", item.name)
23912395
}
2392-
if let AssocItemLink::Anchor = link {
2393-
document(w, item)
2396+
2397+
return if let AssocItemLink::Anchor = link {
2398+
if is_static_method(item) && !render_static {
2399+
Ok(())
2400+
} else {
2401+
document(w, item)
2402+
}
23942403
} else {
23952404
Ok(())
2405+
};
2406+
2407+
fn is_static_method(item: &clean::Item) -> bool {
2408+
match item.inner {
2409+
clean::MethodItem(ref method) => method.self_ == SelfTy::SelfStatic,
2410+
clean::TyMethodItem(ref method) => method.self_ == SelfTy::SelfStatic,
2411+
_ => false
2412+
}
23962413
}
23972414
}
23982415

23992416
try!(write!(w, "<div class='impl-items'>"));
24002417
for trait_item in i.impl_.items.iter() {
2401-
try!(doctraititem(w, trait_item, link));
2418+
try!(doctraititem(w, trait_item, link, render_header));
24022419
}
24032420

24042421
fn render_default_items(w: &mut fmt::Formatter,
24052422
did: ast::DefId,
24062423
t: &clean::Trait,
2407-
i: &clean::Impl) -> fmt::Result {
2424+
i: &clean::Impl,
2425+
render_static: bool) -> fmt::Result {
24082426
for trait_item in &t.items {
24092427
let n = trait_item.name.clone();
24102428
match i.items.iter().find(|m| { m.name == n }) {
24112429
Some(..) => continue,
24122430
None => {}
24132431
}
24142432

2415-
try!(doctraititem(w, trait_item, AssocItemLink::GotoSource(did)));
2433+
try!(doctraititem(w, trait_item, AssocItemLink::GotoSource(did), render_static));
24162434
}
24172435
Ok(())
24182436
}
@@ -2423,7 +2441,8 @@ fn render_impl(w: &mut fmt::Formatter, i: &Impl, link: AssocItemLink,
24232441
// for them work.
24242442
if let Some(clean::ResolvedPath { did, .. }) = i.impl_.trait_ {
24252443
if let Some(t) = cache().traits.get(&did) {
2426-
try!(render_default_items(w, did, t, &i.impl_));
2444+
try!(render_default_items(w, did, t, &i.impl_, render_header));
2445+
24272446
}
24282447
}
24292448
try!(write!(w, "</div>"));
@@ -2432,10 +2451,11 @@ fn render_impl(w: &mut fmt::Formatter, i: &Impl, link: AssocItemLink,
24322451

24332452
fn item_typedef(w: &mut fmt::Formatter, it: &clean::Item,
24342453
t: &clean::Typedef) -> fmt::Result {
2435-
try!(write!(w, "<pre class='rust typedef'>type {}{} = {};</pre>",
2454+
try!(write!(w, "<pre class='rust typedef'>type {}{}{where_clause} = {type_};</pre>",
24362455
it.name.as_ref().unwrap(),
24372456
t.generics,
2438-
t.type_));
2457+
where_clause = WhereClause(&t.generics),
2458+
type_ = t.type_));
24392459

24402460
document(w, it)
24412461
}

branches/auto/src/test/auxiliary/issue-19190-3.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub struct Baz;
2222

2323
impl Baz {
2424
pub fn baz(&self) {}
25+
pub fn static_baz() {}
2526
}
2627

2728
impl Deref for Bar {

0 commit comments

Comments
 (0)