@@ -9,11 +9,10 @@ use hir::def_id::{LocalDefIdMap, LocalDefIdSet};
9
9
use hir:: ItemKind ;
10
10
use rustc_data_structures:: unord:: UnordSet ;
11
11
use rustc_errors:: MultiSpan ;
12
- use rustc_hir as hir;
13
12
use rustc_hir:: def:: { CtorOf , DefKind , Res } ;
14
13
use rustc_hir:: def_id:: { DefId , LocalDefId , LocalModDefId } ;
15
14
use rustc_hir:: intravisit:: { self , Visitor } ;
16
- use rustc_hir:: { Node , PatKind , TyKind } ;
15
+ use rustc_hir:: { self as hir , Node , PatKind , TyKind } ;
17
16
use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
18
17
use rustc_middle:: middle:: privacy:: Level ;
19
18
use rustc_middle:: query:: Providers ;
@@ -231,7 +230,10 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
231
230
pats : & [ hir:: PatField < ' _ > ] ,
232
231
) {
233
232
let variant = match self . typeck_results ( ) . node_type ( lhs. hir_id ) . kind ( ) {
234
- ty:: Adt ( adt, _) => adt. variant_of_res ( res) ,
233
+ ty:: Adt ( adt, _) => {
234
+ self . check_def_id ( adt. did ( ) ) ;
235
+ adt. variant_of_res ( res)
236
+ }
235
237
_ => span_bug ! ( lhs. span, "non-ADT in struct pattern" ) ,
236
238
} ;
237
239
for pat in pats {
@@ -251,7 +253,10 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
251
253
dotdot : hir:: DotDotPos ,
252
254
) {
253
255
let variant = match self . typeck_results ( ) . node_type ( lhs. hir_id ) . kind ( ) {
254
- ty:: Adt ( adt, _) => adt. variant_of_res ( res) ,
256
+ ty:: Adt ( adt, _) => {
257
+ self . check_def_id ( adt. did ( ) ) ;
258
+ adt. variant_of_res ( res)
259
+ }
255
260
_ => {
256
261
self . tcx . dcx ( ) . span_delayed_bug ( lhs. span , "non-ADT in tuple struct pattern" ) ;
257
262
return ;
@@ -356,31 +361,6 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
356
361
return false ;
357
362
}
358
363
359
- // don't ignore impls for Enums and pub Structs whose methods don't have self receiver,
360
- // cause external crate may call such methods to construct values of these types
361
- if let Some ( local_impl_of) = impl_of. as_local ( )
362
- && let Some ( local_def_id) = def_id. as_local ( )
363
- && let Some ( fn_sig) =
364
- self . tcx . hir ( ) . fn_sig_by_hir_id ( self . tcx . local_def_id_to_hir_id ( local_def_id) )
365
- && matches ! ( fn_sig. decl. implicit_self, hir:: ImplicitSelfKind :: None )
366
- && let TyKind :: Path ( hir:: QPath :: Resolved ( _, path) ) =
367
- self . tcx . hir ( ) . expect_item ( local_impl_of) . expect_impl ( ) . self_ty . kind
368
- && let Res :: Def ( def_kind, did) = path. res
369
- {
370
- match def_kind {
371
- // for example, #[derive(Default)] pub struct T(i32);
372
- // external crate can call T::default() to construct T,
373
- // so that don't ignore impl Default for pub Enum and Structs
374
- DefKind :: Struct | DefKind :: Union if self . tcx . visibility ( did) . is_public ( ) => {
375
- return false ;
376
- }
377
- // don't ignore impl Default for Enums,
378
- // cause we don't know which variant is constructed
379
- DefKind :: Enum => return false ,
380
- _ => ( ) ,
381
- } ;
382
- }
383
-
384
364
if let Some ( trait_of) = self . tcx . trait_id_of_impl ( impl_of)
385
365
&& self . tcx . has_attr ( trait_of, sym:: rustc_trivial_field_reads)
386
366
{
0 commit comments