Skip to content

Commit 09374c5

Browse files
committed
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 promt the user to just update the diesel version to fix the corresponding compilation errors.
1 parent 9a28ac8 commit 09374c5

File tree

2 files changed

+45
-45
lines changed

2 files changed

+45
-45
lines changed

src/cargo/core/compiler/job_queue.rs

+22-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};
@@ -1248,56 +1248,41 @@ impl<'cfg> DrainState<'cfg> {
12481248
}
12491249

12501250
fn back_compat_notice(&self, cx: &Context<'_, '_>, unit: &Unit) -> CargoResult<()> {
1251+
fn is_broken_diesel(version: &Version) -> bool {
1252+
use semver::{Comparator, Op, Prerelease};
1253+
1254+
Comparator {
1255+
op: Op::Less,
1256+
major: 1,
1257+
minor: Some(4),
1258+
patch: Some(8),
1259+
pre: Prerelease::EMPTY,
1260+
}
1261+
.matches(version)
1262+
}
1263+
12511264
if unit.pkg.name() != "diesel"
1252-
|| unit.pkg.version().major != 1
1265+
|| !is_broken_diesel(unit.pkg.version())
12531266
|| cx.bcx.ws.resolve_behavior() == ResolveBehavior::V1
12541267
|| !unit.pkg.package_id().source_id().is_registry()
12551268
|| !unit.features.is_empty()
12561269
{
12571270
return Ok(());
12581271
}
1259-
let other_diesel = match cx
1272+
if !cx
12601273
.bcx
12611274
.unit_graph
12621275
.keys()
1263-
.find(|unit| unit.pkg.name() == "diesel" && !unit.features.is_empty())
1276+
.any(|unit| unit.pkg.name() == "diesel" && !unit.features.is_empty())
12641277
{
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-
}
1278+
return Ok(());
12801279
}
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!(
1280+
cx.bcx.config.shell().note(
12851281
"\
12861282
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).
1283+
feature resolver. Try updating to diesel 1.4.8 to fix this error.
12971284
",
1298-
unit.pkg.version(),
1299-
features_suggestion
1300-
))?;
1285+
)?;
13011286
Ok(())
13021287
}
13031288
}

src/cargo/ops/fix.rs

+23-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::{Comparator, Op, Prerelease};
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,31 @@ 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+
if pid.name() != "diesel" {
327+
return false;
328+
}
329+
Comparator {
330+
op: Op::Less,
331+
major: 1,
332+
minor: Some(4),
333+
patch: Some(8),
334+
pre: Prerelease::EMPTY,
335+
}
336+
.matches(pid.version())
337+
}
338+
339+
fn is_broken_diesel_migration(pid: PackageId) -> bool {
340+
pid.name() == "diesel_migrations" && pid.version().major <= 1
341+
}
342+
343+
if resolve.iter().any(is_broken_diesel) && resolve.iter().any(is_broken_diesel_migration) {
329344
config.shell().note(
330345
"\
331346
This project appears to use both diesel and diesel_migrations. These packages have
332347
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.
348+
feature unification between those two packages. Please update to at least diesel 1.4.8
349+
to prevent this issue from happening.
335350
",
336351
)?;
337352
}

0 commit comments

Comments
 (0)