@@ -19,9 +19,10 @@ pub(crate) const COLLECT_TRAIT_IMPLS: Pass = Pass {
19
19
} ;
20
20
21
21
pub ( crate ) fn collect_trait_impls ( mut krate : Crate , cx : & mut DocContext < ' _ > ) -> Crate {
22
+ let tcx = cx. tcx ;
22
23
// We need to check if there are errors before running this pass because it would crash when
23
24
// 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 ( ) {
25
26
return krate;
26
27
}
27
28
@@ -32,8 +33,7 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
32
33
} ) ;
33
34
34
35
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 ( ) ;
37
37
38
38
let crate_items = {
39
39
let mut coll = ItemCollector :: new ( ) ;
@@ -46,24 +46,23 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
46
46
47
47
// External trait impls.
48
48
{
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) {
52
52
inline:: build_impl ( cx, impl_def_id, None , & mut new_items_external) ;
53
53
}
54
54
}
55
55
}
56
56
57
57
// Local trait impls.
58
58
{
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" ) ;
60
60
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) ) ;
63
63
while let Some ( did) = parent {
64
64
attr_buf. extend (
65
- cx. tcx
66
- . get_attrs ( did, sym:: doc)
65
+ tcx. get_attrs ( did, sym:: doc)
67
66
. filter ( |attr| {
68
67
if let Some ( [ attr] ) = attr. meta_item_list ( ) . as_deref ( ) {
69
68
attr. has_name ( sym:: cfg)
@@ -73,25 +72,24 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
73
72
} )
74
73
. cloned ( ) ,
75
74
) ;
76
- parent = cx . tcx . opt_parent ( did) ;
75
+ parent = tcx. opt_parent ( did) ;
77
76
}
78
77
inline:: build_impl ( cx, impl_def_id, Some ( ( & attr_buf, None ) ) , & mut new_items_local) ;
79
78
attr_buf. clear ( ) ;
80
79
}
81
80
}
82
81
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) {
85
84
// Try to inline primitive impls from other crates.
86
85
if !def_id. is_local ( ) {
87
86
inline:: build_impl ( cx, def_id, None , & mut new_items_external) ;
88
87
}
89
88
}
90
- for ( prim, did) in PrimitiveType :: primitive_locations ( cx . tcx ) {
89
+ for ( prim, did) in PrimitiveType :: primitive_locations ( tcx) {
91
90
// Do not calculate blanket impl list for docs that are not going to be rendered.
92
91
// While the `impl` blocks themselves are only in `libcore`, the module with `doc`
93
92
// attached is directly included in `libstd` as well.
94
- let tcx = cx. tcx ;
95
93
if did. is_local ( ) {
96
94
for def_id in prim. impls ( tcx) . filter ( |def_id| {
97
95
// Avoid including impl blocks with filled-in generics.
@@ -157,7 +155,7 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
157
155
// scan through included items ahead of time to splice in Deref targets to the "valid" sets
158
156
for it in new_items_external. iter ( ) . chain ( new_items_local. iter ( ) ) {
159
157
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 ( ) &&
161
159
cleaner. keep_impl ( for_, true )
162
160
{
163
161
let target = items
@@ -199,7 +197,7 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
199
197
if let ImplItem ( box Impl { ref for_, ref trait_, ref kind, .. } ) = * it. kind {
200
198
cleaner. keep_impl (
201
199
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 ( ) ,
203
201
) || trait_. as_ref ( ) . map_or ( false , |t| cleaner. keep_impl_with_def_id ( t. def_id ( ) . into ( ) ) )
204
202
|| kind. is_blanket ( )
205
203
} else {
0 commit comments