Skip to content

Commit f03d47c

Browse files
committed
Address review comments
1 parent 6177c65 commit f03d47c

File tree

5 files changed

+46
-33
lines changed

5 files changed

+46
-33
lines changed

src/bin/cargo/commands/describe_future_incompatibilities.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::command_prelude::*;
22
use anyhow::anyhow;
33
use cargo::core::compiler::future_incompat::{OnDiskReport, FUTURE_INCOMPAT_FILE};
4-
use cargo::core::nightly_features_allowed;
54
use cargo::drop_eprint;
5+
use cargo::util::CargoResultExt;
66
use std::io::Read;
77

88
pub fn cli() -> App {
@@ -19,7 +19,7 @@ pub fn cli() -> App {
1919
}
2020

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

4344
let id = args.value_of("id").unwrap();
4445
if id != on_disk_report.id {
45-
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());
46+
return Err(anyhow!(
47+
"Expected an id of `{}`, but `{}` was provided on the command line.\
48+
Your report may have been overwritten by a different one.",
49+
on_disk_report.id,
50+
id
51+
)
52+
.into());
4653
}
4754

4855
drop_eprint!(config, "{}", on_disk_report.report);

src/cargo/core/compiler/future_incompat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct FutureBreakageItem {
1515
pub diagnostic: Diagnostic,
1616
}
1717

18-
/// A diagnostic emitted by the compiler a a JSON message.
18+
/// A diagnostic emitted by the compiler as a JSON message.
1919
/// We only care about the 'rendered' field
2020
#[derive(Serialize, Deserialize)]
2121
pub struct Diagnostic {

src/cargo/core/compiler/job_queue.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ struct DrainState<'cfg> {
157157

158158
/// How many jobs we've finished
159159
finished: usize,
160-
show_future_incompat_report: bool,
161160
per_crate_future_incompat_reports: Vec<FutureIncompatReportCrate>,
162161
}
163162

@@ -429,7 +428,6 @@ impl<'cfg> JobQueue<'cfg> {
429428
pending_queue: Vec::new(),
430429
print: DiagnosticPrinter::new(cx.bcx.config),
431430
finished: 0,
432-
show_future_incompat_report: cx.bcx.build_config.future_incompat_report,
433431
per_crate_future_incompat_reports: Vec::new(),
434432
};
435433

@@ -613,12 +611,9 @@ impl<'cfg> DrainState<'cfg> {
613611
}
614612
}
615613
Message::FutureIncompatReport(id, report) => {
616-
let unit = self.active[&id].clone();
614+
let package_id = self.active[&id].pkg.package_id();
617615
self.per_crate_future_incompat_reports
618-
.push(FutureIncompatReportCrate {
619-
package_id: unit.pkg.package_id(),
620-
report,
621-
});
616+
.push(FutureIncompatReportCrate { package_id, report });
622617
}
623618
Message::Token(acquired_token) => {
624619
let token = acquired_token.chain_err(|| "failed to acquire jobserver token")?;
@@ -820,12 +815,14 @@ impl<'cfg> DrainState<'cfg> {
820815
let crates_and_versions = self
821816
.per_crate_future_incompat_reports
822817
.iter()
823-
.map(|r| format!("{}", r.package_id))
818+
.map(|r| r.package_id.to_string())
824819
.collect::<Vec<_>>()
825820
.join(", ");
826821

827-
drop(cx.bcx.config.shell().warn(&format!("the following crates contain code that will be rejected by a future version of Rust: {}",
828-
crates_and_versions)));
822+
drop(cx.bcx.config.shell().warn(&format!(
823+
"the following crates contain code that will be rejected by a future version of Rust: {}",
824+
crates_and_versions
825+
)));
829826

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

839836
for report in std::mem::take(&mut self.per_crate_future_incompat_reports) {
840-
full_report.push_str(&format!("The crate `{}` currently triggers the following future incompatibility lints:\n", report.package_id));
837+
full_report.push_str(&format!(
838+
"The crate `{}` currently triggers the following future incompatibility lints:\n",
839+
report.package_id
840+
));
841841
for item in report.report {
842842
let rendered = if cx.bcx.config.shell().err_supports_color() {
843843
item.diagnostic.rendered
@@ -868,13 +868,14 @@ impl<'cfg> DrainState<'cfg> {
868868
})
869869
.err();
870870
if let Some(e) = err {
871-
drop(cx.bcx.config.shell().warn(&format!(
872-
"Failed to open on-disk future incompat report: {:?}",
873-
e
874-
)));
871+
crate::display_warning_with_error(
872+
"failed to write on-disk future incompat report",
873+
&e,
874+
&mut cx.bcx.config.shell(),
875+
);
875876
}
876877

877-
if self.show_future_incompat_report {
878+
if cx.bcx.build_config.future_incompat_report {
878879
drop_eprint!(cx.bcx.config, "{}", full_report);
879880
drop(cx.bcx.config.shell().note(
880881
&format!("this report can be shown with `cargo describe-future-incompatibilities -Z future-incompat-report --id {}`", id)

src/doc/src/reference/unstable.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,3 +1122,11 @@ The 2021 edition will set the default [resolver version] to "2".
11221122
}
11231123
})();
11241124
</script>
1125+
1126+
### future incompat report
1127+
* RFC: [#2834](https://github.com/rust-lang/rfcs/blob/master/text/2834-cargo-report-future-incompat.md)
1128+
* rustc Tracking Issue: [#71249](https://github.com/rust-lang/rust/issues/71249)
1129+
1130+
The `-Z future-incompat-report` flag enables the creation of a future-incompat report
1131+
for all dependencies. This makes users aware if any of their crate's dependencies
1132+
might stop compiling with a future version of Rust.

tests/testsuite/future_incompat_report.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn no_output_on_stable() {
1111

1212
p.cargo("build")
1313
.with_stderr_contains(" = note: `#[warn(array_into_iter)]` on by default")
14-
.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")
14+
.with_stderr_does_not_contain("[..]crates[..]")
1515
.run();
1616
}
1717

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

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

110110
for command in &["build", "check", "rustc"] {
111-
p.cargo(&format!("{} -Z future-incompat-report", command))
111+
p.cargo(command).arg("-Zfuture-incompat-report")
112112
.masquerade_as_nightly_cargo()
113-
.with_stderr_does_not_contain(" = note: `#[warn(array_into_iter)]` on by default")
113+
.with_stderr_does_not_contain("[..]array_into_iter[..]")
114114
.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")
115-
.with_stderr_does_not_contain("The crate `foo` v0.0.0 currently triggers the following future incompatibility lints:")
115+
// Check that we don't have the 'triggers' message shown at the bottom of this loop
116+
.with_stderr_does_not_contain("[..]triggers[..]")
116117
.run();
117118

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

127-
p.cargo(&format!("{} -Z unstable-options -Z future-incompat-report --future-incompat-report", command))
126+
p.cargo(command).arg("-Zunstable-options").arg("-Zfuture-incompat-report").arg("--future-incompat-report")
128127
.masquerade_as_nightly_cargo()
129-
.with_stderr_does_not_contain(" = note: `#[warn(array_into_iter)]` on by default")
130128
.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")
131129
.with_stderr_contains("The crate `first-dep v0.0.1` currently triggers the following future incompatibility lints:")
132130
.with_stderr_contains("The crate `second-dep v0.0.2` currently triggers the following future incompatibility lints:")
@@ -158,7 +156,6 @@ fn test_multi_crate() {
158156

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

0 commit comments

Comments
 (0)