@@ -954,7 +954,7 @@ impl schema::TomlManifest {
954
954
let profiles = me. profile . clone ( ) ;
955
955
if let Some ( profiles) = & profiles {
956
956
let cli_unstable = config. cli_unstable ( ) ;
957
- profiles . validate ( cli_unstable, & features, & mut warnings) ?;
957
+ validate_profiles ( profiles , cli_unstable, & features, & mut warnings) ?;
958
958
}
959
959
960
960
let publish = package. publish . clone ( ) . map ( |publish| {
@@ -1155,7 +1155,7 @@ impl schema::TomlManifest {
1155
1155
} ;
1156
1156
let profiles = me. profile . clone ( ) ;
1157
1157
if let Some ( profiles) = & profiles {
1158
- profiles . validate ( config. cli_unstable ( ) , & features, & mut warnings) ?;
1158
+ validate_profiles ( profiles , config. cli_unstable ( ) , & features, & mut warnings) ?;
1159
1159
}
1160
1160
let resolve_behavior = me
1161
1161
. workspace
@@ -1969,175 +1969,179 @@ impl<P: ResolveToPath + Clone> schema::TomlDetailedDependency<P> {
1969
1969
}
1970
1970
}
1971
1971
1972
- impl schema:: TomlProfiles {
1973
- /// Checks syntax validity and unstable feature gate for each profile.
1974
- ///
1975
- /// It's a bit unfortunate both `-Z` flags and `cargo-features` are required,
1976
- /// because profiles can now be set in either `Cargo.toml` or `config.toml`.
1977
- fn validate (
1978
- & self ,
1979
- cli_unstable : & CliUnstable ,
1980
- features : & Features ,
1981
- warnings : & mut Vec < String > ,
1982
- ) -> CargoResult < ( ) > {
1983
- for ( name, profile) in & self . 0 {
1984
- profile. validate ( name, cli_unstable, features, warnings) ?;
1985
- }
1986
- Ok ( ( ) )
1972
+ /// Checks syntax validity and unstable feature gate for each profile.
1973
+ ///
1974
+ /// It's a bit unfortunate both `-Z` flags and `cargo-features` are required,
1975
+ /// because profiles can now be set in either `Cargo.toml` or `config.toml`.
1976
+ fn validate_profiles (
1977
+ profiles : & schema:: TomlProfiles ,
1978
+ cli_unstable : & CliUnstable ,
1979
+ features : & Features ,
1980
+ warnings : & mut Vec < String > ,
1981
+ ) -> CargoResult < ( ) > {
1982
+ for ( name, profile) in & profiles. 0 {
1983
+ validate_profile ( profile, name, cli_unstable, features, warnings) ?;
1987
1984
}
1985
+ Ok ( ( ) )
1988
1986
}
1989
1987
1990
- impl schema:: TomlProfile {
1991
- /// Checks stytax validity and unstable feature gate for a given profile.
1992
- pub fn validate (
1993
- & self ,
1994
- name : & str ,
1995
- cli_unstable : & CliUnstable ,
1996
- features : & Features ,
1997
- warnings : & mut Vec < String > ,
1998
- ) -> CargoResult < ( ) > {
1999
- self . validate_profile ( name, cli_unstable, features) ?;
2000
- if let Some ( ref profile) = self . build_override {
2001
- profile. validate_override ( "build-override" ) ?;
2002
- profile. validate_profile ( & format ! ( "{name}.build-override" ) , cli_unstable, features) ?;
2003
- }
2004
- if let Some ( ref packages) = self . package {
2005
- for ( override_name, profile) in packages {
2006
- profile. validate_override ( "package" ) ?;
2007
- profile. validate_profile (
2008
- & format ! ( "{name}.package.{override_name}" ) ,
2009
- cli_unstable,
2010
- features,
2011
- ) ?;
2012
- }
1988
+ /// Checks stytax validity and unstable feature gate for a given profile.
1989
+ pub fn validate_profile (
1990
+ root : & schema:: TomlProfile ,
1991
+ name : & str ,
1992
+ cli_unstable : & CliUnstable ,
1993
+ features : & Features ,
1994
+ warnings : & mut Vec < String > ,
1995
+ ) -> CargoResult < ( ) > {
1996
+ validate_profile_layer ( root, name, cli_unstable, features) ?;
1997
+ if let Some ( ref profile) = root. build_override {
1998
+ validate_profile_override ( profile, "build-override" ) ?;
1999
+ validate_profile_layer (
2000
+ profile,
2001
+ & format ! ( "{name}.build-override" ) ,
2002
+ cli_unstable,
2003
+ features,
2004
+ ) ?;
2005
+ }
2006
+ if let Some ( ref packages) = root. package {
2007
+ for ( override_name, profile) in packages {
2008
+ validate_profile_override ( profile, "package" ) ?;
2009
+ validate_profile_layer (
2010
+ profile,
2011
+ & format ! ( "{name}.package.{override_name}" ) ,
2012
+ cli_unstable,
2013
+ features,
2014
+ ) ?;
2013
2015
}
2016
+ }
2014
2017
2015
- // Profile name validation
2016
- restricted_names:: validate_profile_name ( name) ?;
2018
+ // Profile name validation
2019
+ restricted_names:: validate_profile_name ( name) ?;
2017
2020
2018
- if let Some ( dir_name) = & self . dir_name {
2019
- // This is disabled for now, as we would like to stabilize named
2020
- // profiles without this, and then decide in the future if it is
2021
- // needed. This helps simplify the UI a little.
2022
- bail ! (
2023
- "dir-name=\" {}\" in profile `{}` is not currently allowed, \
2021
+ if let Some ( dir_name) = & root . dir_name {
2022
+ // This is disabled for now, as we would like to stabilize named
2023
+ // profiles without this, and then decide in the future if it is
2024
+ // needed. This helps simplify the UI a little.
2025
+ bail ! (
2026
+ "dir-name=\" {}\" in profile `{}` is not currently allowed, \
2024
2027
directory names are tied to the profile name for custom profiles",
2025
- dir_name,
2026
- name
2027
- ) ;
2028
- }
2028
+ dir_name,
2029
+ name
2030
+ ) ;
2031
+ }
2029
2032
2030
- // `inherits` validation
2031
- if matches ! ( self . inherits. as_deref( ) , Some ( "debug" ) ) {
2032
- bail ! (
2033
- "profile.{}.inherits=\" debug\" should be profile.{}.inherits=\" dev\" " ,
2034
- name,
2035
- name
2036
- ) ;
2037
- }
2033
+ // `inherits` validation
2034
+ if matches ! ( root . inherits. as_deref( ) , Some ( "debug" ) ) {
2035
+ bail ! (
2036
+ "profile.{}.inherits=\" debug\" should be profile.{}.inherits=\" dev\" " ,
2037
+ name,
2038
+ name
2039
+ ) ;
2040
+ }
2038
2041
2039
- match name {
2040
- "doc" => {
2041
- warnings. push ( "profile `doc` is deprecated and has no effect" . to_string ( ) ) ;
2042
- }
2043
- "test" | "bench" => {
2044
- if self . panic . is_some ( ) {
2045
- warnings. push ( format ! ( "`panic` setting is ignored for `{}` profile" , name) )
2046
- }
2042
+ match name {
2043
+ "doc" => {
2044
+ warnings. push ( "profile `doc` is deprecated and has no effect" . to_string ( ) ) ;
2045
+ }
2046
+ "test" | "bench" => {
2047
+ if root. panic . is_some ( ) {
2048
+ warnings. push ( format ! ( "`panic` setting is ignored for `{}` profile" , name) )
2047
2049
}
2048
- _ => { }
2049
2050
}
2051
+ _ => { }
2052
+ }
2050
2053
2051
- if let Some ( panic) = & self . panic {
2052
- if panic != "unwind" && panic != "abort" {
2053
- bail ! (
2054
- "`panic` setting of `{}` is not a valid setting, \
2054
+ if let Some ( panic) = & root . panic {
2055
+ if panic != "unwind" && panic != "abort" {
2056
+ bail ! (
2057
+ "`panic` setting of `{}` is not a valid setting, \
2055
2058
must be `unwind` or `abort`",
2056
- panic
2057
- ) ;
2058
- }
2059
+ panic
2060
+ ) ;
2059
2061
}
2062
+ }
2060
2063
2061
- if let Some ( schema:: StringOrBool :: String ( arg) ) = & self . lto {
2062
- if arg == "true" || arg == "false" {
2063
- bail ! (
2064
- "`lto` setting of string `\" {arg}\" ` for `{name}` profile is not \
2064
+ if let Some ( schema:: StringOrBool :: String ( arg) ) = & root . lto {
2065
+ if arg == "true" || arg == "false" {
2066
+ bail ! (
2067
+ "`lto` setting of string `\" {arg}\" ` for `{name}` profile is not \
2065
2068
a valid setting, must be a boolean (`true`/`false`) or a string \
2066
2069
(`\" thin\" `/`\" fat\" `/`\" off\" `) or omitted.",
2067
- ) ;
2068
- }
2070
+ ) ;
2069
2071
}
2070
-
2071
- Ok ( ( ) )
2072
2072
}
2073
2073
2074
- /// Validates a profile.
2075
- ///
2076
- /// This is a shallow check, which is reused for the profile itself and any overrides.
2077
- fn validate_profile (
2078
- & self ,
2079
- name : & str ,
2080
- cli_unstable : & CliUnstable ,
2081
- features : & Features ,
2082
- ) -> CargoResult < ( ) > {
2083
- if let Some ( codegen_backend) = & self . codegen_backend {
2084
- match (
2085
- features. require ( Feature :: codegen_backend ( ) ) ,
2086
- cli_unstable. codegen_backend ,
2087
- ) {
2088
- ( Err ( e) , false ) => return Err ( e) ,
2089
- _ => { }
2090
- }
2074
+ Ok ( ( ) )
2075
+ }
2091
2076
2092
- if codegen_backend. contains ( |c : char | !c. is_ascii_alphanumeric ( ) && c != '_' ) {
2093
- bail ! (
2094
- "`profile.{}.codegen-backend` setting of `{}` is not a valid backend name." ,
2095
- name,
2096
- codegen_backend,
2097
- ) ;
2098
- }
2099
- }
2100
- if self . rustflags . is_some ( ) {
2101
- match (
2102
- features. require ( Feature :: profile_rustflags ( ) ) ,
2103
- cli_unstable. profile_rustflags ,
2104
- ) {
2105
- ( Err ( e) , false ) => return Err ( e) ,
2106
- _ => { }
2107
- }
2108
- }
2109
- if self . trim_paths . is_some ( ) {
2110
- match (
2111
- features. require ( Feature :: trim_paths ( ) ) ,
2112
- cli_unstable. trim_paths ,
2113
- ) {
2114
- ( Err ( e) , false ) => return Err ( e) ,
2115
- _ => { }
2116
- }
2077
+ /// Validates a profile.
2078
+ ///
2079
+ /// This is a shallow check, which is reused for the profile itself and any overrides.
2080
+ fn validate_profile_layer (
2081
+ profile : & schema:: TomlProfile ,
2082
+ name : & str ,
2083
+ cli_unstable : & CliUnstable ,
2084
+ features : & Features ,
2085
+ ) -> CargoResult < ( ) > {
2086
+ if let Some ( codegen_backend) = & profile. codegen_backend {
2087
+ match (
2088
+ features. require ( Feature :: codegen_backend ( ) ) ,
2089
+ cli_unstable. codegen_backend ,
2090
+ ) {
2091
+ ( Err ( e) , false ) => return Err ( e) ,
2092
+ _ => { }
2117
2093
}
2118
- Ok ( ( ) )
2119
- }
2120
2094
2121
- /// Validation that is specific to an override.
2122
- fn validate_override ( & self , which : & str ) -> CargoResult < ( ) > {
2123
- if self . package . is_some ( ) {
2124
- bail ! ( "package-specific profiles cannot be nested" ) ;
2125
- }
2126
- if self . build_override . is_some ( ) {
2127
- bail ! ( "build-override profiles cannot be nested" ) ;
2128
- }
2129
- if self . panic . is_some ( ) {
2130
- bail ! ( "`panic` may not be specified in a `{}` profile" , which)
2095
+ if codegen_backend. contains ( |c : char | !c. is_ascii_alphanumeric ( ) && c != '_' ) {
2096
+ bail ! (
2097
+ "`profile.{}.codegen-backend` setting of `{}` is not a valid backend name." ,
2098
+ name,
2099
+ codegen_backend,
2100
+ ) ;
2131
2101
}
2132
- if self . lto . is_some ( ) {
2133
- bail ! ( "`lto` may not be specified in a `{}` profile" , which)
2102
+ }
2103
+ if profile. rustflags . is_some ( ) {
2104
+ match (
2105
+ features. require ( Feature :: profile_rustflags ( ) ) ,
2106
+ cli_unstable. profile_rustflags ,
2107
+ ) {
2108
+ ( Err ( e) , false ) => return Err ( e) ,
2109
+ _ => { }
2134
2110
}
2135
- if self . rpath . is_some ( ) {
2136
- bail ! ( "`rpath` may not be specified in a `{}` profile" , which)
2111
+ }
2112
+ if profile. trim_paths . is_some ( ) {
2113
+ match (
2114
+ features. require ( Feature :: trim_paths ( ) ) ,
2115
+ cli_unstable. trim_paths ,
2116
+ ) {
2117
+ ( Err ( e) , false ) => return Err ( e) ,
2118
+ _ => { }
2137
2119
}
2138
- Ok ( ( ) )
2139
2120
}
2121
+ Ok ( ( ) )
2122
+ }
2140
2123
2124
+ /// Validation that is specific to an override.
2125
+ fn validate_profile_override ( profile : & schema:: TomlProfile , which : & str ) -> CargoResult < ( ) > {
2126
+ if profile. package . is_some ( ) {
2127
+ bail ! ( "package-specific profiles cannot be nested" ) ;
2128
+ }
2129
+ if profile. build_override . is_some ( ) {
2130
+ bail ! ( "build-override profiles cannot be nested" ) ;
2131
+ }
2132
+ if profile. panic . is_some ( ) {
2133
+ bail ! ( "`panic` may not be specified in a `{}` profile" , which)
2134
+ }
2135
+ if profile. lto . is_some ( ) {
2136
+ bail ! ( "`lto` may not be specified in a `{}` profile" , which)
2137
+ }
2138
+ if profile. rpath . is_some ( ) {
2139
+ bail ! ( "`rpath` may not be specified in a `{}` profile" , which)
2140
+ }
2141
+ Ok ( ( ) )
2142
+ }
2143
+
2144
+ impl schema:: TomlProfile {
2141
2145
/// Overwrite self's values with the given profile.
2142
2146
pub fn merge ( & mut self , profile : & schema:: TomlProfile ) {
2143
2147
if let Some ( v) = & profile. opt_level {
0 commit comments