Skip to content

Commit

Permalink
Have Edition know what its default resolver behaviour is
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemo157 committed Aug 9, 2022
1 parent e6827ee commit df0c64e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
9 changes: 9 additions & 0 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ use anyhow::{bail, Error};
use cargo_util::ProcessBuilder;
use serde::{Deserialize, Serialize};

use crate::core::resolver::ResolveBehavior;
use crate::util::errors::CargoResult;
use crate::util::{indented_lines, iter_join};
use crate::Config;
Expand Down Expand Up @@ -242,6 +243,14 @@ impl Edition {
Edition2021 => false,
}
}

pub(crate) fn default_resolve_behavior(&self) -> ResolveBehavior {
if *self >= Edition::Edition2021 {
ResolveBehavior::V2
} else {
ResolveBehavior::V1
}
}
}

impl fmt::Display for Edition {
Expand Down
16 changes: 6 additions & 10 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::core::features::Features;
use crate::core::registry::PackageRegistry;
use crate::core::resolver::features::CliFeatures;
use crate::core::resolver::ResolveBehavior;
use crate::core::{Dependency, Edition, FeatureValue, PackageId, PackageIdSpec};
use crate::core::{Dependency, FeatureValue, PackageId, PackageIdSpec};
use crate::core::{EitherManifest, Package, SourceId, VirtualManifest};
use crate::ops;
use crate::sources::{PathSource, CRATES_IO_INDEX, CRATES_IO_REGISTRY};
Expand Down Expand Up @@ -287,16 +287,12 @@ impl<'cfg> Workspace<'cfg> {
// - If the root package specifies edition 2021, use v2.
// - Otherwise, use the default v1.
self.resolve_behavior = match self.root_maybe() {
MaybePackage::Package(p) => p.manifest().resolve_behavior().or_else(|| {
if p.manifest().edition() >= Edition::Edition2021 {
Some(ResolveBehavior::V2)
} else {
None
}
}),
MaybePackage::Virtual(vm) => vm.resolve_behavior(),
MaybePackage::Package(p) => p
.manifest()
.resolve_behavior()
.unwrap_or_else(|| p.manifest().edition().default_resolve_behavior()),
MaybePackage::Virtual(vm) => vm.resolve_behavior().unwrap_or(ResolveBehavior::V1),
}
.unwrap_or(ResolveBehavior::V1);
}

/// Returns the current package of this workspace.
Expand Down

0 comments on commit df0c64e

Please sign in to comment.