Skip to content

Commit

Permalink
Auto merge of #10434 - weihanglo:stop-gating-stable-features, r=alexc…
Browse files Browse the repository at this point in the history
…richton

Stop gating stable features
  • Loading branch information
bors committed Feb 28, 2022
2 parents 3d6970d + 4947f09 commit 489b66f
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 201 deletions.
1 change: 0 additions & 1 deletion src/cargo/core/compiler/standard_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ pub fn generate_std_roots(
/*is_member*/ false,
/*is_local*/ false,
unit_for,
mode,
*kind,
);
list.push(interner.intern(
Expand Down
1 change: 0 additions & 1 deletion src/cargo/core/compiler/unit_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,6 @@ fn new_unit_dep(
state.ws.is_member(pkg),
is_local,
unit_for,
mode,
kind,
);
new_unit_dep_with_profile(
Expand Down
136 changes: 4 additions & 132 deletions src/cargo/core/profiles.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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<InternedString, TomlProfile>,
/// 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`.
Expand All @@ -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(),
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,6 @@ fn generate_targets(
ws.is_member(pkg),
is_local,
unit_for,
target_mode,
*kind,
);
let unit = interner.intern(
Expand Down
44 changes: 7 additions & 37 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,34 +496,19 @@ 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)?;
}
}

// 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
Expand Down Expand Up @@ -1146,18 +1131,19 @@ 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")?
} 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",
Expand Down Expand Up @@ -1193,14 +1179,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()),
Expand Down Expand Up @@ -1540,13 +1518,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()
Expand Down Expand Up @@ -1959,7 +1930,6 @@ impl<P: ResolveToPath> DetailedTomlDependency<P> {
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);
}

Expand Down
Loading

0 comments on commit 489b66f

Please sign in to comment.