@@ -44,7 +44,7 @@ use rustc::middle::stability;
44
44
45
45
use rustc_front:: hir;
46
46
47
- use std:: collections:: HashMap ;
47
+ use std:: collections:: { HashMap , HashSet } ;
48
48
use std:: path:: PathBuf ;
49
49
use std:: rc:: Rc ;
50
50
use std:: u32;
@@ -559,15 +559,9 @@ impl TyParamBound {
559
559
fn is_sized_bound ( & self , cx : & DocContext ) -> bool {
560
560
use rustc_front:: hir:: TraitBoundModifier as TBM ;
561
561
if let Some ( tcx) = cx. tcx_opt ( ) {
562
- let sized_did = match tcx. lang_items . sized_trait ( ) {
563
- Some ( did) => did,
564
- None => return false
565
- } ;
566
- if let TyParamBound :: TraitBound ( PolyTrait {
567
- trait_ : Type :: ResolvedPath { did, .. } , ..
568
- } , TBM :: None ) = * self {
569
- if did == sized_did {
570
- return true
562
+ if let TyParamBound :: TraitBound ( PolyTrait { ref trait_, .. } , TBM :: None ) = * self {
563
+ if trait_. def_id ( ) == tcx. lang_items . sized_trait ( ) {
564
+ return true ;
571
565
}
572
566
}
573
567
}
@@ -724,15 +718,18 @@ impl<'tcx> Clean<TyParamBound> for ty::TraitRef<'tcx> {
724
718
}
725
719
}
726
720
727
- TraitBound ( PolyTrait {
728
- trait_ : ResolvedPath {
729
- path : path,
730
- typarams : None ,
731
- did : self . def_id ,
732
- is_generic : false ,
721
+ TraitBound (
722
+ PolyTrait {
723
+ trait_ : ResolvedPath {
724
+ path : path,
725
+ typarams : None ,
726
+ did : self . def_id ,
727
+ is_generic : false ,
728
+ } ,
729
+ lifetimes : late_bounds,
733
730
} ,
734
- lifetimes : late_bounds
735
- } , hir :: TraitBoundModifier :: None )
731
+ hir :: TraitBoundModifier :: None
732
+ )
736
733
}
737
734
}
738
735
@@ -932,7 +929,6 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics<'tcx>,
932
929
& ' a ty:: GenericPredicates < ' tcx > ,
933
930
subst:: ParamSpace ) {
934
931
fn clean ( & self , cx : & DocContext ) -> Generics {
935
- use std:: collections:: HashSet ;
936
932
use self :: WherePredicate as WP ;
937
933
938
934
let ( gens, preds, space) = * self ;
@@ -1486,6 +1482,16 @@ pub enum TypeKind {
1486
1482
TypeTypedef ,
1487
1483
}
1488
1484
1485
+ pub trait GetDefId {
1486
+ fn def_id ( & self ) -> Option < DefId > ;
1487
+ }
1488
+
1489
+ impl < T : GetDefId > GetDefId for Option < T > {
1490
+ fn def_id ( & self ) -> Option < DefId > {
1491
+ self . as_ref ( ) . and_then ( |d| d. def_id ( ) )
1492
+ }
1493
+ }
1494
+
1489
1495
impl Type {
1490
1496
pub fn primitive_type ( & self ) -> Option < PrimitiveType > {
1491
1497
match * self {
@@ -1499,7 +1505,9 @@ impl Type {
1499
1505
_ => None ,
1500
1506
}
1501
1507
}
1508
+ }
1502
1509
1510
+ impl GetDefId for Type {
1503
1511
fn def_id ( & self ) -> Option < DefId > {
1504
1512
match * self {
1505
1513
ResolvedPath { did, .. } => Some ( did) ,
@@ -1884,18 +1892,11 @@ impl<'tcx> Clean<Item> for ty::VariantDefData<'tcx, 'static> {
1884
1892
Item {
1885
1893
source : Span :: empty ( ) ,
1886
1894
name : Some ( field. name . clean ( cx) ) ,
1887
- attrs : Vec :: new ( ) ,
1895
+ attrs : cx . tcx ( ) . get_attrs ( field . did ) . clean ( cx ) ,
1888
1896
visibility : Some ( field. vis ) ,
1889
- // FIXME: this is not accurate, we need an id for
1890
- // the specific field but we're using the id
1891
- // for the whole variant. Thus we read the
1892
- // stability from the whole variant as well.
1893
- // Struct variants are experimental and need
1894
- // more infrastructure work before we can get
1895
- // at the needed information here.
1896
- def_id : self . did ,
1897
- stability : get_stability ( cx, self . did ) ,
1898
- deprecation : get_deprecation ( cx, self . did ) ,
1897
+ def_id : field. did ,
1898
+ stability : get_stability ( cx, field. did ) ,
1899
+ deprecation : get_deprecation ( cx, field. did ) ,
1899
1900
inner : StructFieldItem (
1900
1901
TypedStructField ( field. unsubst_ty ( ) . clean ( cx) )
1901
1902
)
@@ -1908,7 +1909,7 @@ impl<'tcx> Clean<Item> for ty::VariantDefData<'tcx, 'static> {
1908
1909
name : Some ( self . name . clean ( cx) ) ,
1909
1910
attrs : inline:: load_attrs ( cx, cx. tcx ( ) , self . did ) ,
1910
1911
source : Span :: empty ( ) ,
1911
- visibility : Some ( hir:: Public ) ,
1912
+ visibility : Some ( hir:: Inherited ) ,
1912
1913
def_id : self . did ,
1913
1914
inner : VariantItem ( Variant { kind : kind } ) ,
1914
1915
stability : get_stability ( cx, self . did ) ,
@@ -2208,6 +2209,7 @@ impl Clean<ImplPolarity> for hir::ImplPolarity {
2208
2209
pub struct Impl {
2209
2210
pub unsafety : hir:: Unsafety ,
2210
2211
pub generics : Generics ,
2212
+ pub provided_trait_methods : HashSet < String > ,
2211
2213
pub trait_ : Option < Type > ,
2212
2214
pub for_ : Type ,
2213
2215
pub items : Vec < Item > ,
@@ -2227,12 +2229,19 @@ impl Clean<Vec<Item>> for doctree::Impl {
2227
2229
2228
2230
// If this impl block is an implementation of the Deref trait, then we
2229
2231
// need to try inlining the target's inherent impl blocks as well.
2230
- if let Some ( ResolvedPath { did, .. } ) = trait_ {
2231
- if Some ( did) == cx. deref_trait_did . get ( ) {
2232
- build_deref_target_impls ( cx, & items, & mut ret) ;
2233
- }
2232
+ if trait_. def_id ( ) == cx. deref_trait_did . get ( ) {
2233
+ build_deref_target_impls ( cx, & items, & mut ret) ;
2234
2234
}
2235
2235
2236
+ let provided = trait_. def_id ( ) . and_then ( |did| {
2237
+ cx. tcx_opt ( ) . map ( |tcx| {
2238
+ tcx. provided_trait_methods ( did)
2239
+ . into_iter ( )
2240
+ . map ( |meth| meth. name . to_string ( ) )
2241
+ . collect ( )
2242
+ } )
2243
+ } ) . unwrap_or ( HashSet :: new ( ) ) ;
2244
+
2236
2245
ret. push ( Item {
2237
2246
name : None ,
2238
2247
attrs : self . attrs . clean ( cx) ,
@@ -2244,6 +2253,7 @@ impl Clean<Vec<Item>> for doctree::Impl {
2244
2253
inner : ImplItem ( Impl {
2245
2254
unsafety : self . unsafety ,
2246
2255
generics : self . generics . clean ( cx) ,
2256
+ provided_trait_methods : provided,
2247
2257
trait_ : trait_,
2248
2258
for_ : self . for_ . clean ( cx) ,
2249
2259
items : items,
0 commit comments