Skip to content

Commit 6d221ef

Browse files
authored
fix(future): Report all content as a single Report (#15943)
### What does this PR try to resolve? This changes the future-incompat message to be reported in a single `Report`. The primary motivation is to cleanup the output compared to taking the existing note's and aligning all content with the first line which is what would happen otherwise in #15917. In preparation for this, the message was cleaned up and made more like what a rustc message might look like. ### How to test and review this PR?
2 parents 7f8ed80 + 2c5b4df commit 6d221ef

File tree

2 files changed

+134
-174
lines changed

2 files changed

+134
-174
lines changed

src/cargo/core/compiler/future_incompat.rs

Lines changed: 64 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,10 @@ fn get_updates(ws: &Workspace<'_>, package_ids: &BTreeSet<PackageId>) -> Option<
359359

360360
if !updated_versions.is_empty() {
361361
let updated_versions = itertools::join(updated_versions, ", ");
362-
writeln!(
362+
write!(
363363
updates,
364-
"{} has the following newer versions available: {}",
364+
"
365+
- {} has the following newer versions available: {}",
365366
pkg_id, updated_versions
366367
)
367368
.unwrap();
@@ -428,23 +429,12 @@ pub fn save_and_display_report(
428429
.collect();
429430
let package_vers: Vec<_> = package_ids.iter().map(|pid| pid.to_string()).collect();
430431

431-
if should_display_message || bcx.build_config.future_incompat_report {
432-
drop(bcx.gctx.shell().warn(&format!(
433-
"the following packages contain code that will be rejected by a future \
434-
version of Rust: {}",
435-
package_vers.join(", ")
436-
)));
437-
}
438-
439432
let updated_versions = get_updates(bcx.ws, &package_ids).unwrap_or(String::new());
440433

441434
let update_message = if !updated_versions.is_empty() {
442435
format!(
443-
"
444-
- Some affected dependencies have newer versions available.
445-
You may want to consider updating them to a newer version to see if the issue has been fixed.
446-
447-
{updated_versions}\n",
436+
"\
437+
update to a newer version to see if the issue has been fixed{updated_versions}",
448438
updated_versions = updated_versions
449439
)
450440
} else {
@@ -456,10 +446,9 @@ You may want to consider updating them to a newer version to see if the issue ha
456446
.map(|package_id| {
457447
let manifest = bcx.packages.get_one(*package_id).unwrap().manifest();
458448
format!(
459-
"
460-
- {package_spec}
461-
- Repository: {url}
462-
- Detailed warning command: `cargo report future-incompatibilities --id {id} --package {package_spec}`",
449+
" - {package_spec}
450+
- repository: {url}
451+
- detailed warning command: `cargo report future-incompatibilities --id {id} --package {package_spec}`",
463452
package_spec = format!("{}@{}", package_id.name(), package_id.version()),
464453
url = manifest
465454
.metadata()
@@ -470,54 +459,75 @@ You may want to consider updating them to a newer version to see if the issue ha
470459
)
471460
})
472461
.collect::<Vec<_>>()
473-
.join("\n");
462+
.join("\n\n");
474463

475464
let all_is_local = per_package_future_incompat_reports
476465
.iter()
477466
.all(|report| report.is_local);
478467

479-
let suggestion_message = if all_is_local {
468+
let suggestion_header = "to solve this problem, you can try the following approaches:";
469+
let mut suggestions = Vec::new();
470+
if !all_is_local {
471+
if !update_message.is_empty() {
472+
suggestions.push(update_message);
473+
}
474+
suggestions.push(format!(
475+
"\
476+
ensure the maintainers know of this problem (e.g. creating a bug report if needed)
477+
or even helping with a fix (e.g. by creating a pull request)
478+
{upstream_info}"
479+
));
480+
suggestions.push(
481+
"\
482+
use your own version of the dependency with the `[patch]` section in `Cargo.toml`
483+
For more information, see:
484+
https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section"
485+
.to_owned(),
486+
);
487+
}
488+
489+
let suggestion_message = if suggestions.is_empty() {
480490
String::new()
481491
} else {
482-
format!(
483-
"
484-
To solve this problem, you can try the following approaches:
485-
486-
{update_message}\
487-
- If the issue is not solved by updating the dependencies, a fix has to be
488-
implemented by those dependencies. You can help with that by notifying the
489-
maintainers of this problem (e.g. by creating a bug report) or by proposing a
490-
fix to the maintainers (e.g. by creating a pull request):
491-
{upstream_info}
492-
493-
- If waiting for an upstream fix is not an option, you can use the `[patch]`
494-
section in `Cargo.toml` to use your own version of the dependency. For more
495-
information, see:
496-
https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section
497-
",
498-
upstream_info = upstream_info,
499-
update_message = update_message,
500-
)
492+
let mut suggestion_message = String::new();
493+
writeln!(&mut suggestion_message, "{suggestion_header}").unwrap();
494+
for suggestion in &suggestions {
495+
writeln!(
496+
&mut suggestion_message,
497+
"
498+
- {suggestion}"
499+
)
500+
.unwrap();
501+
}
502+
suggestion_message
501503
};
502-
503504
let saved_report_id =
504505
current_reports.save_report(bcx.ws, suggestion_message.clone(), rendered_report);
505506

506-
if bcx.build_config.future_incompat_report {
507-
if !suggestion_message.is_empty() {
508-
drop(bcx.gctx.shell().note(&suggestion_message));
509-
}
510-
drop(bcx.gctx.shell().note(&format!(
511-
"this report can be shown with `cargo report \
507+
if should_display_message || bcx.build_config.future_incompat_report {
508+
use annotate_snippets::*;
509+
let mut report = vec![Group::with_title(Level::WARNING.secondary_title(format!(
510+
"the following packages contain code that will be rejected by a future \
511+
version of Rust: {}",
512+
package_vers.join(", ")
513+
)))];
514+
if bcx.build_config.future_incompat_report {
515+
for suggestion in &suggestions {
516+
report.push(Group::with_title(Level::HELP.secondary_title(suggestion)));
517+
}
518+
report.push(Group::with_title(Level::NOTE.secondary_title(format!(
519+
"this report can be shown with `cargo report \
512520
future-incompatibilities --id {}`",
513-
saved_report_id
514-
)));
515-
} else if should_display_message {
516-
drop(bcx.gctx.shell().note(&format!(
517-
"to see what the problems were, use the option \
521+
saved_report_id
522+
))));
523+
} else if should_display_message {
524+
report.push(Group::with_title(Level::NOTE.secondary_title(format!(
525+
"to see what the problems were, use the option \
518526
`--future-incompat-report`, or run `cargo report \
519527
future-incompatibilities --id {}`",
520-
saved_report_id
521-
)));
528+
saved_report_id
529+
))));
530+
}
531+
drop(bcx.gctx.shell().print_report(&report, false))
522532
}
523533
}

0 commit comments

Comments
 (0)