@@ -36,15 +36,11 @@ use crate::formats::item_type::ItemType;
3636/// 
3737/// The returned value is `None` if the definition could not be inlined, 
3838/// and `Some` of a vector of items if it was successfully expanded. 
39- /// 
40- /// `parent_module` refers to the parent of the *re-export*, not the original item. 
4139pub ( crate )  fn  try_inline ( 
4240    cx :  & mut  DocContext < ' _ > , 
43-     parent_module :  DefId , 
44-     import_def_id :  Option < DefId > , 
4541    res :  Res , 
4642    name :  Symbol , 
47-     attrs :  Option < & [ ast:: Attribute ] > , 
43+     attrs :  Option < ( & [ ast:: Attribute ] ,   Option < DefId > ) > , 
4844    visited :  & mut  DefIdSet , 
4945)  -> Option < Vec < clean:: Item > >  { 
5046    let  did = res. opt_def_id ( ) ?; 
@@ -55,38 +51,17 @@ pub(crate) fn try_inline(
5551
5652    debug ! ( "attrs={:?}" ,  attrs) ; 
5753
58-     let  attrs_without_docs = attrs. map ( |attrs| { 
59-         attrs. into_iter ( ) . filter ( |a| a. doc_str ( ) . is_none ( ) ) . cloned ( ) . collect :: < Vec < _ > > ( ) 
54+     let  attrs_without_docs = attrs. map ( |( attrs,  def_id ) | { 
55+         ( attrs. into_iter ( ) . filter ( |a| a. doc_str ( ) . is_none ( ) ) . cloned ( ) . collect :: < Vec < _ > > ( ) ,  def_id ) 
6056    } ) ; 
61-     // We need this ugly code because: 
62-     // 
63-     // ``` 
64-     // attrs_without_docs.map(|a| a.as_slice()) 
65-     // ``` 
66-     // 
67-     // will fail because it returns a temporary slice and: 
68-     // 
69-     // ``` 
70-     // attrs_without_docs.map(|s| { 
71-     //     vec = s.as_slice(); 
72-     //     vec 
73-     // }) 
74-     // ``` 
75-     // 
76-     // will fail because we're moving an uninitialized variable into a closure. 
77-     let  vec; 
78-     let  attrs_without_docs = match  attrs_without_docs { 
79-         Some ( s)  => { 
80-             vec = s; 
81-             Some ( vec. as_slice ( ) ) 
82-         } 
83-         None  => None , 
84-     } ; 
57+     let  attrs_without_docs =
58+         attrs_without_docs. as_ref ( ) . map ( |( attrs,  def_id) | ( & attrs[ ..] ,  * def_id) ) ; 
8559
60+     let  import_def_id = attrs. and_then ( |( _,  def_id) | def_id) ; 
8661    let  kind = match  res { 
8762        Res :: Def ( DefKind :: Trait ,  did)  => { 
8863            record_extern_fqn ( cx,  did,  ItemType :: Trait ) ; 
89-             build_impls ( cx,  Some ( parent_module ) ,   did,  attrs_without_docs,  & mut  ret) ; 
64+             build_impls ( cx,  did,  attrs_without_docs,  & mut  ret) ; 
9065            clean:: TraitItem ( Box :: new ( build_external_trait ( cx,  did) ) ) 
9166        } 
9267        Res :: Def ( DefKind :: Fn ,  did)  => { 
@@ -95,27 +70,27 @@ pub(crate) fn try_inline(
9570        } 
9671        Res :: Def ( DefKind :: Struct ,  did)  => { 
9772            record_extern_fqn ( cx,  did,  ItemType :: Struct ) ; 
98-             build_impls ( cx,  Some ( parent_module ) ,   did,  attrs_without_docs,  & mut  ret) ; 
73+             build_impls ( cx,  did,  attrs_without_docs,  & mut  ret) ; 
9974            clean:: StructItem ( build_struct ( cx,  did) ) 
10075        } 
10176        Res :: Def ( DefKind :: Union ,  did)  => { 
10277            record_extern_fqn ( cx,  did,  ItemType :: Union ) ; 
103-             build_impls ( cx,  Some ( parent_module ) ,   did,  attrs_without_docs,  & mut  ret) ; 
78+             build_impls ( cx,  did,  attrs_without_docs,  & mut  ret) ; 
10479            clean:: UnionItem ( build_union ( cx,  did) ) 
10580        } 
10681        Res :: Def ( DefKind :: TyAlias ,  did)  => { 
10782            record_extern_fqn ( cx,  did,  ItemType :: Typedef ) ; 
108-             build_impls ( cx,  Some ( parent_module ) ,   did,  attrs_without_docs,  & mut  ret) ; 
83+             build_impls ( cx,  did,  attrs_without_docs,  & mut  ret) ; 
10984            clean:: TypedefItem ( build_type_alias ( cx,  did) ) 
11085        } 
11186        Res :: Def ( DefKind :: Enum ,  did)  => { 
11287            record_extern_fqn ( cx,  did,  ItemType :: Enum ) ; 
113-             build_impls ( cx,  Some ( parent_module ) ,   did,  attrs_without_docs,  & mut  ret) ; 
88+             build_impls ( cx,  did,  attrs_without_docs,  & mut  ret) ; 
11489            clean:: EnumItem ( build_enum ( cx,  did) ) 
11590        } 
11691        Res :: Def ( DefKind :: ForeignTy ,  did)  => { 
11792            record_extern_fqn ( cx,  did,  ItemType :: ForeignType ) ; 
118-             build_impls ( cx,  Some ( parent_module ) ,   did,  attrs_without_docs,  & mut  ret) ; 
93+             build_impls ( cx,  did,  attrs_without_docs,  & mut  ret) ; 
11994            clean:: ForeignTypeItem 
12095        } 
12196        // Never inline enum variants but leave them shown as re-exports. 
@@ -149,7 +124,7 @@ pub(crate) fn try_inline(
149124        _ => return  None , 
150125    } ; 
151126
152-     let  ( attrs,  cfg)  = merge_attrs ( cx,  Some ( parent_module ) ,   load_attrs ( cx,  did) ,  attrs) ; 
127+     let  ( attrs,  cfg)  = merge_attrs ( cx,  load_attrs ( cx,  did) ,  attrs) ; 
153128    cx. inlined . insert ( did. into ( ) ) ; 
154129    let  mut  item =
155130        clean:: Item :: from_def_id_and_attrs_and_parts ( did,  Some ( name) ,  kind,  Box :: new ( attrs) ,  cfg) ; 
@@ -316,17 +291,16 @@ fn build_type_alias(cx: &mut DocContext<'_>, did: DefId) -> Box<clean::Typedef>
316291/// Builds all inherent implementations of an ADT (struct/union/enum) or Trait item/path/reexport. 
317292pub ( crate )  fn  build_impls ( 
318293    cx :  & mut  DocContext < ' _ > , 
319-     parent_module :  Option < DefId > , 
320294    did :  DefId , 
321-     attrs :  Option < & [ ast:: Attribute ] > , 
295+     attrs :  Option < ( & [ ast:: Attribute ] ,   Option < DefId > ) > , 
322296    ret :  & mut  Vec < clean:: Item > , 
323297)  { 
324298    let  _prof_timer = cx. tcx . sess . prof . generic_activity ( "build_inherent_impls" ) ; 
325299    let  tcx = cx. tcx ; 
326300
327301    // for each implementation of an item represented by `did`, build the clean::Item for that impl 
328302    for  & did in  tcx. inherent_impls ( did) . iter ( )  { 
329-         build_impl ( cx,  parent_module ,   did,  attrs,  ret) ; 
303+         build_impl ( cx,  did,  attrs,  ret) ; 
330304    } 
331305
332306    // This pretty much exists expressly for `dyn Error` traits that exist in the `alloc` crate. 
@@ -340,28 +314,26 @@ pub(crate) fn build_impls(
340314        let  type_ =
341315            if  tcx. is_trait ( did)  {  TraitSimplifiedType ( did)  }  else  {  AdtSimplifiedType ( did)  } ; 
342316        for  & did in  tcx. incoherent_impls ( type_)  { 
343-             build_impl ( cx,  parent_module ,   did,  attrs,  ret) ; 
317+             build_impl ( cx,  did,  attrs,  ret) ; 
344318        } 
345319    } 
346320} 
347321
348- /// `parent_module` refers to the parent of the re-export, not the original item 
349322pub ( crate )  fn  merge_attrs ( 
350323    cx :  & mut  DocContext < ' _ > , 
351-     parent_module :  Option < DefId > , 
352324    old_attrs :  & [ ast:: Attribute ] , 
353-     new_attrs :  Option < & [ ast:: Attribute ] > , 
325+     new_attrs :  Option < ( & [ ast:: Attribute ] ,   Option < DefId > ) > , 
354326)  -> ( clean:: Attributes ,  Option < Arc < clean:: cfg:: Cfg > > )  { 
355327    // NOTE: If we have additional attributes (from a re-export), 
356328    // always insert them first. This ensure that re-export 
357329    // doc comments show up before the original doc comments 
358330    // when we render them. 
359-     if  let  Some ( inner)  = new_attrs { 
331+     if  let  Some ( ( inner,  item_id ) )  = new_attrs { 
360332        let  mut  both = inner. to_vec ( ) ; 
361333        both. extend_from_slice ( old_attrs) ; 
362334        ( 
363-             if  let  Some ( new_id )  = parent_module  { 
364-                 Attributes :: from_ast_with_additional ( old_attrs,  ( inner,  new_id ) ) 
335+             if  let  Some ( item_id )  = item_id  { 
336+                 Attributes :: from_ast_with_additional ( old_attrs,  ( inner,  item_id ) ) 
365337            }  else  { 
366338                Attributes :: from_ast ( & both) 
367339            } , 
@@ -375,9 +347,8 @@ pub(crate) fn merge_attrs(
375347/// Inline an `impl`, inherent or of a trait. The `did` must be for an `impl`. 
376348pub ( crate )  fn  build_impl ( 
377349    cx :  & mut  DocContext < ' _ > , 
378-     parent_module :  Option < DefId > , 
379350    did :  DefId , 
380-     attrs :  Option < & [ ast:: Attribute ] > , 
351+     attrs :  Option < ( & [ ast:: Attribute ] ,   Option < DefId > ) > , 
381352    ret :  & mut  Vec < clean:: Item > , 
382353)  { 
383354    if  !cx. inlined . insert ( did. into ( ) )  { 
@@ -539,7 +510,7 @@ pub(crate) fn build_impl(
539510        record_extern_trait ( cx,  did) ; 
540511    } 
541512
542-     let  ( merged_attrs,  cfg)  = merge_attrs ( cx,  parent_module ,   load_attrs ( cx,  did) ,  attrs) ; 
513+     let  ( merged_attrs,  cfg)  = merge_attrs ( cx,  load_attrs ( cx,  did) ,  attrs) ; 
543514    trace ! ( "merged_attrs={:?}" ,  merged_attrs) ; 
544515
545516    trace ! ( 
@@ -635,7 +606,7 @@ fn build_module_items(
635606                    cfg :  None , 
636607                    inline_stmt_id :  None , 
637608                } ) ; 
638-             }  else  if  let  Some ( i)  = try_inline ( cx,  did ,   None ,   res,  item. ident . name ,  None ,  visited)  { 
609+             }  else  if  let  Some ( i)  = try_inline ( cx,  res,  item. ident . name ,  None ,  visited)  { 
639610                items. extend ( i) 
640611            } 
641612        } 
0 commit comments