diff --git a/src/cargo/core/compiler/future_incompat.rs b/src/cargo/core/compiler/future_incompat.rs index c7501bd3f0c..0d6d59d5c08 100644 --- a/src/cargo/core/compiler/future_incompat.rs +++ b/src/cargo/core/compiler/future_incompat.rs @@ -359,9 +359,10 @@ fn get_updates(ws: &Workspace<'_>, package_ids: &BTreeSet) -> Option< if !updated_versions.is_empty() { let updated_versions = itertools::join(updated_versions, ", "); - writeln!( + write!( updates, - "{} has the following newer versions available: {}", + " + - {} has the following newer versions available: {}", pkg_id, updated_versions ) .unwrap(); @@ -428,23 +429,12 @@ pub fn save_and_display_report( .collect(); let package_vers: Vec<_> = package_ids.iter().map(|pid| pid.to_string()).collect(); - if should_display_message || bcx.build_config.future_incompat_report { - drop(bcx.gctx.shell().warn(&format!( - "the following packages contain code that will be rejected by a future \ - version of Rust: {}", - package_vers.join(", ") - ))); - } - let updated_versions = get_updates(bcx.ws, &package_ids).unwrap_or(String::new()); let update_message = if !updated_versions.is_empty() { format!( - " -- Some affected dependencies have newer versions available. -You may want to consider updating them to a newer version to see if the issue has been fixed. - -{updated_versions}\n", + "\ +update to a newer version to see if the issue has been fixed{updated_versions}", updated_versions = updated_versions ) } else { @@ -456,10 +446,9 @@ You may want to consider updating them to a newer version to see if the issue ha .map(|package_id| { let manifest = bcx.packages.get_one(*package_id).unwrap().manifest(); format!( - " - - {package_spec} - - Repository: {url} - - Detailed warning command: `cargo report future-incompatibilities --id {id} --package {package_spec}`", + " - {package_spec} + - repository: {url} + - detailed warning command: `cargo report future-incompatibilities --id {id} --package {package_spec}`", package_spec = format!("{}@{}", package_id.name(), package_id.version()), url = manifest .metadata() @@ -470,54 +459,75 @@ You may want to consider updating them to a newer version to see if the issue ha ) }) .collect::>() - .join("\n"); + .join("\n\n"); let all_is_local = per_package_future_incompat_reports .iter() .all(|report| report.is_local); - let suggestion_message = if all_is_local { + let suggestion_header = "to solve this problem, you can try the following approaches:"; + let mut suggestions = Vec::new(); + if !all_is_local { + if !update_message.is_empty() { + suggestions.push(update_message); + } + suggestions.push(format!( + "\ +ensure the maintainers know of this problem (e.g. creating a bug report if needed) +or even helping with a fix (e.g. by creating a pull request) +{upstream_info}" + )); + suggestions.push( + "\ +use your own version of the dependency with the `[patch]` section in `Cargo.toml` +For more information, see: +https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section" + .to_owned(), + ); + } + + let suggestion_message = if suggestions.is_empty() { String::new() } else { - format!( - " -To solve this problem, you can try the following approaches: - -{update_message}\ -- If the issue is not solved by updating the dependencies, a fix has to be -implemented by those dependencies. You can help with that by notifying the -maintainers of this problem (e.g. by creating a bug report) or by proposing a -fix to the maintainers (e.g. by creating a pull request): -{upstream_info} - -- If waiting for an upstream fix is not an option, you can use the `[patch]` -section in `Cargo.toml` to use your own version of the dependency. For more -information, see: -https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section -", - upstream_info = upstream_info, - update_message = update_message, - ) + let mut suggestion_message = String::new(); + writeln!(&mut suggestion_message, "{suggestion_header}").unwrap(); + for suggestion in &suggestions { + writeln!( + &mut suggestion_message, + " +- {suggestion}" + ) + .unwrap(); + } + suggestion_message }; - let saved_report_id = current_reports.save_report(bcx.ws, suggestion_message.clone(), rendered_report); - if bcx.build_config.future_incompat_report { - if !suggestion_message.is_empty() { - drop(bcx.gctx.shell().note(&suggestion_message)); - } - drop(bcx.gctx.shell().note(&format!( - "this report can be shown with `cargo report \ + if should_display_message || bcx.build_config.future_incompat_report { + use annotate_snippets::*; + let mut report = vec![Group::with_title(Level::WARNING.secondary_title(format!( + "the following packages contain code that will be rejected by a future \ + version of Rust: {}", + package_vers.join(", ") + )))]; + if bcx.build_config.future_incompat_report { + for suggestion in &suggestions { + report.push(Group::with_title(Level::HELP.secondary_title(suggestion))); + } + report.push(Group::with_title(Level::NOTE.secondary_title(format!( + "this report can be shown with `cargo report \ future-incompatibilities --id {}`", - saved_report_id - ))); - } else if should_display_message { - drop(bcx.gctx.shell().note(&format!( - "to see what the problems were, use the option \ + saved_report_id + )))); + } else if should_display_message { + report.push(Group::with_title(Level::NOTE.secondary_title(format!( + "to see what the problems were, use the option \ `--future-incompat-report`, or run `cargo report \ future-incompatibilities --id {}`", - saved_report_id - ))); + saved_report_id + )))); + } + drop(bcx.gctx.shell().print_report(&report, false)) } } diff --git a/tests/testsuite/future_incompat_report.rs b/tests/testsuite/future_incompat_report.rs index e60c15c425b..a6de493e460 100644 --- a/tests/testsuite/future_incompat_report.rs +++ b/tests/testsuite/future_incompat_report.rs @@ -146,23 +146,14 @@ fn incompat_in_dependency() { .with_stderr_data(str![[r#" [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s [WARNING] the following packages contain code that will be rejected by a future version of Rust: bar v1.0.0 -[NOTE] -To solve this problem, you can try the following approaches: - -- If the issue is not solved by updating the dependencies, a fix has to be -implemented by those dependencies. You can help with that by notifying the -maintainers of this problem (e.g. by creating a bug report) or by proposing a -fix to the maintainers (e.g. by creating a pull request): - - - bar@1.0.0 - - Repository: https://example.com/ - - Detailed warning command: `cargo report future-incompatibilities --id 1 --package bar@1.0.0` - -- If waiting for an upstream fix is not an option, you can use the `[patch]` -section in `Cargo.toml` to use your own version of the dependency. For more -information, see: -https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section - +[HELP] ensure the maintainers know of this problem (e.g. creating a bug report if needed) + or even helping with a fix (e.g. by creating a pull request) + - bar@1.0.0 + - repository: https://example.com/ + - detailed warning command: `cargo report future-incompatibilities --id 1 --package bar@1.0.0` +[HELP] use your own version of the dependency with the `[patch]` section in `Cargo.toml` + For more information, see: + https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section [NOTE] this report can be shown with `cargo report future-incompatibilities --id 1` "#]]) @@ -180,21 +171,16 @@ to be in wide use. Each warning should contain a link for more information on what the warning means and how to resolve it. +to solve this problem, you can try the following approaches: -To solve this problem, you can try the following approaches: - -- If the issue is not solved by updating the dependencies, a fix has to be -implemented by those dependencies. You can help with that by notifying the -maintainers of this problem (e.g. by creating a bug report) or by proposing a -fix to the maintainers (e.g. by creating a pull request): - +- ensure the maintainers know of this problem (e.g. creating a bug report if needed) +or even helping with a fix (e.g. by creating a pull request) - bar@1.0.0 - - Repository: https://example.com/ - - Detailed warning command: `cargo report future-incompatibilities --id 1 --package bar@1.0.0` + - repository: https://example.com/ + - detailed warning command: `cargo report future-incompatibilities --id 1 --package bar@1.0.0` -- If waiting for an upstream fix is not an option, you can use the `[patch]` -section in `Cargo.toml` to use your own version of the dependency. For more -information, see: +- use your own version of the dependency with the `[patch]` section in `Cargo.toml` +For more information, see: https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section The package `bar v1.0.0` currently triggers the following future incompatibility lints: @@ -372,9 +358,9 @@ fn test_multi_crate() { ... [WARNING] the following packages contain code that will be rejected by a future version of Rust: first-dep v0.0.1, second-dep v0.0.2 ... - - first-dep@0.0.1 + - first-dep@0.0.1 ... - - second-dep@0.0.2 + - second-dep@0.0.2 ... ") .run(); @@ -539,9 +525,11 @@ fn suggestions_for_updates() { .publish(); Package::new("big_update", "1.0.0") .file("src/lib.rs", FUTURE_EXAMPLE) + .dep("with_updates", "1.0.0") .publish(); Package::new("without_updates", "1.0.0") .file("src/lib.rs", FUTURE_EXAMPLE) + .dep("big_update", "1.0.0") .publish(); let p = project() @@ -575,6 +563,7 @@ fn suggestions_for_updates() { .publish(); Package::new("big_update", "2.0.0") .file("src/lib.rs", "") + .dep("with_updates", "1.0.0") .publish(); // This is a hack to force cargo to update the index. Cargo can't do this @@ -600,41 +589,28 @@ fn suggestions_for_updates() { [CHECKING] foo v0.1.0 ([ROOT]/foo) [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s [WARNING] the following packages contain code that will be rejected by a future version of Rust: big_update v1.0.0, with_updates v1.0.0, without_updates v1.0.0 -[NOTE] -To solve this problem, you can try the following approaches: - - -- Some affected dependencies have newer versions available. -You may want to consider updating them to a newer version to see if the issue has been fixed. - -big_update v1.0.0 has the following newer versions available: 2.0.0 -with_updates v1.0.0 has the following newer versions available: 1.0.1, 1.0.2, 3.0.1 - - -- If the issue is not solved by updating the dependencies, a fix has to be -implemented by those dependencies. You can help with that by notifying the -maintainers of this problem (e.g. by creating a bug report) or by proposing a -fix to the maintainers (e.g. by creating a pull request): - - - big_update@1.0.0 - - Repository: - - Detailed warning command: `cargo report future-incompatibilities --id 1 --package big_update@1.0.0` - - - with_updates@1.0.0 - - Repository: - - Detailed warning command: `cargo report future-incompatibilities --id 1 --package with_updates@1.0.0` - - - without_updates@1.0.0 - - Repository: - - Detailed warning command: `cargo report future-incompatibilities --id 1 --package without_updates@1.0.0` - -- If waiting for an upstream fix is not an option, you can use the `[patch]` -section in `Cargo.toml` to use your own version of the dependency. For more -information, see: -https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section +[HELP] update to a newer version to see if the issue has been fixed + - big_update v1.0.0 has the following newer versions available: 2.0.0 + - with_updates v1.0.0 has the following newer versions available: 1.0.1, 1.0.2, 3.0.1 +[HELP] ensure the maintainers know of this problem (e.g. creating a bug report if needed) + or even helping with a fix (e.g. by creating a pull request) + - big_update@1.0.0 + - repository: + - detailed warning command: `cargo report future-incompatibilities --id 1 --package big_update@1.0.0` + + - with_updates@1.0.0 + - repository: + - detailed warning command: `cargo report future-incompatibilities --id 1 --package with_updates@1.0.0` + + - without_updates@1.0.0 + - repository: + - detailed warning command: `cargo report future-incompatibilities --id 1 --package without_updates@1.0.0` +[HELP] use your own version of the dependency with the `[patch]` section in `Cargo.toml` + For more information, see: + https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section [NOTE] this report can be shown with `cargo report future-incompatibilities --id 1` -"#]].unordered()) +"#]]) .run(); p.cargo("report future-incompatibilities") @@ -649,36 +625,28 @@ to be in wide use. Each warning should contain a link for more information on what the warning means and how to resolve it. +to solve this problem, you can try the following approaches: -To solve this problem, you can try the following approaches: - - -- Some affected dependencies have newer versions available. -You may want to consider updating them to a newer version to see if the issue has been fixed. - -big_update v1.0.0 has the following newer versions available: 2.0.0 -with_updates v1.0.0 has the following newer versions available: 1.0.1, 1.0.2, 3.0.1 - -- If the issue is not solved by updating the dependencies, a fix has to be -implemented by those dependencies. You can help with that by notifying the -maintainers of this problem (e.g. by creating a bug report) or by proposing a -fix to the maintainers (e.g. by creating a pull request): +- update to a newer version to see if the issue has been fixed + - big_update v1.0.0 has the following newer versions available: 2.0.0 + - with_updates v1.0.0 has the following newer versions available: 1.0.1, 1.0.2, 3.0.1 +- ensure the maintainers know of this problem (e.g. creating a bug report if needed) +or even helping with a fix (e.g. by creating a pull request) - big_update@1.0.0 - - Repository: - - Detailed warning command: `cargo report future-incompatibilities --id 1 --package big_update@1.0.0` + - repository: + - detailed warning command: `cargo report future-incompatibilities --id 1 --package big_update@1.0.0` - with_updates@1.0.0 - - Repository: - - Detailed warning command: `cargo report future-incompatibilities --id 1 --package with_updates@1.0.0` + - repository: + - detailed warning command: `cargo report future-incompatibilities --id 1 --package with_updates@1.0.0` - without_updates@1.0.0 - - Repository: - - Detailed warning command: `cargo report future-incompatibilities --id 1 --package without_updates@1.0.0` + - repository: + - detailed warning command: `cargo report future-incompatibilities --id 1 --package without_updates@1.0.0` -- If waiting for an upstream fix is not an option, you can use the `[patch]` -section in `Cargo.toml` to use your own version of the dependency. For more -information, see: +- use your own version of the dependency with the `[patch]` section in `Cargo.toml` +For more information, see: https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section The package `big_update v1.0.0` currently triggers the following future incompatibility lints: @@ -717,23 +685,14 @@ fn correct_report_id_when_cached() { [CHECKING] foo v1.0.0 ([ROOT]/foo) [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s [WARNING] the following packages contain code that will be rejected by a future version of Rust: bar v1.0.0 -[NOTE] -To solve this problem, you can try the following approaches: - -- If the issue is not solved by updating the dependencies, a fix has to be -implemented by those dependencies. You can help with that by notifying the -maintainers of this problem (e.g. by creating a bug report) or by proposing a -fix to the maintainers (e.g. by creating a pull request): - - - bar@1.0.0 - - Repository: https://example.com/ - - Detailed warning command: `cargo report future-incompatibilities --id 1 --package bar@1.0.0` - -- If waiting for an upstream fix is not an option, you can use the `[patch]` -section in `Cargo.toml` to use your own version of the dependency. For more -information, see: -https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section - +[HELP] ensure the maintainers know of this problem (e.g. creating a bug report if needed) + or even helping with a fix (e.g. by creating a pull request) + - bar@1.0.0 + - repository: https://example.com/ + - detailed warning command: `cargo report future-incompatibilities --id 1 --package bar@1.0.0` +[HELP] use your own version of the dependency with the `[patch]` section in `Cargo.toml` + For more information, see: + https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section [NOTE] this report can be shown with `cargo report future-incompatibilities --id 1` "#]]) @@ -744,23 +703,14 @@ https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch .with_stderr_data(str![[r#" [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s [WARNING] the following packages contain code that will be rejected by a future version of Rust: bar v1.0.0 -[NOTE] -To solve this problem, you can try the following approaches: - -- If the issue is not solved by updating the dependencies, a fix has to be -implemented by those dependencies. You can help with that by notifying the -maintainers of this problem (e.g. by creating a bug report) or by proposing a -fix to the maintainers (e.g. by creating a pull request): - - - bar@1.0.0 - - Repository: https://example.com/ - - Detailed warning command: `cargo report future-incompatibilities --id 1 --package bar@1.0.0` - -- If waiting for an upstream fix is not an option, you can use the `[patch]` -section in `Cargo.toml` to use your own version of the dependency. For more -information, see: -https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section - +[HELP] ensure the maintainers know of this problem (e.g. creating a bug report if needed) + or even helping with a fix (e.g. by creating a pull request) + - bar@1.0.0 + - repository: https://example.com/ + - detailed warning command: `cargo report future-incompatibilities --id 1 --package bar@1.0.0` +[HELP] use your own version of the dependency with the `[patch]` section in `Cargo.toml` + For more information, see: + https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section [NOTE] this report can be shown with `cargo report future-incompatibilities --id 1` "#]])