From cd97322c122bd610d1b974e711cabc80c672eab2 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Mon, 28 Feb 2022 22:50:45 +0800 Subject: [PATCH 1/6] Stop gating feature "edition" --- src/cargo/util/toml/mod.rs | 3 --- src/cargo/util/toml/targets.rs | 23 ++++++----------------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 85eb64ede96..8f4d38499e2 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -1146,9 +1146,6 @@ impl TomlManifest { let pkgid = project.to_package_id(source_id)?; let edition = if let Some(ref edition) = project.edition { - features - .require(Feature::edition()) - .with_context(|| "editions are unstable")?; edition .parse() .with_context(|| "failed to parse the `edition` key")? diff --git a/src/cargo/util/toml/targets.rs b/src/cargo/util/toml/targets.rs index af98bc7469d..c82e958a237 100644 --- a/src/cargo/util/toml/targets.rs +++ b/src/cargo/util/toml/targets.rs @@ -46,7 +46,6 @@ pub fn targets( let has_lib; if let Some(target) = clean_lib( - features, manifest.lib.as_ref(), package_root, package_name, @@ -78,7 +77,6 @@ pub fn targets( )?); targets.extend(clean_examples( - features, manifest.example.as_ref(), package_root, edition, @@ -88,7 +86,6 @@ pub fn targets( )?); targets.extend(clean_tests( - features, manifest.test.as_ref(), package_root, edition, @@ -98,7 +95,6 @@ pub fn targets( )?); targets.extend(clean_benches( - features, manifest.bench.as_ref(), package_root, edition, @@ -147,7 +143,6 @@ pub fn targets( } fn clean_lib( - features: &Features, toml_lib: Option<&TomlLibTarget>, package_root: &Path, package_name: &str, @@ -251,7 +246,7 @@ fn clean_lib( }; let mut target = Target::lib_target(&lib.name(), crate_types, path, edition); - configure(features, lib, &mut target)?; + configure(lib, &mut target)?; Ok(Some(target)) } @@ -350,7 +345,7 @@ fn clean_bins( edition, ); - configure(features, bin, &mut target)?; + configure(bin, &mut target)?; result.push(target); } return Ok(result); @@ -379,7 +374,6 @@ fn clean_bins( } fn clean_examples( - features: &Features, toml_examples: Option<&Vec>, package_root: &Path, edition: Edition, @@ -416,7 +410,7 @@ fn clean_examples( toml.required_features.clone(), edition, ); - configure(features, &toml, &mut target)?; + configure(&toml, &mut target)?; result.push(target); } @@ -424,7 +418,6 @@ fn clean_examples( } fn clean_tests( - features: &Features, toml_tests: Option<&Vec>, package_root: &Path, edition: Edition, @@ -451,14 +444,13 @@ fn clean_tests( for (path, toml) in targets { let mut target = Target::test_target(&toml.name(), path, toml.required_features.clone(), edition); - configure(features, &toml, &mut target)?; + configure(&toml, &mut target)?; result.push(target); } Ok(result) } fn clean_benches( - features: &Features, toml_benches: Option<&Vec>, package_root: &Path, edition: Edition, @@ -506,7 +498,7 @@ fn clean_benches( for (path, toml) in targets { let mut target = Target::bench_target(&toml.name(), path, toml.required_features.clone(), edition); - configure(features, &toml, &mut target)?; + configure(&toml, &mut target)?; result.push(target); } @@ -804,7 +796,7 @@ fn validate_unique_names(targets: &[TomlTarget], target_kind: &str) -> CargoResu Ok(()) } -fn configure(features: &Features, toml: &TomlTarget, target: &mut Target) -> CargoResult<()> { +fn configure(toml: &TomlTarget, target: &mut Target) -> CargoResult<()> { let t2 = target.clone(); target .set_tested(toml.test.unwrap_or_else(|| t2.tested())) @@ -819,9 +811,6 @@ fn configure(features: &Features, toml: &TomlTarget, target: &mut Target) -> Car (Some(false), _) | (_, Some(false)) => false, }); if let Some(edition) = toml.edition.clone() { - features - .require(Feature::edition()) - .with_context(|| "editions are unstable")?; target.set_edition( edition .parse() From a1c8518b56b552f40ebb4ae70b3a211c58d5a57b Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Mon, 28 Feb 2022 22:56:21 +0800 Subject: [PATCH 2/6] Stop gating feature "rename-dependency" --- src/cargo/util/toml/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 8f4d38499e2..9187649765d 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -1956,7 +1956,6 @@ impl DetailedTomlDependency

{ dep.set_kind(kind); } if let Some(name_in_toml) = explicit_name_in_toml { - cx.features.require(Feature::rename_dependency())?; dep.set_explicit_name_in_toml(name_in_toml); } From 1ea39565708f84f6c9f38b7608117dd95a7921a2 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Mon, 28 Feb 2022 22:59:11 +0800 Subject: [PATCH 3/6] Stop gating feature "profile-overrides" --- src/cargo/util/toml/mod.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 9187649765d..b193e6f874d 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -496,12 +496,10 @@ impl TomlProfile { ) -> CargoResult<()> { self.validate_profile(name, features)?; if let Some(ref profile) = self.build_override { - features.require(Feature::profile_overrides())?; profile.validate_override("build-override")?; profile.validate_profile(&format!("{name}.build-override"), features)?; } if let Some(ref packages) = self.package { - features.require(Feature::profile_overrides())?; for (override_name, profile) in packages { profile.validate_override("package")?; profile.validate_profile(&format!("{name}.package.{override_name}"), features)?; From 555209ce0660dcf0b64eb7c92f3e32418ce21c86 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Mon, 28 Feb 2022 23:15:21 +0800 Subject: [PATCH 4/6] Stop gating feature "named-profiles" --- src/cargo/core/compiler/standard_lib.rs | 1 - src/cargo/core/compiler/unit_dependencies.rs | 1 - src/cargo/core/profiles.rs | 136 +------------------ src/cargo/ops/cargo_compile.rs | 1 - src/cargo/util/toml/mod.rs | 13 -- tests/testsuite/profile_config.rs | 16 +-- 6 files changed, 8 insertions(+), 160 deletions(-) diff --git a/src/cargo/core/compiler/standard_lib.rs b/src/cargo/core/compiler/standard_lib.rs index 94242fdb8fd..e556fe9d566 100644 --- a/src/cargo/core/compiler/standard_lib.rs +++ b/src/cargo/core/compiler/standard_lib.rs @@ -169,7 +169,6 @@ pub fn generate_std_roots( /*is_member*/ false, /*is_local*/ false, unit_for, - mode, *kind, ); list.push(interner.intern( diff --git a/src/cargo/core/compiler/unit_dependencies.rs b/src/cargo/core/compiler/unit_dependencies.rs index 857436e9f90..932c91a2275 100644 --- a/src/cargo/core/compiler/unit_dependencies.rs +++ b/src/cargo/core/compiler/unit_dependencies.rs @@ -861,7 +861,6 @@ fn new_unit_dep( state.ws.is_member(pkg), is_local, unit_for, - mode, kind, ); new_unit_dep_with_profile( diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index bb354abdc82..e6415daff7f 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -1,7 +1,7 @@ -use crate::core::compiler::{CompileKind, CompileMode, CompileTarget, Unit}; +use crate::core::compiler::{CompileKind, CompileTarget, Unit}; use crate::core::dependency::Artifact; use crate::core::resolver::features::FeaturesFor; -use crate::core::{Feature, PackageId, PackageIdSpec, Resolve, Shell, Target, Workspace}; +use crate::core::{PackageId, PackageIdSpec, Resolve, Shell, Target, Workspace}; use crate::util::interning::InternedString; use crate::util::toml::{ProfilePackageSpec, StringOrBool, TomlProfile, TomlProfiles, U32OrBool}; use crate::util::{closest_msg, config, CargoResult, Config}; @@ -26,8 +26,6 @@ pub struct Profiles { /// This is here to assist with error reporting, as the `ProfileMaker` /// values have the inherits chains all merged together. original_profiles: BTreeMap, - /// Whether or not unstable "named" profiles are enabled. - named_profiles_enabled: bool, /// The profile the user requested to use. requested_profile: InternedString, /// The host target for rustc being used by this `Profiles`. @@ -44,64 +42,8 @@ impl Profiles { let mut profiles = merge_config_profiles(ws, requested_profile)?; let rustc_host = ws.config().load_global_rustc(Some(ws))?.host; - if !ws.unstable_features().is_enabled(Feature::named_profiles()) { - let mut profile_makers = Profiles { - incremental, - named_profiles_enabled: false, - dir_names: Self::predefined_dir_names(), - by_name: HashMap::new(), - original_profiles: profiles.clone(), - requested_profile, - rustc_host, - }; - - profile_makers.by_name.insert( - InternedString::new("dev"), - ProfileMaker::new(Profile::default_dev(), profiles.remove("dev")), - ); - profile_makers - .dir_names - .insert(InternedString::new("dev"), InternedString::new("debug")); - - profile_makers.by_name.insert( - InternedString::new("release"), - ProfileMaker::new(Profile::default_release(), profiles.remove("release")), - ); - profile_makers.dir_names.insert( - InternedString::new("release"), - InternedString::new("release"), - ); - - profile_makers.by_name.insert( - InternedString::new("test"), - ProfileMaker::new(Profile::default_test(), profiles.remove("test")), - ); - profile_makers - .dir_names - .insert(InternedString::new("test"), InternedString::new("debug")); - - profile_makers.by_name.insert( - InternedString::new("bench"), - ProfileMaker::new(Profile::default_bench(), profiles.remove("bench")), - ); - profile_makers - .dir_names - .insert(InternedString::new("bench"), InternedString::new("release")); - - profile_makers.by_name.insert( - InternedString::new("doc"), - ProfileMaker::new(Profile::default_doc(), profiles.remove("doc")), - ); - profile_makers - .dir_names - .insert(InternedString::new("doc"), InternedString::new("debug")); - - return Ok(profile_makers); - } - let mut profile_makers = Profiles { incremental, - named_profiles_enabled: true, dir_names: Self::predefined_dir_names(), by_name: HashMap::new(), original_profiles: profiles.clone(), @@ -290,48 +232,9 @@ impl Profiles { is_member: bool, is_local: bool, unit_for: UnitFor, - mode: CompileMode, kind: CompileKind, ) -> Profile { - let (profile_name, inherits) = if !self.named_profiles_enabled { - // With the feature disabled, we degrade `--profile` back to the - // `--release` and `--debug` predicates, and convert back from - // ProfileKind::Custom instantiation. - - let release = matches!(self.requested_profile.as_str(), "release" | "bench"); - - match mode { - CompileMode::Test | CompileMode::Bench | CompileMode::Doctest => { - if release { - ( - InternedString::new("bench"), - Some(InternedString::new("release")), - ) - } else { - ( - InternedString::new("test"), - Some(InternedString::new("dev")), - ) - } - } - CompileMode::Build | CompileMode::Check { .. } | CompileMode::RunCustomBuild => { - // Note: `RunCustomBuild` doesn't normally use this code path. - // `build_unit_profiles` normally ensures that it selects the - // ancestor's profile. However, `cargo clean -p` can hit this - // path. - if release { - (InternedString::new("release"), None) - } else { - (InternedString::new("dev"), None) - } - } - CompileMode::Doc { .. } | CompileMode::Docscrape => { - (InternedString::new("doc"), None) - } - } - } else { - (self.requested_profile, None) - }; + let (profile_name, inherits) = (self.requested_profile, None); let maker = self.get_profile_maker(profile_name).unwrap(); let mut profile = maker.get_profile(Some(pkg_id), is_member, unit_for.is_for_host()); @@ -404,15 +307,7 @@ impl Profiles { /// `[Finished]` line. It is not entirely accurate, since it doesn't /// select for the package that was actually built. pub fn base_profile(&self) -> Profile { - let profile_name = if !self.named_profiles_enabled { - match self.requested_profile.as_str() { - "release" | "bench" => self.requested_profile, - _ => InternedString::new("dev"), - } - } else { - self.requested_profile - }; - + let profile_name = self.requested_profile; let maker = self.get_profile_maker(profile_name).unwrap(); maker.get_profile(None, /*is_member*/ true, /*is_for_host*/ false) } @@ -772,29 +667,6 @@ impl Profile { } } - // NOTE: Remove the following three once `named_profiles` is default: - - fn default_test() -> Profile { - Profile { - name: InternedString::new("test"), - ..Profile::default_dev() - } - } - - fn default_bench() -> Profile { - Profile { - name: InternedString::new("bench"), - ..Profile::default_release() - } - } - - fn default_doc() -> Profile { - Profile { - name: InternedString::new("doc"), - ..Profile::default_dev() - } - } - /// Compares all fields except `name`, which doesn't affect compilation. /// This is necessary for `Unit` deduplication for things like "test" and /// "dev" which are essentially the same. diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 0dd03da81ee..51f104ca1fe 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -1068,7 +1068,6 @@ fn generate_targets( ws.is_member(pkg), is_local, unit_for, - target_mode, *kind, ); let unit = interner.intern( diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index b193e6f874d..e8b8ba34a84 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -506,22 +506,9 @@ impl TomlProfile { } } - // Feature gate definition of named profiles - match name { - "dev" | "release" | "bench" | "test" | "doc" => {} - _ => { - features.require(Feature::named_profiles())?; - } - } - // Profile name validation Self::validate_name(name)?; - // Feature gate on uses of keys related to named profiles - if self.inherits.is_some() { - features.require(Feature::named_profiles())?; - } - if let Some(dir_name) = self.dir_name { // This is disabled for now, as we would like to stabilize named // profiles without this, and then decide in the future if it is diff --git a/tests/testsuite/profile_config.rs b/tests/testsuite/profile_config.rs index 038d6d40d92..93e76d4c0c1 100644 --- a/tests/testsuite/profile_config.rs +++ b/tests/testsuite/profile_config.rs @@ -312,7 +312,7 @@ fn named_config_profile() { // foo -> middle -> bar -> dev // middle exists in Cargo.toml, the others in .cargo/config use super::config::ConfigBuilder; - use cargo::core::compiler::{CompileKind, CompileMode}; + use cargo::core::compiler::CompileKind; use cargo::core::profiles::{Profiles, UnitFor}; use cargo::core::{PackageId, Workspace}; use cargo::util::interning::InternedString; @@ -370,9 +370,8 @@ fn named_config_profile() { let dep_pkg = PackageId::new("dep", "0.1.0", crates_io).unwrap(); // normal package - let mode = CompileMode::Build; let kind = CompileKind::Host; - let p = profiles.get_profile(a_pkg, true, true, UnitFor::new_normal(kind), mode, kind); + let p = profiles.get_profile(a_pkg, true, true, UnitFor::new_normal(kind), kind); assert_eq!(p.name, "foo"); assert_eq!(p.codegen_units, Some(2)); // "foo" from config assert_eq!(p.opt_level, "1"); // "middle" from manifest @@ -381,14 +380,7 @@ fn named_config_profile() { assert_eq!(p.overflow_checks, true); // "dev" built-in (ignore package override) // build-override - let bo = profiles.get_profile( - a_pkg, - true, - true, - UnitFor::new_host(false, kind), - mode, - kind, - ); + let bo = profiles.get_profile(a_pkg, true, true, UnitFor::new_host(false, kind), kind); assert_eq!(bo.name, "foo"); assert_eq!(bo.codegen_units, Some(6)); // "foo" build override from config assert_eq!(bo.opt_level, "0"); // default to zero @@ -397,7 +389,7 @@ fn named_config_profile() { assert_eq!(bo.overflow_checks, true); // SAME as normal // package overrides - let po = profiles.get_profile(dep_pkg, false, true, UnitFor::new_normal(kind), mode, kind); + let po = profiles.get_profile(dep_pkg, false, true, UnitFor::new_normal(kind), kind); assert_eq!(po.name, "foo"); assert_eq!(po.codegen_units, Some(7)); // "foo" package override from config assert_eq!(po.opt_level, "1"); // SAME as normal From 74f20d25e2ede60b515dc2db6ee333c7fe8ab83b Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Mon, 28 Feb 2022 23:25:21 +0800 Subject: [PATCH 5/6] Stop gating feature "resolver" --- src/cargo/util/toml/mod.rs | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index e8b8ba34a84..c802d3d6a7c 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -1175,14 +1175,6 @@ impl TomlManifest { features.require(Feature::metabuild())?; } - if project.resolver.is_some() - || me - .workspace - .as_ref() - .map_or(false, |ws| ws.resolver.is_some()) - { - features.require(Feature::resolver())?; - } let resolve_behavior = match ( project.resolver.as_ref(), me.workspace.as_ref().and_then(|ws| ws.resolver.as_ref()), @@ -1522,13 +1514,6 @@ impl TomlManifest { if let Some(profiles) = &profiles { profiles.validate(&features, &mut warnings)?; } - if me - .workspace - .as_ref() - .map_or(false, |ws| ws.resolver.is_some()) - { - features.require(Feature::resolver())?; - } let resolve_behavior = me .workspace .as_ref() From 4947f099661811a10911b414870331d1b8798e29 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Mon, 28 Feb 2022 23:33:22 +0800 Subject: [PATCH 6/6] Stop gating feature "edition2021" --- src/cargo/util/toml/mod.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index c802d3d6a7c..69de9be3a2f 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -1137,9 +1137,13 @@ impl TomlManifest { } else { Edition::Edition2015 }; - if edition == Edition::Edition2021 { - features.require(Feature::edition2021())?; - } else if !edition.is_stable() { + // Add these lines if start a new unstable edition. + // ``` + // if edition == Edition::Edition20xx { + // features.require(Feature::edition20xx))?; + // } + // ``` + if !edition.is_stable() { // Guard in case someone forgets to add .require() return Err(util::errors::internal(format!( "edition {} should be gated",