Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron1011 committed Mar 4, 2021
1 parent 6177c65 commit f03d47c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 33 deletions.
17 changes: 12 additions & 5 deletions src/bin/cargo/commands/describe_future_incompatibilities.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::command_prelude::*;
use anyhow::anyhow;
use cargo::core::compiler::future_incompat::{OnDiskReport, FUTURE_INCOMPAT_FILE};
use cargo::core::nightly_features_allowed;
use cargo::drop_eprint;
use cargo::util::CargoResultExt;
use std::io::Read;

pub fn cli() -> App {
Expand All @@ -19,7 +19,7 @@ pub fn cli() -> App {
}

pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
if !nightly_features_allowed() {
if !config.nightly_features_allowed {
return Err(anyhow!(
"`cargo describe-future-incompatibilities` can only be used on the nightly channel"
)
Expand All @@ -37,12 +37,19 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
report_file
.file()
.read_to_string(&mut file_contents)
.map_err(|e| anyhow!("Failed to read report: {:?}", e))?;
let on_disk_report: OnDiskReport = serde_json::from_str(&file_contents).unwrap();
.chain_err(|| "failed to read report")?;
let on_disk_report: OnDiskReport =
serde_json::from_str(&file_contents).chain_err(|| "failed to load report")?;

let id = args.value_of("id").unwrap();
if id != on_disk_report.id {
return Err(anyhow!("Expected an id of `{}`, but `{}` was provided on the command line. Your report may have been overwritten by a different one.", on_disk_report.id, id).into());
return Err(anyhow!(
"Expected an id of `{}`, but `{}` was provided on the command line.\
Your report may have been overwritten by a different one.",
on_disk_report.id,
id
)
.into());
}

drop_eprint!(config, "{}", on_disk_report.report);
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/future_incompat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct FutureBreakageItem {
pub diagnostic: Diagnostic,
}

/// A diagnostic emitted by the compiler a a JSON message.
/// A diagnostic emitted by the compiler as a JSON message.
/// We only care about the 'rendered' field
#[derive(Serialize, Deserialize)]
pub struct Diagnostic {
Expand Down
33 changes: 17 additions & 16 deletions src/cargo/core/compiler/job_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ struct DrainState<'cfg> {

/// How many jobs we've finished
finished: usize,
show_future_incompat_report: bool,
per_crate_future_incompat_reports: Vec<FutureIncompatReportCrate>,
}

Expand Down Expand Up @@ -429,7 +428,6 @@ impl<'cfg> JobQueue<'cfg> {
pending_queue: Vec::new(),
print: DiagnosticPrinter::new(cx.bcx.config),
finished: 0,
show_future_incompat_report: cx.bcx.build_config.future_incompat_report,
per_crate_future_incompat_reports: Vec::new(),
};

Expand Down Expand Up @@ -613,12 +611,9 @@ impl<'cfg> DrainState<'cfg> {
}
}
Message::FutureIncompatReport(id, report) => {
let unit = self.active[&id].clone();
let package_id = self.active[&id].pkg.package_id();
self.per_crate_future_incompat_reports
.push(FutureIncompatReportCrate {
package_id: unit.pkg.package_id(),
report,
});
.push(FutureIncompatReportCrate { package_id, report });
}
Message::Token(acquired_token) => {
let token = acquired_token.chain_err(|| "failed to acquire jobserver token")?;
Expand Down Expand Up @@ -820,12 +815,14 @@ impl<'cfg> DrainState<'cfg> {
let crates_and_versions = self
.per_crate_future_incompat_reports
.iter()
.map(|r| format!("{}", r.package_id))
.map(|r| r.package_id.to_string())
.collect::<Vec<_>>()
.join(", ");

drop(cx.bcx.config.shell().warn(&format!("the following crates contain code that will be rejected by a future version of Rust: {}",
crates_and_versions)));
drop(cx.bcx.config.shell().warn(&format!(
"the following crates contain code that will be rejected by a future version of Rust: {}",
crates_and_versions
)));

let mut full_report = String::new();
let mut rng = thread_rng();
Expand All @@ -837,7 +834,10 @@ impl<'cfg> DrainState<'cfg> {
.collect();

for report in std::mem::take(&mut self.per_crate_future_incompat_reports) {
full_report.push_str(&format!("The crate `{}` currently triggers the following future incompatibility lints:\n", report.package_id));
full_report.push_str(&format!(
"The crate `{}` currently triggers the following future incompatibility lints:\n",
report.package_id
));
for item in report.report {
let rendered = if cx.bcx.config.shell().err_supports_color() {
item.diagnostic.rendered
Expand Down Expand Up @@ -868,13 +868,14 @@ impl<'cfg> DrainState<'cfg> {
})
.err();
if let Some(e) = err {
drop(cx.bcx.config.shell().warn(&format!(
"Failed to open on-disk future incompat report: {:?}",
e
)));
crate::display_warning_with_error(
"failed to write on-disk future incompat report",
&e,
&mut cx.bcx.config.shell(),
);
}

if self.show_future_incompat_report {
if cx.bcx.build_config.future_incompat_report {
drop_eprint!(cx.bcx.config, "{}", full_report);
drop(cx.bcx.config.shell().note(
&format!("this report can be shown with `cargo describe-future-incompatibilities -Z future-incompat-report --id {}`", id)
Expand Down
8 changes: 8 additions & 0 deletions src/doc/src/reference/unstable.md
Original file line number Diff line number Diff line change
Expand Up @@ -1122,3 +1122,11 @@ The 2021 edition will set the default [resolver version] to "2".
}
})();
</script>

### future incompat report
* RFC: [#2834](https://github.com/rust-lang/rfcs/blob/master/text/2834-cargo-report-future-incompat.md)
* rustc Tracking Issue: [#71249](https://github.com/rust-lang/rust/issues/71249)

The `-Z future-incompat-report` flag enables the creation of a future-incompat report
for all dependencies. This makes users aware if any of their crate's dependencies
might stop compiling with a future version of Rust.
19 changes: 8 additions & 11 deletions tests/testsuite/future_incompat_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn no_output_on_stable() {

p.cargo("build")
.with_stderr_contains(" = note: `#[warn(array_into_iter)]` on by default")
.with_stderr_does_not_contain("warning: the following crates contain code that will be rejected by a future version of Rust: `foo` v0.0.0")
.with_stderr_does_not_contain("[..]crates[..]")
.run();
}

Expand Down Expand Up @@ -66,7 +66,7 @@ fn test_single_crate() {
.masquerade_as_nightly_cargo()
.with_stderr_contains(" = note: `#[warn(array_into_iter)]` on by default")
.with_stderr_contains("warning: the following crates contain code that will be rejected by a future version of Rust: foo v0.0.0 [..]")
.with_stderr_does_not_contain("[..] future incompatibility lints:")
.with_stderr_does_not_contain("[..]incompatibility[..]")
.run();

p.cargo(command).arg("-Zfuture-incompat-report").arg("-Zunstable-options").arg("--future-incompat-report")
Expand Down Expand Up @@ -108,25 +108,23 @@ fn test_multi_crate() {
.build();

for command in &["build", "check", "rustc"] {
p.cargo(&format!("{} -Z future-incompat-report", command))
p.cargo(command).arg("-Zfuture-incompat-report")
.masquerade_as_nightly_cargo()
.with_stderr_does_not_contain(" = note: `#[warn(array_into_iter)]` on by default")
.with_stderr_does_not_contain("[..]array_into_iter[..]")
.with_stderr_contains("warning: the following crates contain code that will be rejected by a future version of Rust: first-dep v0.0.1, second-dep v0.0.2")
.with_stderr_does_not_contain("The crate `foo` v0.0.0 currently triggers the following future incompatibility lints:")
// Check that we don't have the 'triggers' message shown at the bottom of this loop
.with_stderr_does_not_contain("[..]triggers[..]")
.run();

p.cargo("describe-future-incompatibilities -Z future-incompat-report --id bad-id")
.masquerade_as_nightly_cargo()
.with_stderr_does_not_contain(" = note: `#[warn(array_into_iter)]` on by default")
.with_stderr_contains("error: Expected an id of [..]")
.with_stderr_does_not_contain("The crate `first-dep v0.0.1` currently triggers the following future incompatibility lints:")
.with_stderr_does_not_contain("The crate `second-dep v0.0.2` currently triggers the following future incompatibility lints:")
.with_stderr_does_not_contain("[..]triggers[..]")
.with_status(101)
.run();

p.cargo(&format!("{} -Z unstable-options -Z future-incompat-report --future-incompat-report", command))
p.cargo(command).arg("-Zunstable-options").arg("-Zfuture-incompat-report").arg("--future-incompat-report")
.masquerade_as_nightly_cargo()
.with_stderr_does_not_contain(" = note: `#[warn(array_into_iter)]` on by default")
.with_stderr_contains("warning: the following crates contain code that will be rejected by a future version of Rust: first-dep v0.0.1, second-dep v0.0.2")
.with_stderr_contains("The crate `first-dep v0.0.1` currently triggers the following future incompatibility lints:")
.with_stderr_contains("The crate `second-dep v0.0.2` currently triggers the following future incompatibility lints:")
Expand Down Expand Up @@ -158,7 +156,6 @@ fn test_multi_crate() {

p.cargo(&format!("describe-future-incompatibilities -Z future-incompat-report --id {}", id))
.masquerade_as_nightly_cargo()
.with_stderr_does_not_contain("warning: Expected an id of [..]")
.with_stderr_contains("The crate `first-dep v0.0.1` currently triggers the following future incompatibility lints:")
.with_stderr_contains("The crate `second-dep v0.0.2` currently triggers the following future incompatibility lints:")
.run();
Expand Down

0 comments on commit f03d47c

Please sign in to comment.