File tree Expand file tree Collapse file tree 1 file changed +15
-19
lines changed Expand file tree Collapse file tree 1 file changed +15
-19
lines changed Original file line number Diff line number Diff line change @@ -64,25 +64,21 @@ declare_lint_pass!(EmptyEnum => [EMPTY_ENUM]);
64
64
65
65
impl < ' tcx > LateLintPass < ' tcx > for EmptyEnum {
66
66
fn check_item ( & mut self , cx : & LateContext < ' _ > , item : & Item < ' _ > ) {
67
- // Only suggest the `never_type` if the feature is enabled
68
- if !cx. tcx . features ( ) . never_type {
69
- return ;
70
- }
71
-
72
- if let ItemKind :: Enum ( ..) = item. kind {
73
- let ty = cx. tcx . type_of ( item. owner_id ) . instantiate_identity ( ) ;
74
- let adt = ty. ty_adt_def ( ) . expect ( "already checked whether this is an enum" ) ;
75
- if adt. variants ( ) . is_empty ( ) {
76
- span_lint_and_help (
77
- cx,
78
- EMPTY_ENUM ,
79
- item. span ,
80
- "enum with no variants" ,
81
- None ,
82
- "consider using the uninhabited type `!` (never type) or a wrapper \
83
- around it to introduce a type which can't be instantiated",
84
- ) ;
85
- }
67
+ if let ItemKind :: Enum ( ..) = item. kind
68
+ // Only suggest the `never_type` if the feature is enabled
69
+ && cx. tcx . features ( ) . never_type
70
+ && let Some ( adt) = cx. tcx . type_of ( item. owner_id ) . instantiate_identity ( ) . ty_adt_def ( )
71
+ && adt. variants ( ) . is_empty ( )
72
+ {
73
+ span_lint_and_help (
74
+ cx,
75
+ EMPTY_ENUM ,
76
+ item. span ,
77
+ "enum with no variants" ,
78
+ None ,
79
+ "consider using the uninhabited type `!` (never type) or a wrapper \
80
+ around it to introduce a type which can't be instantiated",
81
+ ) ;
86
82
}
87
83
}
88
84
}
You can’t perform that action at this time.
0 commit comments