@@ -14,7 +14,7 @@ use rustc_errors::MultiSpan;
14
14
use rustc_hir:: def:: { CtorOf , DefKind , Res } ;
15
15
use rustc_hir:: def_id:: { DefId , LocalDefId , LocalModDefId } ;
16
16
use rustc_hir:: intravisit:: { self , Visitor } ;
17
- use rustc_hir:: { self as hir, Node , PatKind , QPath , TyKind } ;
17
+ use rustc_hir:: { self as hir, ImplItem , ImplItemKind , Node , PatKind , QPath , TyKind } ;
18
18
use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
19
19
use rustc_middle:: middle:: privacy:: Level ;
20
20
use rustc_middle:: query:: Providers ;
@@ -936,7 +936,9 @@ enum ShouldWarnAboutField {
936
936
937
937
#[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
938
938
enum ReportOn {
939
+ /// Report on something that hasn't got a proper name to refer to
939
940
TupleField ,
941
+ /// Report on something that has got a name, which could be a field but also a method
940
942
NamedField ,
941
943
}
942
944
@@ -1061,6 +1063,31 @@ impl<'tcx> DeadVisitor<'tcx> {
1061
1063
None
1062
1064
} ;
1063
1065
1066
+ let enum_variants_with_same_name = dead_codes
1067
+ . iter ( )
1068
+ . filter_map ( |dead_item| {
1069
+ if let Node :: ImplItem ( ImplItem {
1070
+ kind : ImplItemKind :: Fn ( ..) | ImplItemKind :: Const ( ..) ,
1071
+ ..
1072
+ } ) = tcx. hir_node_by_def_id ( dead_item. def_id )
1073
+ && let Some ( impl_did) = tcx. opt_parent ( dead_item. def_id . to_def_id ( ) )
1074
+ && let DefKind :: Impl { of_trait : false } = tcx. def_kind ( impl_did)
1075
+ && let ty:: Adt ( maybe_enum, _) = tcx. type_of ( impl_did) . skip_binder ( ) . kind ( )
1076
+ && maybe_enum. is_enum ( )
1077
+ && let Some ( variant) =
1078
+ maybe_enum. variants ( ) . iter ( ) . find ( |i| i. name == dead_item. name )
1079
+ {
1080
+ Some ( crate :: errors:: EnumVariantSameName {
1081
+ descr : tcx. def_descr ( dead_item. def_id . to_def_id ( ) ) ,
1082
+ dead_name : dead_item. name ,
1083
+ variant_span : tcx. def_span ( variant. def_id ) ,
1084
+ } )
1085
+ } else {
1086
+ None
1087
+ }
1088
+ } )
1089
+ . collect ( ) ;
1090
+
1064
1091
let diag = match report_on {
1065
1092
ReportOn :: TupleField => {
1066
1093
let tuple_fields = if let Some ( parent_id) = parent_item
@@ -1114,6 +1141,7 @@ impl<'tcx> DeadVisitor<'tcx> {
1114
1141
name_list,
1115
1142
parent_info,
1116
1143
ignored_derived_impls,
1144
+ enum_variants_with_same_name,
1117
1145
} ,
1118
1146
} ;
1119
1147
0 commit comments