Skip to content

Commit e79ba78

Browse files
committed
Auto merge of #9927 - weiznich:diesel_2021_edition, r=ehuss
Change diesel compatibility messages Diesel 1.4.8 fixes the critical behaviour. This commit changes the corresponding messages for `cargo fix` and normal builds to prompt the user to just update the diesel version to fix the corresponding compilation errors. As discussed in rust-lang/rust#88903 (comment) Fixes rust-lang/rust#88903 Fixes #9450
2 parents 4bfcf56 + dd03e40 commit e79ba78

File tree

2 files changed

+22
-45
lines changed

2 files changed

+22
-45
lines changed

src/cargo/core/compiler/job_queue.rs

+9-37
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ use cargo_util::ProcessBuilder;
6262
use crossbeam_utils::thread::Scope;
6363
use jobserver::{Acquired, Client, HelperThread};
6464
use log::{debug, info, trace};
65+
use semver::Version;
6566

6667
use super::context::OutputFile;
6768
use super::job::{
@@ -74,9 +75,8 @@ use crate::core::compiler::future_incompat::{
7475
FutureBreakageItem, FutureIncompatReportPackage, OnDiskReports,
7576
};
7677
use crate::core::resolver::ResolveBehavior;
77-
use crate::core::{FeatureValue, PackageId, Shell, TargetKind};
78+
use crate::core::{PackageId, Shell, TargetKind};
7879
use crate::util::diagnostic_server::{self, DiagnosticPrinter};
79-
use crate::util::interning::InternedString;
8080
use crate::util::machine_message::{self, Message as _};
8181
use crate::util::CargoResult;
8282
use crate::util::{self, internal, profile};
@@ -1249,55 +1249,27 @@ impl<'cfg> DrainState<'cfg> {
12491249

12501250
fn back_compat_notice(&self, cx: &Context<'_, '_>, unit: &Unit) -> CargoResult<()> {
12511251
if unit.pkg.name() != "diesel"
1252-
|| unit.pkg.version().major != 1
1252+
|| unit.pkg.version() >= &Version::new(1, 4, 8)
12531253
|| cx.bcx.ws.resolve_behavior() == ResolveBehavior::V1
12541254
|| !unit.pkg.package_id().source_id().is_registry()
12551255
|| !unit.features.is_empty()
12561256
{
12571257
return Ok(());
12581258
}
1259-
let other_diesel = match cx
1259+
if !cx
12601260
.bcx
12611261
.unit_graph
12621262
.keys()
1263-
.find(|unit| unit.pkg.name() == "diesel" && !unit.features.is_empty())
1263+
.any(|unit| unit.pkg.name() == "diesel" && !unit.features.is_empty())
12641264
{
1265-
Some(u) => u,
1266-
// Unlikely due to features.
1267-
None => return Ok(()),
1268-
};
1269-
let mut features_suggestion: BTreeSet<_> = other_diesel.features.iter().collect();
1270-
let fmap = other_diesel.pkg.summary().features();
1271-
// Remove any unnecessary features.
1272-
for feature in &other_diesel.features {
1273-
if let Some(feats) = fmap.get(feature) {
1274-
for feat in feats {
1275-
if let FeatureValue::Feature(f) = feat {
1276-
features_suggestion.remove(&f);
1277-
}
1278-
}
1279-
}
1265+
return Ok(());
12801266
}
1281-
features_suggestion.remove(&InternedString::new("default"));
1282-
let features_suggestion = toml::to_string(&features_suggestion).unwrap();
1283-
1284-
cx.bcx.config.shell().note(&format!(
1267+
cx.bcx.config.shell().note(
12851268
"\
12861269
This error may be due to an interaction between diesel and Cargo's new
1287-
feature resolver. Some workarounds you may want to consider:
1288-
- Add a build-dependency in Cargo.toml on diesel to force Cargo to add the appropriate
1289-
features. This may look something like this:
1290-
1291-
[build-dependencies]
1292-
diesel = {{ version = \"{}\", features = {} }}
1293-
1294-
- Try using the previous resolver by setting `resolver = \"1\"` in `Cargo.toml`
1295-
(see <https://doc.rust-lang.org/cargo/reference/resolver.html#resolver-versions>
1296-
for more information).
1270+
feature resolver. Try updating to diesel 1.4.8 to fix this error.
12971271
",
1298-
unit.pkg.version(),
1299-
features_suggestion
1300-
))?;
1272+
)?;
13011273
Ok(())
13021274
}
13031275
}

src/cargo/ops/fix.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ use cargo_util::{exit_status_to_string, is_simple_exit_code, paths, ProcessBuild
5050
use log::{debug, trace, warn};
5151
use rustfix::diagnostics::Diagnostic;
5252
use rustfix::{self, CodeFix};
53+
use semver::Version;
5354

5455
use crate::core::compiler::{CompileKind, RustcTargetData, TargetInfo};
5556
use crate::core::resolver::features::{DiffMap, FeatureOpts, FeatureResolver};
5657
use crate::core::resolver::{HasDevUnits, Resolve, ResolveBehavior};
57-
use crate::core::{Edition, MaybePackage, Workspace};
58+
use crate::core::{Edition, MaybePackage, PackageId, Workspace};
5859
use crate::ops::resolve::WorkspaceResolve;
5960
use crate::ops::{self, CompileOptions};
6061
use crate::util::diagnostic_server::{Message, RustfixDiagnosticServer};
@@ -321,17 +322,21 @@ fn check_resolver_change(ws: &Workspace<'_>, opts: &FixOptions) -> CargoResult<(
321322
}
322323

323324
fn report_maybe_diesel(config: &Config, resolve: &Resolve) -> CargoResult<()> {
324-
if resolve
325-
.iter()
326-
.any(|pid| pid.name() == "diesel" && pid.version().major == 1)
327-
&& resolve.iter().any(|pid| pid.name() == "diesel_migrations")
328-
{
325+
fn is_broken_diesel(pid: PackageId) -> bool {
326+
pid.name() == "diesel" && pid.version() < &Version::new(1, 4, 8)
327+
}
328+
329+
fn is_broken_diesel_migration(pid: PackageId) -> bool {
330+
pid.name() == "diesel_migrations" && pid.version().major <= 1
331+
}
332+
333+
if resolve.iter().any(is_broken_diesel) && resolve.iter().any(is_broken_diesel_migration) {
329334
config.shell().note(
330335
"\
331336
This project appears to use both diesel and diesel_migrations. These packages have
332337
a known issue where the build may fail due to the version 2 resolver preventing
333-
feature unification between those two packages. See
334-
<https://github.com/rust-lang/cargo/issues/9450> for some potential workarounds.
338+
feature unification between those two packages. Please update to at least diesel 1.4.8
339+
to prevent this issue from happening.
335340
",
336341
)?;
337342
}

0 commit comments

Comments
 (0)