Skip to content

Commit 580461b

Browse files
committed
Auto merge of #9774 - Aaron1011:future-incompat-config, r=ehuss
Implement `[future-incompat-report]` config section Currently, I've just implemented the `always` and `never` frequencies from the RFC, which don't require tracking any additional state. cc `@ehuss`
2 parents 53ea285 + 88679e0 commit 580461b

File tree

5 files changed

+108
-9
lines changed

5 files changed

+108
-9
lines changed

src/cargo/core/compiler/job_queue.rs

+22-6
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,21 @@ impl<'cfg> DrainState<'cfg> {
885885
if !bcx.config.cli_unstable().future_incompat_report {
886886
return;
887887
}
888+
let should_display_message = match bcx.config.future_incompat_config() {
889+
Ok(config) => config.should_display_message(),
890+
Err(e) => {
891+
crate::display_warning_with_error(
892+
"failed to read future-incompat config from disk",
893+
&e,
894+
&mut bcx.config.shell(),
895+
);
896+
true
897+
}
898+
};
899+
888900
if self.per_package_future_incompat_reports.is_empty() {
901+
// Explicitly passing a command-line flag overrides
902+
// `should_display_message` from the config file
889903
if bcx.build_config.future_incompat_report {
890904
drop(
891905
bcx.config
@@ -907,11 +921,13 @@ impl<'cfg> DrainState<'cfg> {
907921
.map(|pid| pid.to_string())
908922
.collect();
909923

910-
drop(bcx.config.shell().warn(&format!(
911-
"the following packages contain code that will be rejected by a future \
912-
version of Rust: {}",
913-
package_vers.join(", ")
914-
)));
924+
if should_display_message || bcx.build_config.future_incompat_report {
925+
drop(bcx.config.shell().warn(&format!(
926+
"the following packages contain code that will be rejected by a future \
927+
version of Rust: {}",
928+
package_vers.join(", ")
929+
)));
930+
}
915931

916932
let on_disk_reports =
917933
OnDiskReports::save_report(bcx.ws, &self.per_package_future_incompat_reports);
@@ -925,7 +941,7 @@ impl<'cfg> DrainState<'cfg> {
925941
future-incompatibilities -Z future-incompat-report --id {}`",
926942
report_id
927943
)));
928-
} else {
944+
} else if should_display_message {
929945
drop(bcx.config.shell().note(&format!(
930946
"to see what the problems were, use the option \
931947
`--future-incompat-report`, or run `cargo report \

src/cargo/util/config/mod.rs

+38
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ pub struct Config {
178178
package_cache_lock: RefCell<Option<(Option<FileLock>, usize)>>,
179179
/// Cached configuration parsed by Cargo
180180
http_config: LazyCell<CargoHttpConfig>,
181+
future_incompat_config: LazyCell<CargoFutureIncompatConfig>,
181182
net_config: LazyCell<CargoNetConfig>,
182183
build_config: LazyCell<CargoBuildConfig>,
183184
target_cfgs: LazyCell<Vec<(String, TargetCfgConfig)>>,
@@ -275,6 +276,7 @@ impl Config {
275276
updated_sources: LazyCell::new(),
276277
package_cache_lock: RefCell::new(None),
277278
http_config: LazyCell::new(),
279+
future_incompat_config: LazyCell::new(),
278280
net_config: LazyCell::new(),
279281
build_config: LazyCell::new(),
280282
target_cfgs: LazyCell::new(),
@@ -1436,6 +1438,11 @@ impl Config {
14361438
.try_borrow_with(|| self.get::<CargoHttpConfig>("http"))
14371439
}
14381440

1441+
pub fn future_incompat_config(&self) -> CargoResult<&CargoFutureIncompatConfig> {
1442+
self.future_incompat_config
1443+
.try_borrow_with(|| self.get::<CargoFutureIncompatConfig>("future-incompat-report"))
1444+
}
1445+
14391446
pub fn net_config(&self) -> CargoResult<&CargoNetConfig> {
14401447
self.net_config
14411448
.try_borrow_with(|| self.get::<CargoNetConfig>("net"))
@@ -2034,6 +2041,37 @@ pub struct CargoHttpConfig {
20342041
pub ssl_version: Option<SslVersionConfig>,
20352042
}
20362043

2044+
#[derive(Debug, Default, Deserialize, PartialEq)]
2045+
#[serde(rename_all = "kebab-case")]
2046+
pub struct CargoFutureIncompatConfig {
2047+
frequency: Option<CargoFutureIncompatFrequencyConfig>,
2048+
}
2049+
2050+
#[derive(Debug, Deserialize, PartialEq)]
2051+
#[serde(rename_all = "kebab-case")]
2052+
pub enum CargoFutureIncompatFrequencyConfig {
2053+
Always,
2054+
Never,
2055+
}
2056+
2057+
impl CargoFutureIncompatConfig {
2058+
pub fn should_display_message(&self) -> bool {
2059+
use CargoFutureIncompatFrequencyConfig::*;
2060+
2061+
let frequency = self.frequency.as_ref().unwrap_or(&Always);
2062+
match frequency {
2063+
Always => true,
2064+
Never => false,
2065+
}
2066+
}
2067+
}
2068+
2069+
impl Default for CargoFutureIncompatFrequencyConfig {
2070+
fn default() -> Self {
2071+
Self::Always
2072+
}
2073+
}
2074+
20372075
/// Configuration for `ssl-version` in `http` section
20382076
/// There are two ways to configure:
20392077
///

src/doc/src/reference/unstable.md

+12
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,18 @@ the `--future-incompat-report` flag. The developer should then update their
12151215
dependencies to a version where the issue is fixed, or work with the
12161216
developers of the dependencies to help resolve the issue.
12171217

1218+
This feature can be configured through a `[future-incompat-report]`
1219+
section in `.cargo/config`. Currently, the supported options are:
1220+
1221+
```
1222+
[future-incompat-report]
1223+
frequency = FREQUENCY
1224+
```
1225+
1226+
The supported values for `FREQUENCY` are 'always` and 'never', which control
1227+
whether or not a message is printed out at the end of `cargo build` / `cargo check`.
1228+
1229+
12181230
### patch-in-config
12191231
* Original Pull Request: [#9204](https://github.com/rust-lang/cargo/pull/9204)
12201232
* Tracking Issue: [#9269](https://github.com/rust-lang/cargo/issues/9269)

tests/testsuite/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ pub fn write_config_at(path: impl AsRef<Path>, contents: &str) {
148148
fs::write(path, contents).unwrap();
149149
}
150150

151-
fn write_config_toml(config: &str) {
151+
pub fn write_config_toml(config: &str) {
152152
write_config_at(paths::root().join(".cargo/config.toml"), config);
153153
}
154154

tests/testsuite/future_incompat_report.rs

+35-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//! So we pick some random lint that will likely always be the same
88
//! over time.
99
10+
use super::config::write_config_toml;
1011
use cargo_test_support::registry::Package;
1112
use cargo_test_support::{basic_manifest, is_nightly, project, Project};
1213

@@ -115,14 +116,46 @@ fn test_single_crate() {
115116
let p = simple_project();
116117

117118
for command in &["build", "check", "rustc", "test"] {
118-
p.cargo(command).arg("-Zfuture-incompat-report")
119+
let check_has_future_compat = || {
120+
p.cargo(command).arg("-Zfuture-incompat-report")
121+
.masquerade_as_nightly_cargo()
122+
.env("RUSTFLAGS", "-Zfuture-incompat-test")
123+
.with_stderr_contains(FUTURE_OUTPUT)
124+
.with_stderr_contains("warning: the following packages contain code that will be rejected by a future version of Rust: foo v0.0.0 [..]")
125+
.with_stderr_does_not_contain("[..]incompatibility[..]")
126+
.run();
127+
};
128+
129+
// Check that we show a message with no [future-incompat-report] config section
130+
write_config_toml("");
131+
check_has_future_compat();
132+
133+
// Check that we show a message with `frequence = "always"`
134+
write_config_toml(
135+
"\
136+
[future-incompat-report]
137+
frequency = 'always'
138+
",
139+
);
140+
check_has_future_compat();
141+
142+
// Check that we do not show a message with `frequency = "never"`
143+
write_config_toml(
144+
"\
145+
[future-incompat-report]
146+
frequency = 'never'
147+
",
148+
);
149+
p.cargo(command)
150+
.arg("-Zfuture-incompat-report")
119151
.masquerade_as_nightly_cargo()
120152
.env("RUSTFLAGS", "-Zfuture-incompat-test")
121153
.with_stderr_contains(FUTURE_OUTPUT)
122-
.with_stderr_contains("warning: the following packages contain code that will be rejected by a future version of Rust: foo v0.0.0 [..]")
154+
.with_stderr_does_not_contain("[..]rejected[..]")
123155
.with_stderr_does_not_contain("[..]incompatibility[..]")
124156
.run();
125157

158+
// Check that passing `--future-incompat-report` overrides `frequency = 'never'`
126159
p.cargo(command).arg("-Zfuture-incompat-report").arg("-Zunstable-options").arg("--future-incompat-report")
127160
.masquerade_as_nightly_cargo()
128161
.env("RUSTFLAGS", "-Zfuture-incompat-test")

0 commit comments

Comments
 (0)