@@ -2682,6 +2682,8 @@ pub struct TomlProfile {
2682
2682
// requires all non-tables to be listed first.
2683
2683
pub package : Option < BTreeMap < ProfilePackageSpec , TomlProfile > > ,
2684
2684
pub build_override : Option < Box < TomlProfile > > ,
2685
+ /// Unstable feature `-Ztrim-paths`.
2686
+ pub trim_paths : Option < TomlTrimPaths > ,
2685
2687
}
2686
2688
2687
2689
impl TomlProfile {
@@ -2882,6 +2884,15 @@ impl TomlProfile {
2882
2884
_ => { }
2883
2885
}
2884
2886
}
2887
+ if self . trim_paths . is_some ( ) {
2888
+ match (
2889
+ features. require ( Feature :: trim_paths ( ) ) ,
2890
+ cli_unstable. trim_paths ,
2891
+ ) {
2892
+ ( Err ( e) , false ) => return Err ( e) ,
2893
+ _ => { }
2894
+ }
2895
+ }
2885
2896
Ok ( ( ) )
2886
2897
}
2887
2898
@@ -3157,6 +3168,122 @@ impl<'de> de::Deserialize<'de> for TomlDebugInfo {
3157
3168
}
3158
3169
}
3159
3170
3171
+ #[ derive( Clone , Debug , PartialEq , Eq , Ord , PartialOrd , Hash , Serialize ) ]
3172
+ #[ serde( untagged, rename_all = "kebab-case" ) ]
3173
+ pub enum TomlTrimPaths {
3174
+ Values ( Vec < TomlTrimPathsValue > ) ,
3175
+ All ,
3176
+ }
3177
+
3178
+ impl < ' de > de:: Deserialize < ' de > for TomlTrimPaths {
3179
+ fn deserialize < D > ( d : D ) -> Result < TomlTrimPaths , D :: Error >
3180
+ where
3181
+ D : de:: Deserializer < ' de > ,
3182
+ {
3183
+ use serde:: de:: Error as _;
3184
+ let expecting = r#"a boolean, "none", "diagnostics", "macro", "object", "all", or an array with these options"# ;
3185
+ UntaggedEnumVisitor :: new ( )
3186
+ . expecting ( expecting)
3187
+ . bool ( |value| {
3188
+ Ok ( if value {
3189
+ TomlTrimPaths :: All
3190
+ } else {
3191
+ TomlTrimPaths :: none ( )
3192
+ } )
3193
+ } )
3194
+ . string ( |v| match v {
3195
+ "none" => Ok ( TomlTrimPaths :: none ( ) ) ,
3196
+ "all" => Ok ( TomlTrimPaths :: All ) ,
3197
+ v => {
3198
+ let d = v. into_deserializer ( ) ;
3199
+ let err = |_: D :: Error | {
3200
+ serde_untagged:: de:: Error :: custom ( format ! ( "expected {expecting}" ) )
3201
+ } ;
3202
+ TomlTrimPathsValue :: deserialize ( d)
3203
+ . map_err ( err)
3204
+ . map ( |v| v. into ( ) )
3205
+ }
3206
+ } )
3207
+ . seq ( |seq| {
3208
+ let seq: Vec < String > = seq. deserialize ( ) ?;
3209
+ let seq: Vec < _ > = seq
3210
+ . into_iter ( )
3211
+ . map ( |s| TomlTrimPathsValue :: deserialize ( s. into_deserializer ( ) ) )
3212
+ . collect :: < Result < _ , _ > > ( ) ?;
3213
+ Ok ( seq. into ( ) )
3214
+ } )
3215
+ . deserialize ( d)
3216
+ }
3217
+ }
3218
+
3219
+ impl TomlTrimPaths {
3220
+ pub fn none ( ) -> Self {
3221
+ TomlTrimPaths :: Values ( Vec :: new ( ) )
3222
+ }
3223
+
3224
+ pub fn is_none ( & self ) -> bool {
3225
+ match self {
3226
+ TomlTrimPaths :: Values ( v) => v. is_empty ( ) ,
3227
+ TomlTrimPaths :: All => false ,
3228
+ }
3229
+ }
3230
+ }
3231
+
3232
+ impl fmt:: Display for TomlTrimPaths {
3233
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
3234
+ match self {
3235
+ TomlTrimPaths :: All => write ! ( f, "all" ) ,
3236
+ TomlTrimPaths :: Values ( v) if v. is_empty ( ) => write ! ( f, "none" ) ,
3237
+ TomlTrimPaths :: Values ( v) => {
3238
+ let mut iter = v. iter ( ) ;
3239
+ if let Some ( value) = iter. next ( ) {
3240
+ write ! ( f, "{value}" ) ?;
3241
+ }
3242
+ for value in iter {
3243
+ write ! ( f, ",{value}" ) ?;
3244
+ }
3245
+ Ok ( ( ) )
3246
+ }
3247
+ }
3248
+ }
3249
+ }
3250
+
3251
+ impl From < TomlTrimPathsValue > for TomlTrimPaths {
3252
+ fn from ( value : TomlTrimPathsValue ) -> Self {
3253
+ TomlTrimPaths :: Values ( vec ! [ value] )
3254
+ }
3255
+ }
3256
+
3257
+ impl From < Vec < TomlTrimPathsValue > > for TomlTrimPaths {
3258
+ fn from ( value : Vec < TomlTrimPathsValue > ) -> Self {
3259
+ TomlTrimPaths :: Values ( value)
3260
+ }
3261
+ }
3262
+
3263
+ #[ derive( Clone , Debug , PartialEq , Eq , Ord , PartialOrd , Hash , Serialize , Deserialize ) ]
3264
+ #[ serde( rename_all = "kebab-case" ) ]
3265
+ pub enum TomlTrimPathsValue {
3266
+ Diagnostics ,
3267
+ Macro ,
3268
+ Object ,
3269
+ }
3270
+
3271
+ impl TomlTrimPathsValue {
3272
+ pub fn as_str ( & self ) -> & ' static str {
3273
+ match self {
3274
+ TomlTrimPathsValue :: Diagnostics => "diagnostics" ,
3275
+ TomlTrimPathsValue :: Macro => "macro" ,
3276
+ TomlTrimPathsValue :: Object => "object" ,
3277
+ }
3278
+ }
3279
+ }
3280
+
3281
+ impl fmt:: Display for TomlTrimPathsValue {
3282
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
3283
+ write ! ( f, "{}" , self . as_str( ) )
3284
+ }
3285
+ }
3286
+
3160
3287
type TomlLibTarget = TomlTarget ;
3161
3288
type TomlBinTarget = TomlTarget ;
3162
3289
type TomlExampleTarget = TomlTarget ;
0 commit comments