@@ -2671,6 +2671,8 @@ pub struct TomlProfile {
26712671 // requires all non-tables to be listed first.
26722672 pub package : Option < BTreeMap < ProfilePackageSpec , TomlProfile > > ,
26732673 pub build_override : Option < Box < TomlProfile > > ,
2674+ /// Unstable feature `-Ztrim-paths`.
2675+ pub trim_paths : Option < TomlTrimPaths > ,
26742676}
26752677
26762678impl TomlProfile {
@@ -2871,6 +2873,15 @@ impl TomlProfile {
28712873 _ => { }
28722874 }
28732875 }
2876+ if self . trim_paths . is_some ( ) {
2877+ match (
2878+ features. require ( Feature :: trim_paths ( ) ) ,
2879+ cli_unstable. trim_paths ,
2880+ ) {
2881+ ( Err ( e) , false ) => return Err ( e) ,
2882+ _ => { }
2883+ }
2884+ }
28742885 Ok ( ( ) )
28752886 }
28762887
@@ -3146,6 +3157,120 @@ impl<'de> de::Deserialize<'de> for TomlDebugInfo {
31463157 }
31473158}
31483159
3160+ #[ derive( Clone , Debug , PartialEq , Eq , Ord , PartialOrd , Hash , Serialize ) ]
3161+ #[ serde( untagged) ]
3162+ pub enum TomlTrimPaths {
3163+ One ( TomlTrimPathsValue ) ,
3164+ Many ( Vec < TomlTrimPathsValue > ) ,
3165+ }
3166+
3167+ impl < ' de > de:: Deserialize < ' de > for TomlTrimPaths {
3168+ fn deserialize < D > ( d : D ) -> Result < TomlTrimPaths , D :: Error >
3169+ where
3170+ D : de:: Deserializer < ' de > ,
3171+ {
3172+ let expecting = r#"a boolean, "none", "macro", "diagnostics", "object", "all", or a list of these options"# ;
3173+ UntaggedEnumVisitor :: new ( )
3174+ . expecting ( expecting)
3175+ . bool ( |value| {
3176+ Ok ( if value {
3177+ TomlTrimPaths :: all ( )
3178+ } else {
3179+ TomlTrimPaths :: none ( )
3180+ } )
3181+ } )
3182+ . string ( |value| {
3183+ TomlTrimPathsValue :: deserialize ( value. into_deserializer ( ) ) . map ( TomlTrimPaths :: One )
3184+ } )
3185+ . seq ( |seq| {
3186+ let seq: Vec < String > = seq. deserialize ( ) ?;
3187+ let seq = seq
3188+ . into_iter ( )
3189+ . map ( |s| TomlTrimPathsValue :: deserialize ( s. into_deserializer ( ) ) )
3190+ . collect :: < Result < _ , _ > > ( ) ?;
3191+ Ok ( TomlTrimPaths :: Many ( seq) )
3192+ } )
3193+ . deserialize ( d)
3194+ }
3195+ }
3196+
3197+ impl TomlTrimPaths {
3198+ pub fn none ( ) -> TomlTrimPaths {
3199+ TomlTrimPaths :: One ( TomlTrimPathsValue :: None )
3200+ }
3201+
3202+ pub fn all ( ) -> TomlTrimPaths {
3203+ TomlTrimPaths :: One ( TomlTrimPathsValue :: All )
3204+ }
3205+
3206+ pub fn diagnostics ( ) -> TomlTrimPaths {
3207+ TomlTrimPaths :: One ( TomlTrimPathsValue :: Diagnostics )
3208+ }
3209+
3210+ pub fn r#macro ( ) -> TomlTrimPaths {
3211+ TomlTrimPaths :: One ( TomlTrimPathsValue :: Macro )
3212+ }
3213+
3214+ pub fn object ( ) -> TomlTrimPaths {
3215+ TomlTrimPaths :: One ( TomlTrimPathsValue :: Object )
3216+ }
3217+
3218+ pub fn is_none ( & self ) -> bool {
3219+ match self {
3220+ TomlTrimPaths :: One ( TomlTrimPathsValue :: None ) => true ,
3221+ TomlTrimPaths :: Many ( list) if list. is_empty ( ) => true ,
3222+ TomlTrimPaths :: Many ( list) => list. iter ( ) . any ( |v| matches ! ( v, TomlTrimPathsValue :: None ) ) ,
3223+ _ => false ,
3224+ }
3225+ }
3226+ }
3227+
3228+ impl fmt:: Display for TomlTrimPaths {
3229+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
3230+ match self {
3231+ TomlTrimPaths :: One ( value) => write ! ( f, "{value}" ) ,
3232+ TomlTrimPaths :: Many ( values) => {
3233+ let mut iter = values. iter ( ) ;
3234+ if let Some ( value) = iter. next ( ) {
3235+ write ! ( f, "{value}" ) ?;
3236+ }
3237+ for value in iter {
3238+ write ! ( f, ",{value}" ) ?;
3239+ }
3240+ Ok ( ( ) )
3241+ }
3242+ }
3243+ }
3244+ }
3245+
3246+ #[ derive( Clone , Debug , PartialEq , Eq , Ord , PartialOrd , Hash , Serialize , Deserialize ) ]
3247+ #[ serde( rename_all = "kebab-case" ) ]
3248+ pub enum TomlTrimPathsValue {
3249+ None ,
3250+ Diagnostics ,
3251+ Macro ,
3252+ Object ,
3253+ All ,
3254+ }
3255+
3256+ impl TomlTrimPathsValue {
3257+ pub fn as_str ( & self ) -> & ' static str {
3258+ match self {
3259+ TomlTrimPathsValue :: None => "none" ,
3260+ TomlTrimPathsValue :: Diagnostics => "diagnostics" ,
3261+ TomlTrimPathsValue :: Macro => "macro" ,
3262+ TomlTrimPathsValue :: Object => "object" ,
3263+ TomlTrimPathsValue :: All => "all" ,
3264+ }
3265+ }
3266+ }
3267+
3268+ impl fmt:: Display for TomlTrimPathsValue {
3269+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
3270+ write ! ( f, "{}" , self . as_str( ) )
3271+ }
3272+ }
3273+
31493274type TomlLibTarget = TomlTarget ;
31503275type TomlBinTarget = TomlTarget ;
31513276type TomlExampleTarget = TomlTarget ;
0 commit comments