@@ -163,25 +163,56 @@ impl<'a> DeclValidator<'a> {
163
163
|| allows. contains ( allow:: NONSTANDARD_STYLE )
164
164
} )
165
165
} ;
166
+ let db = self . db . upcast ( ) ;
167
+ let file_id_is_derive = || {
168
+ match id {
169
+ AttrDefId :: ModuleId ( m) => {
170
+ m. def_map ( db) [ m. local_id ] . origin . file_id ( ) . map ( Into :: into)
171
+ }
172
+ AttrDefId :: FunctionId ( f) => Some ( f. lookup ( db) . id . file_id ( ) ) ,
173
+ AttrDefId :: StaticId ( sid) => Some ( sid. lookup ( db) . id . file_id ( ) ) ,
174
+ AttrDefId :: ConstId ( cid) => Some ( cid. lookup ( db) . id . file_id ( ) ) ,
175
+ AttrDefId :: TraitId ( tid) => Some ( tid. lookup ( db) . id . file_id ( ) ) ,
176
+ AttrDefId :: TraitAliasId ( taid) => Some ( taid. lookup ( db) . id . file_id ( ) ) ,
177
+ AttrDefId :: ImplId ( iid) => Some ( iid. lookup ( db) . id . file_id ( ) ) ,
178
+ AttrDefId :: ExternBlockId ( id) => Some ( id. lookup ( db) . id . file_id ( ) ) ,
179
+ AttrDefId :: ExternCrateId ( id) => Some ( id. lookup ( db) . id . file_id ( ) ) ,
180
+ AttrDefId :: UseId ( id) => Some ( id. lookup ( db) . id . file_id ( ) ) ,
181
+ // These warnings should not explore macro definitions at all
182
+ AttrDefId :: MacroId ( _) => None ,
183
+ AttrDefId :: AdtId ( aid) => match aid {
184
+ AdtId :: StructId ( sid) => Some ( sid. lookup ( db) . id . file_id ( ) ) ,
185
+ AdtId :: EnumId ( eid) => Some ( eid. lookup ( db) . id . file_id ( ) ) ,
186
+ // Unions aren't yet supported
187
+ AdtId :: UnionId ( _) => None ,
188
+ } ,
189
+ AttrDefId :: FieldId ( _) => None ,
190
+ AttrDefId :: EnumVariantId ( _) => None ,
191
+ AttrDefId :: TypeAliasId ( _) => None ,
192
+ AttrDefId :: GenericParamId ( _) => None ,
193
+ }
194
+ . map_or ( false , |file_id| {
195
+ file_id. is_custom_derive ( db. upcast ( ) ) || file_id. is_builtin_derive ( db. upcast ( ) )
196
+ } )
197
+ } ;
166
198
167
- is_allowed ( id)
168
- // go upwards one step or give up
169
- || match id {
170
- AttrDefId :: ModuleId ( m) => m. containing_module ( self . db . upcast ( ) ) . map ( |v| v. into ( ) ) ,
171
- AttrDefId :: FunctionId ( f) => Some ( f. lookup ( self . db . upcast ( ) ) . container . into ( ) ) ,
172
- AttrDefId :: StaticId ( sid) => Some ( sid. lookup ( self . db . upcast ( ) ) . container . into ( ) ) ,
173
- AttrDefId :: ConstId ( cid) => Some ( cid. lookup ( self . db . upcast ( ) ) . container . into ( ) ) ,
174
- AttrDefId :: TraitId ( tid) => Some ( tid. lookup ( self . db . upcast ( ) ) . container . into ( ) ) ,
175
- AttrDefId :: TraitAliasId ( taid) => Some ( taid. lookup ( self . db . upcast ( ) ) . container . into ( ) ) ,
176
- AttrDefId :: ImplId ( iid) => Some ( iid. lookup ( self . db . upcast ( ) ) . container . into ( ) ) ,
177
- AttrDefId :: ExternBlockId ( id) => Some ( id. lookup ( self . db . upcast ( ) ) . container . into ( ) ) ,
178
- AttrDefId :: ExternCrateId ( id) => Some ( id. lookup ( self . db . upcast ( ) ) . container . into ( ) ) ,
179
- AttrDefId :: UseId ( id) => Some ( id. lookup ( self . db . upcast ( ) ) . container . into ( ) ) ,
199
+ let parent = || {
200
+ match id {
201
+ AttrDefId :: ModuleId ( m) => m. containing_module ( db) . map ( |v| v. into ( ) ) ,
202
+ AttrDefId :: FunctionId ( f) => Some ( f. lookup ( db) . container . into ( ) ) ,
203
+ AttrDefId :: StaticId ( sid) => Some ( sid. lookup ( db) . container . into ( ) ) ,
204
+ AttrDefId :: ConstId ( cid) => Some ( cid. lookup ( db) . container . into ( ) ) ,
205
+ AttrDefId :: TraitId ( tid) => Some ( tid. lookup ( db) . container . into ( ) ) ,
206
+ AttrDefId :: TraitAliasId ( taid) => Some ( taid. lookup ( db) . container . into ( ) ) ,
207
+ AttrDefId :: ImplId ( iid) => Some ( iid. lookup ( db) . container . into ( ) ) ,
208
+ AttrDefId :: ExternBlockId ( id) => Some ( id. lookup ( db) . container . into ( ) ) ,
209
+ AttrDefId :: ExternCrateId ( id) => Some ( id. lookup ( db) . container . into ( ) ) ,
210
+ AttrDefId :: UseId ( id) => Some ( id. lookup ( db) . container . into ( ) ) ,
180
211
// These warnings should not explore macro definitions at all
181
212
AttrDefId :: MacroId ( _) => None ,
182
213
AttrDefId :: AdtId ( aid) => match aid {
183
- AdtId :: StructId ( sid) => Some ( sid. lookup ( self . db . upcast ( ) ) . container . into ( ) ) ,
184
- AdtId :: EnumId ( eid) => Some ( eid. lookup ( self . db . upcast ( ) ) . container . into ( ) ) ,
214
+ AdtId :: StructId ( sid) => Some ( sid. lookup ( db ) . container . into ( ) ) ,
215
+ AdtId :: EnumId ( eid) => Some ( eid. lookup ( db ) . container . into ( ) ) ,
185
216
// Unions aren't yet supported
186
217
AdtId :: UnionId ( _) => None ,
187
218
} ,
@@ -191,6 +222,12 @@ impl<'a> DeclValidator<'a> {
191
222
AttrDefId :: GenericParamId ( _) => None ,
192
223
}
193
224
. is_some_and ( |mid| self . allowed ( mid, allow_name, true ) )
225
+ } ;
226
+ is_allowed ( id)
227
+ // FIXME: this is a hack to avoid false positives in derive macros currently
228
+ || file_id_is_derive ( )
229
+ // go upwards one step or give up
230
+ || parent ( )
194
231
}
195
232
196
233
fn validate_func ( & mut self , func : FunctionId ) {
0 commit comments