@@ -28,14 +28,21 @@ pub fn provide(providers: &mut Providers) {
28
28
/// Determine which generic parameters are used by the function/method/closure represented by
29
29
/// `def_id`. Returns a bitset where bits representing unused parameters are set (`is_empty`
30
30
/// indicates all parameters are used).
31
- fn unused_generic_params ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> FiniteBitSet < u64 > {
31
+ fn unused_generic_params ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> FiniteBitSet < u32 > {
32
32
debug ! ( "unused_generic_params({:?})" , def_id) ;
33
33
34
34
if !tcx. sess . opts . debugging_opts . polymorphize {
35
35
// If polymorphization disabled, then all parameters are used.
36
36
return FiniteBitSet :: new_empty ( ) ;
37
37
}
38
38
39
+ // Polymorphization results are stored in cross-crate metadata only when there are unused
40
+ // parameters, so assume that non-local items must have only used parameters (else this query
41
+ // would not be invoked, and the cross-crate metadata used instead).
42
+ if !def_id. is_local ( ) {
43
+ return FiniteBitSet :: new_empty ( ) ;
44
+ }
45
+
39
46
let generics = tcx. generics_of ( def_id) ;
40
47
debug ! ( "unused_generic_params: generics={:?}" , generics) ;
41
48
@@ -53,7 +60,7 @@ fn unused_generic_params(tcx: TyCtxt<'_>, def_id: DefId) -> FiniteBitSet<u64> {
53
60
// Create a bitset with N rightmost ones for each parameter.
54
61
let generics_count: u32 =
55
62
generics. count ( ) . try_into ( ) . expect ( "more generic parameters than can fit into a `u32`" ) ;
56
- let mut unused_parameters = FiniteBitSet :: < u64 > :: new_empty ( ) ;
63
+ let mut unused_parameters = FiniteBitSet :: < u32 > :: new_empty ( ) ;
57
64
unused_parameters. set_range ( 0 ..generics_count) ;
58
65
debug ! ( "unused_generic_params: (start) unused_parameters={:?}" , unused_parameters) ;
59
66
mark_used_by_default_parameters ( tcx, def_id, generics, & mut unused_parameters) ;
@@ -84,7 +91,7 @@ fn mark_used_by_default_parameters<'tcx>(
84
91
tcx : TyCtxt < ' tcx > ,
85
92
def_id : DefId ,
86
93
generics : & ' tcx ty:: Generics ,
87
- unused_parameters : & mut FiniteBitSet < u64 > ,
94
+ unused_parameters : & mut FiniteBitSet < u32 > ,
88
95
) {
89
96
if !tcx. is_trait ( def_id) && ( tcx. is_closure ( def_id) || tcx. type_of ( def_id) . is_generator ( ) ) {
90
97
for param in & generics. params {
@@ -110,11 +117,11 @@ fn mark_used_by_default_parameters<'tcx>(
110
117
fn mark_used_by_predicates < ' tcx > (
111
118
tcx : TyCtxt < ' tcx > ,
112
119
def_id : DefId ,
113
- unused_parameters : & mut FiniteBitSet < u64 > ,
120
+ unused_parameters : & mut FiniteBitSet < u32 > ,
114
121
) {
115
122
let def_id = tcx. closure_base_def_id ( def_id) ;
116
123
117
- let is_self_ty_used = |unused_parameters : & mut FiniteBitSet < u64 > , self_ty : Ty < ' tcx > | {
124
+ let is_self_ty_used = |unused_parameters : & mut FiniteBitSet < u32 > , self_ty : Ty < ' tcx > | {
118
125
debug ! ( "unused_generic_params: self_ty={:?}" , self_ty) ;
119
126
if let ty:: Param ( param) = self_ty. kind {
120
127
!unused_parameters. contains ( param. index ) . unwrap_or ( false )
@@ -123,7 +130,7 @@ fn mark_used_by_predicates<'tcx>(
123
130
}
124
131
} ;
125
132
126
- let mark_ty = |unused_parameters : & mut FiniteBitSet < u64 > , ty : Ty < ' tcx > | {
133
+ let mark_ty = |unused_parameters : & mut FiniteBitSet < u32 > , ty : Ty < ' tcx > | {
127
134
let mut vis = UsedGenericParametersVisitor { tcx, def_id, unused_parameters } ;
128
135
ty. visit_with ( & mut vis) ;
129
136
} ;
@@ -159,7 +166,7 @@ fn emit_unused_generic_params_error<'tcx>(
159
166
tcx : TyCtxt < ' tcx > ,
160
167
def_id : DefId ,
161
168
generics : & ' tcx ty:: Generics ,
162
- unused_parameters : & FiniteBitSet < u64 > ,
169
+ unused_parameters : & FiniteBitSet < u32 > ,
163
170
) {
164
171
debug ! ( "emit_unused_generic_params_error: def_id={:?}" , def_id) ;
165
172
let base_def_id = tcx. closure_base_def_id ( def_id) ;
@@ -195,7 +202,7 @@ fn emit_unused_generic_params_error<'tcx>(
195
202
struct UsedGenericParametersVisitor < ' a , ' tcx > {
196
203
tcx : TyCtxt < ' tcx > ,
197
204
def_id : DefId ,
198
- unused_parameters : & ' a mut FiniteBitSet < u64 > ,
205
+ unused_parameters : & ' a mut FiniteBitSet < u32 > ,
199
206
}
200
207
201
208
impl < ' a , ' tcx > Visitor < ' tcx > for UsedGenericParametersVisitor < ' a , ' tcx > {
0 commit comments