@@ -98,6 +98,7 @@ impl CheckAttrVisitor<'_> {
98
98
target,
99
99
& mut specified_inline,
100
100
& mut doc_aliases,
101
+ & mut seen,
101
102
) ,
102
103
sym:: no_link => self . check_no_link ( hir_id, & attr, span, target) ,
103
104
sym:: export_name => self . check_export_name ( hir_id, & attr, span, target) ,
@@ -948,15 +949,16 @@ impl CheckAttrVisitor<'_> {
948
949
949
950
/// Checks that `doc(auto_cfg)` is valid (i.e. no value) and warn if it's used whereas the
950
951
/// "equivalent feature" is already enabled.
951
- fn check_auto_cfg ( & self , meta : & MetaItem , hir_id : HirId ) -> bool {
952
+ fn check_auto_cfg ( & self , meta : & MetaItem , hir_id : HirId , seen : & mut FxHashMap < Symbol , Span > ) -> bool {
952
953
let name = meta. name_or_empty ( ) ;
953
- let mut is_valid = true ;
954
954
if !meta. is_word ( ) {
955
955
self . tcx
956
956
. sess
957
957
. emit_err ( errors:: DocAutoCfgMalformed { span : meta. span , attr_str : name. as_str ( ) } ) ;
958
- is_valid = false ;
959
- } else if name == sym:: no_auto_cfg {
958
+ return false ;
959
+ }
960
+ let mut is_valid = true ;
961
+ let other = if name == sym:: no_auto_cfg {
960
962
if self . tcx . sess . edition ( ) < Edition :: Edition2024 {
961
963
self . tcx . emit_spanned_lint (
962
964
UNUSED_ATTRIBUTES ,
@@ -966,6 +968,7 @@ impl CheckAttrVisitor<'_> {
966
968
) ;
967
969
is_valid = false ;
968
970
}
971
+ sym:: auto_cfg
969
972
} else {
970
973
if self . tcx . sess . edition ( ) > Edition :: Edition2021 {
971
974
self . tcx . emit_spanned_lint (
@@ -976,7 +979,21 @@ impl CheckAttrVisitor<'_> {
976
979
) ;
977
980
is_valid = false ;
978
981
}
982
+ sym:: no_auto_cfg
983
+ } ;
984
+
985
+ match seen. entry ( other) {
986
+ Entry :: Occupied ( entry) => {
987
+ self . tcx
988
+ . sess
989
+ . emit_err ( errors:: BothDocAutoCfg { span : * entry. get ( ) , attr_span : meta. span } ) ;
990
+ is_valid = false ;
991
+ }
992
+ Entry :: Vacant ( entry) => {
993
+ entry. insert ( meta. span ) ;
994
+ }
979
995
}
996
+
980
997
is_valid
981
998
}
982
999
@@ -993,6 +1010,7 @@ impl CheckAttrVisitor<'_> {
993
1010
target : Target ,
994
1011
specified_inline : & mut Option < ( bool , Span ) > ,
995
1012
aliases : & mut FxHashMap < String , Span > ,
1013
+ seen : & mut FxHashMap < Symbol , Span > ,
996
1014
) -> bool {
997
1015
let mut is_valid = true ;
998
1016
@@ -1048,7 +1066,7 @@ impl CheckAttrVisitor<'_> {
1048
1066
}
1049
1067
1050
1068
sym:: auto_cfg | sym:: no_auto_cfg
1051
- if !self . check_auto_cfg ( i_meta, hir_id) => {
1069
+ if !self . check_auto_cfg ( i_meta, hir_id, seen ) => {
1052
1070
is_valid = false ;
1053
1071
}
1054
1072
0 commit comments