@@ -19,9 +19,10 @@ pub(crate) const COLLECT_TRAIT_IMPLS: Pass = Pass {
1919} ;
2020
2121pub ( crate ) fn collect_trait_impls ( mut krate : Crate , cx : & mut DocContext < ' _ > ) -> Crate {
22+ let tcx = cx. tcx ;
2223 // We need to check if there are errors before running this pass because it would crash when
2324 // we try to get auto and blanket implementations.
24- if cx . tcx . sess . diagnostic ( ) . has_errors_or_lint_errors ( ) . is_some ( ) {
25+ if tcx. sess . diagnostic ( ) . has_errors_or_lint_errors ( ) . is_some ( ) {
2526 return krate;
2627 }
2728
@@ -32,8 +33,7 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
3233 } ) ;
3334
3435 let local_crate = ExternalCrate { crate_num : LOCAL_CRATE } ;
35- let prims: FxHashSet < PrimitiveType > =
36- local_crate. primitives ( cx. tcx ) . iter ( ) . map ( |p| p. 1 ) . collect ( ) ;
36+ let prims: FxHashSet < PrimitiveType > = local_crate. primitives ( tcx) . iter ( ) . map ( |p| p. 1 ) . collect ( ) ;
3737
3838 let crate_items = {
3939 let mut coll = ItemCollector :: new ( ) ;
@@ -46,24 +46,23 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
4646
4747 // External trait impls.
4848 {
49- let _prof_timer = cx . tcx . sess . prof . generic_activity ( "build_extern_trait_impls" ) ;
50- for & cnum in cx . tcx . crates ( ( ) ) {
51- for & impl_def_id in cx . tcx . trait_impls_in_crate ( cnum) {
49+ let _prof_timer = tcx. sess . prof . generic_activity ( "build_extern_trait_impls" ) ;
50+ for & cnum in tcx. crates ( ( ) ) {
51+ for & impl_def_id in tcx. trait_impls_in_crate ( cnum) {
5252 inline:: build_impl ( cx, impl_def_id, None , & mut new_items_external) ;
5353 }
5454 }
5555 }
5656
5757 // Local trait impls.
5858 {
59- let _prof_timer = cx . tcx . sess . prof . generic_activity ( "build_local_trait_impls" ) ;
59+ let _prof_timer = tcx. sess . prof . generic_activity ( "build_local_trait_impls" ) ;
6060 let mut attr_buf = Vec :: new ( ) ;
61- for & impl_def_id in cx . tcx . trait_impls_in_crate ( LOCAL_CRATE ) {
62- let mut parent = Some ( cx . tcx . parent ( impl_def_id) ) ;
61+ for & impl_def_id in tcx. trait_impls_in_crate ( LOCAL_CRATE ) {
62+ let mut parent = Some ( tcx. parent ( impl_def_id) ) ;
6363 while let Some ( did) = parent {
6464 attr_buf. extend (
65- cx. tcx
66- . get_attrs ( did, sym:: doc)
65+ tcx. get_attrs ( did, sym:: doc)
6766 . filter ( |attr| {
6867 if let Some ( [ attr] ) = attr. meta_item_list ( ) . as_deref ( ) {
6968 attr. has_name ( sym:: cfg)
@@ -73,25 +72,24 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
7372 } )
7473 . cloned ( ) ,
7574 ) ;
76- parent = cx . tcx . opt_parent ( did) ;
75+ parent = tcx. opt_parent ( did) ;
7776 }
7877 inline:: build_impl ( cx, impl_def_id, Some ( ( & attr_buf, None ) ) , & mut new_items_local) ;
7978 attr_buf. clear ( ) ;
8079 }
8180 }
8281
83- cx . tcx . sess . prof . generic_activity ( "build_primitive_trait_impls" ) . run ( || {
84- for def_id in PrimitiveType :: all_impls ( cx . tcx ) {
82+ tcx. sess . prof . generic_activity ( "build_primitive_trait_impls" ) . run ( || {
83+ for def_id in PrimitiveType :: all_impls ( tcx) {
8584 // Try to inline primitive impls from other crates.
8685 if !def_id. is_local ( ) {
8786 inline:: build_impl ( cx, def_id, None , & mut new_items_external) ;
8887 }
8988 }
90- for ( prim, did) in PrimitiveType :: primitive_locations ( cx . tcx ) {
89+ for ( prim, did) in PrimitiveType :: primitive_locations ( tcx) {
9190 // Do not calculate blanket impl list for docs that are not going to be rendered.
9291 // While the `impl` blocks themselves are only in `libcore`, the module with `doc`
9392 // attached is directly included in `libstd` as well.
94- let tcx = cx. tcx ;
9593 if did. is_local ( ) {
9694 for def_id in prim. impls ( tcx) . filter ( |def_id| {
9795 // Avoid including impl blocks with filled-in generics.
@@ -157,7 +155,7 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
157155 // scan through included items ahead of time to splice in Deref targets to the "valid" sets
158156 for it in new_items_external. iter ( ) . chain ( new_items_local. iter ( ) ) {
159157 if let ImplItem ( box Impl { ref for_, ref trait_, ref items, .. } ) = * it. kind &&
160- trait_. as_ref ( ) . map ( |t| t. def_id ( ) ) == cx . tcx . lang_items ( ) . deref_trait ( ) &&
158+ trait_. as_ref ( ) . map ( |t| t. def_id ( ) ) == tcx. lang_items ( ) . deref_trait ( ) &&
161159 cleaner. keep_impl ( for_, true )
162160 {
163161 let target = items
@@ -199,7 +197,7 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
199197 if let ImplItem ( box Impl { ref for_, ref trait_, ref kind, .. } ) = * it. kind {
200198 cleaner. keep_impl (
201199 for_,
202- trait_. as_ref ( ) . map ( |t| t. def_id ( ) ) == cx . tcx . lang_items ( ) . deref_trait ( ) ,
200+ trait_. as_ref ( ) . map ( |t| t. def_id ( ) ) == tcx. lang_items ( ) . deref_trait ( ) ,
203201 ) || trait_. as_ref ( ) . map_or ( false , |t| cleaner. keep_impl_with_def_id ( t. def_id ( ) . into ( ) ) )
204202 || kind. is_blanket ( )
205203 } else {
0 commit comments