@@ -13,6 +13,7 @@ use rustc_data_structures::impl_stable_hash_via_hash;
13
13
14
14
use rustc_target:: abi:: { Align , TargetDataLayout } ;
15
15
use rustc_target:: spec:: { LinkerFlavor , SplitDebuginfo , Target , TargetTriple , TargetWarnings } ;
16
+ use rustc_target:: spec:: { PanicStrategy , SanitizerSet , TARGETS } ;
16
17
17
18
use rustc_serialize:: json;
18
19
@@ -1025,13 +1026,19 @@ pub fn to_crate_config(cfg: FxHashSet<(String, Option<String>)>) -> CrateConfig
1025
1026
pub struct CheckCfg < T = String > {
1026
1027
/// The set of all `names()`, if None no name checking is performed
1027
1028
pub names_valid : Option < FxHashSet < T > > ,
1029
+ /// Is well known values activated
1030
+ pub well_known_values : bool ,
1028
1031
/// The set of all `values()`
1029
1032
pub values_valid : FxHashMap < T , FxHashSet < T > > ,
1030
1033
}
1031
1034
1032
1035
impl < T > Default for CheckCfg < T > {
1033
1036
fn default ( ) -> Self {
1034
- CheckCfg { names_valid : Default :: default ( ) , values_valid : Default :: default ( ) }
1037
+ CheckCfg {
1038
+ names_valid : Default :: default ( ) ,
1039
+ values_valid : Default :: default ( ) ,
1040
+ well_known_values : false ,
1041
+ }
1035
1042
}
1036
1043
}
1037
1044
@@ -1047,6 +1054,7 @@ impl<T> CheckCfg<T> {
1047
1054
. iter ( )
1048
1055
. map ( |( a, b) | ( f ( a) , b. iter ( ) . map ( |b| f ( b) ) . collect ( ) ) )
1049
1056
. collect ( ) ,
1057
+ well_known_values : self . well_known_values ,
1050
1058
}
1051
1059
}
1052
1060
}
@@ -1060,8 +1068,9 @@ pub fn to_crate_check_config(cfg: CheckCfg) -> CrateCheckConfig {
1060
1068
1061
1069
impl CrateCheckConfig {
1062
1070
/// Fills a `CrateCheckConfig` with well-known configuration names.
1063
- pub fn fill_well_known ( & mut self ) {
1064
- // NOTE: This should be kept in sync with `default_configuration`
1071
+ fn fill_well_known_names ( & mut self ) {
1072
+ // NOTE: This should be kept in sync with `default_configuration` and
1073
+ // `fill_well_known_values`
1065
1074
const WELL_KNOWN_NAMES : & [ Symbol ] = & [
1066
1075
sym:: unix,
1067
1076
sym:: windows,
@@ -1086,11 +1095,106 @@ impl CrateCheckConfig {
1086
1095
sym:: doctest,
1087
1096
sym:: feature,
1088
1097
] ;
1098
+
1099
+ // We only insert well-known names if `names()` was activated
1089
1100
if let Some ( names_valid) = & mut self . names_valid {
1090
- for & name in WELL_KNOWN_NAMES {
1091
- names_valid. insert ( name) ;
1092
- }
1101
+ names_valid. extend ( WELL_KNOWN_NAMES ) ;
1102
+ }
1103
+ }
1104
+
1105
+ /// Fills a `CrateCheckConfig` with well-known configuration values.
1106
+ fn fill_well_known_values ( & mut self ) {
1107
+ if !self . well_known_values {
1108
+ return ;
1093
1109
}
1110
+
1111
+ // NOTE: This should be kept in sync with `default_configuration` and
1112
+ // `fill_well_known_names`
1113
+
1114
+ let panic_values = & PanicStrategy :: all ( ) ;
1115
+
1116
+ let atomic_values = & [
1117
+ sym:: ptr,
1118
+ sym:: integer ( 8usize ) ,
1119
+ sym:: integer ( 16usize ) ,
1120
+ sym:: integer ( 32usize ) ,
1121
+ sym:: integer ( 64usize ) ,
1122
+ sym:: integer ( 128usize ) ,
1123
+ ] ;
1124
+
1125
+ let sanitize_values = SanitizerSet :: all ( )
1126
+ . into_iter ( )
1127
+ . map ( |sanitizer| Symbol :: intern ( sanitizer. as_str ( ) . unwrap ( ) ) ) ;
1128
+
1129
+ // No-values
1130
+ for name in [
1131
+ sym:: unix,
1132
+ sym:: windows,
1133
+ sym:: debug_assertions,
1134
+ sym:: proc_macro,
1135
+ sym:: test,
1136
+ sym:: doc,
1137
+ sym:: doctest,
1138
+ sym:: target_thread_local,
1139
+ ] {
1140
+ self . values_valid . entry ( name) . or_default ( ) ;
1141
+ }
1142
+
1143
+ // Pre-defined values
1144
+ self . values_valid . entry ( sym:: panic) . or_default ( ) . extend ( panic_values) ;
1145
+ self . values_valid . entry ( sym:: sanitize) . or_default ( ) . extend ( sanitize_values) ;
1146
+ self . values_valid . entry ( sym:: target_has_atomic) . or_default ( ) . extend ( atomic_values) ;
1147
+ self . values_valid
1148
+ . entry ( sym:: target_has_atomic_load_store)
1149
+ . or_default ( )
1150
+ . extend ( atomic_values) ;
1151
+ self . values_valid
1152
+ . entry ( sym:: target_has_atomic_equal_alignment)
1153
+ . or_default ( )
1154
+ . extend ( atomic_values) ;
1155
+
1156
+ // Target specific values
1157
+ for target in
1158
+ TARGETS . iter ( ) . map ( |target| Target :: expect_builtin ( & TargetTriple :: from_triple ( target) ) )
1159
+ {
1160
+ self . values_valid
1161
+ . entry ( sym:: target_os)
1162
+ . or_default ( )
1163
+ . insert ( Symbol :: intern ( & target. options . os ) ) ;
1164
+ self . values_valid
1165
+ . entry ( sym:: target_family)
1166
+ . or_default ( )
1167
+ . extend ( target. options . families . iter ( ) . map ( |family| Symbol :: intern ( family) ) ) ;
1168
+ self . values_valid
1169
+ . entry ( sym:: target_arch)
1170
+ . or_default ( )
1171
+ . insert ( Symbol :: intern ( & target. arch ) ) ;
1172
+ self . values_valid
1173
+ . entry ( sym:: target_endian)
1174
+ . or_default ( )
1175
+ . insert ( Symbol :: intern ( & target. options . endian . as_str ( ) ) ) ;
1176
+ self . values_valid
1177
+ . entry ( sym:: target_env)
1178
+ . or_default ( )
1179
+ . insert ( Symbol :: intern ( & target. options . env ) ) ;
1180
+ self . values_valid
1181
+ . entry ( sym:: target_abi)
1182
+ . or_default ( )
1183
+ . insert ( Symbol :: intern ( & target. options . abi ) ) ;
1184
+ self . values_valid
1185
+ . entry ( sym:: target_vendor)
1186
+ . or_default ( )
1187
+ . insert ( Symbol :: intern ( & target. options . vendor ) ) ;
1188
+ self . values_valid
1189
+ . entry ( sym:: target_pointer_width)
1190
+ . or_default ( )
1191
+ . insert ( sym:: integer ( target. pointer_width ) ) ;
1192
+ }
1193
+ }
1194
+
1195
+ pub fn fill_well_known ( & mut self ) {
1196
+ self . fill_well_known_names ( ) ;
1197
+ self . fill_well_known_values ( ) ;
1094
1198
}
1095
1199
1096
1200
/// Fills a `CrateCheckConfig` with configuration names and values that are actually active.
0 commit comments