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