@@ -99,6 +99,21 @@ impl IntoDiagArg for ProcMacroKind {
99
99
}
100
100
}
101
101
102
+ #[ derive( Clone , Copy ) ]
103
+ enum DocFakeItemKind {
104
+ Attribute ,
105
+ Keyword ,
106
+ }
107
+
108
+ impl DocFakeItemKind {
109
+ fn name ( self ) -> & ' static str {
110
+ match self {
111
+ Self :: Attribute => "attribute" ,
112
+ Self :: Keyword => "keyword" ,
113
+ }
114
+ }
115
+ }
116
+
102
117
struct CheckAttrVisitor < ' tcx > {
103
118
tcx : TyCtxt < ' tcx > ,
104
119
@@ -855,7 +870,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
855
870
& self ,
856
871
meta : & MetaItemInner ,
857
872
hir_id : HirId ,
858
- is_keyword : bool ,
873
+ attr_kind : DocFakeItemKind ,
859
874
) {
860
875
fn is_doc_keyword ( s : Symbol ) -> bool {
861
876
// FIXME: Once rustdoc can handle URL conflicts on case insensitive file systems, we
@@ -868,13 +883,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
868
883
rustc_feature:: BUILTIN_ATTRIBUTE_MAP . contains_key ( & s)
869
884
}
870
885
871
- fn get_attr_name ( is_keyword : bool ) -> & ' static str {
872
- if is_keyword { "keyword" } else { "attribute" }
873
- }
874
-
875
886
let value = match meta. value_str ( ) {
876
887
Some ( value) if value != sym:: empty => value,
877
- _ => return self . doc_attr_str_error ( meta, get_attr_name ( is_keyword ) ) ,
888
+ _ => return self . doc_attr_str_error ( meta, attr_kind . name ( ) ) ,
878
889
} ;
879
890
880
891
let item_kind = match self . tcx . hir_node ( hir_id) {
@@ -886,31 +897,36 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
886
897
if !module. item_ids . is_empty ( ) {
887
898
self . dcx ( ) . emit_err ( errors:: DocKeywordAttributeEmptyMod {
888
899
span : meta. span ( ) ,
889
- attr_name : get_attr_name ( is_keyword ) ,
900
+ attr_name : attr_kind . name ( ) ,
890
901
} ) ;
891
902
return ;
892
903
}
893
904
}
894
905
_ => {
895
906
self . dcx ( ) . emit_err ( errors:: DocKeywordAttributeNotMod {
896
907
span : meta. span ( ) ,
897
- attr_name : get_attr_name ( is_keyword ) ,
908
+ attr_name : attr_kind . name ( ) ,
898
909
} ) ;
899
910
return ;
900
911
}
901
912
}
902
- if is_keyword {
903
- if !is_doc_keyword ( value) {
904
- self . dcx ( ) . emit_err ( errors:: DocKeywordNotKeyword {
905
- span : meta. name_value_literal_span ( ) . unwrap_or_else ( || meta. span ( ) ) ,
906
- keyword : value,
907
- } ) ;
913
+ match attr_kind {
914
+ DocFakeItemKind :: Keyword => {
915
+ if !is_doc_keyword ( value) {
916
+ self . dcx ( ) . emit_err ( errors:: DocKeywordNotKeyword {
917
+ span : meta. name_value_literal_span ( ) . unwrap_or_else ( || meta. span ( ) ) ,
918
+ keyword : value,
919
+ } ) ;
920
+ }
921
+ }
922
+ DocFakeItemKind :: Attribute => {
923
+ if !is_builtin_attr ( value) {
924
+ self . dcx ( ) . emit_err ( errors:: DocAttributeNotAttribute {
925
+ span : meta. name_value_literal_span ( ) . unwrap_or_else ( || meta. span ( ) ) ,
926
+ attribute : value,
927
+ } ) ;
928
+ }
908
929
}
909
- } else if !is_builtin_attr ( value) {
910
- self . dcx ( ) . emit_err ( errors:: DocAttributeNotAttribute {
911
- span : meta. name_value_literal_span ( ) . unwrap_or_else ( || meta. span ( ) ) ,
912
- attribute : value,
913
- } ) ;
914
930
}
915
931
}
916
932
@@ -1170,13 +1186,21 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
1170
1186
1171
1187
Some ( sym:: keyword) => {
1172
1188
if self . check_attr_not_crate_level ( meta, hir_id, "keyword" ) {
1173
- self . check_doc_keyword_and_attribute ( meta, hir_id, true ) ;
1189
+ self . check_doc_keyword_and_attribute (
1190
+ meta,
1191
+ hir_id,
1192
+ DocFakeItemKind :: Keyword ,
1193
+ ) ;
1174
1194
}
1175
1195
}
1176
1196
1177
1197
Some ( sym:: attribute) => {
1178
1198
if self . check_attr_not_crate_level ( meta, hir_id, "attribute" ) {
1179
- self . check_doc_keyword_and_attribute ( meta, hir_id, false ) ;
1199
+ self . check_doc_keyword_and_attribute (
1200
+ meta,
1201
+ hir_id,
1202
+ DocFakeItemKind :: Attribute ,
1203
+ ) ;
1180
1204
}
1181
1205
}
1182
1206
0 commit comments