@@ -2692,6 +2692,8 @@ pub struct TomlProfile {
26922692 // requires all non-tables to be listed first.
26932693 pub package : Option < BTreeMap < ProfilePackageSpec , TomlProfile > > ,
26942694 pub build_override : Option < Box < TomlProfile > > ,
2695+ /// Unstable feature `-Ztrim-paths`.
2696+ pub trim_paths : Option < TomlTrimPaths > ,
26952697}
26962698
26972699impl TomlProfile {
@@ -2892,6 +2894,15 @@ impl TomlProfile {
28922894 _ => { }
28932895 }
28942896 }
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+ }
28952906 Ok ( ( ) )
28962907 }
28972908
@@ -3167,6 +3178,122 @@ impl<'de> de::Deserialize<'de> for TomlDebugInfo {
31673178 }
31683179}
31693180
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 < ' de > de:: Deserialize < ' de > for TomlTrimPaths {
3189+ fn deserialize < D > ( d : D ) -> Result < TomlTrimPaths , D :: Error >
3190+ where
3191+ D : de:: Deserializer < ' de > ,
3192+ {
3193+ use serde:: de:: Error as _;
3194+ let expecting = r#"a boolean, "none", "diagnostics", "macro", "object", "all", or an array with these options"# ;
3195+ UntaggedEnumVisitor :: new ( )
3196+ . expecting ( expecting)
3197+ . bool ( |value| {
3198+ Ok ( if value {
3199+ TomlTrimPaths :: All
3200+ } else {
3201+ TomlTrimPaths :: none ( )
3202+ } )
3203+ } )
3204+ . string ( |v| match v {
3205+ "none" => Ok ( TomlTrimPaths :: none ( ) ) ,
3206+ "all" => Ok ( TomlTrimPaths :: All ) ,
3207+ v => {
3208+ let d = v. into_deserializer ( ) ;
3209+ let err = |_: D :: Error | {
3210+ serde_untagged:: de:: Error :: custom ( format ! ( "expected {expecting}" ) )
3211+ } ;
3212+ TomlTrimPathsValue :: deserialize ( d)
3213+ . map_err ( err)
3214+ . map ( |v| v. into ( ) )
3215+ }
3216+ } )
3217+ . seq ( |seq| {
3218+ let seq: Vec < String > = seq. deserialize ( ) ?;
3219+ let seq: Vec < _ > = seq
3220+ . into_iter ( )
3221+ . map ( |s| TomlTrimPathsValue :: deserialize ( s. into_deserializer ( ) ) )
3222+ . collect :: < Result < _ , _ > > ( ) ?;
3223+ Ok ( seq. into ( ) )
3224+ } )
3225+ . deserialize ( d)
3226+ }
3227+ }
3228+
3229+ impl TomlTrimPaths {
3230+ pub fn none ( ) -> Self {
3231+ TomlTrimPaths :: Values ( Vec :: new ( ) )
3232+ }
3233+
3234+ pub fn is_none ( & self ) -> bool {
3235+ match self {
3236+ TomlTrimPaths :: Values ( v) => v. is_empty ( ) ,
3237+ TomlTrimPaths :: All => false ,
3238+ }
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+
31703297type TomlLibTarget = TomlTarget ;
31713298type TomlBinTarget = TomlTarget ;
31723299type TomlExampleTarget = TomlTarget ;
0 commit comments