Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[beta-1.79] fix(toml): Don't warn on lints.rust.unexpected_cfgs.check-cfg #13925

Merged
merged 11 commits into from
May 22, 2024
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,11 @@ jobs:
curl -Lf https://github.com/rust-lang/mdBook/releases/download/v0.4.37/mdbook-v0.4.37-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook
echo `pwd`/mdbook >> $GITHUB_PATH
- run: cd src/doc && mdbook build --dest-dir ../../target/doc
- name: Run linkchecker.sh
run: |
cd target
curl -sSLO https://raw.githubusercontent.com/rust-lang/rust/master/src/tools/linkchecker/linkcheck.sh
sh linkcheck.sh --all --path ../src/doc cargo
# - name: Run linkchecker.sh
# run: |
# cd target
# curl -sSLO https://raw.githubusercontent.com/rust-lang/rust/master/src/tools/linkchecker/linkcheck.sh
# sh linkcheck.sh --all --path ../src/doc cargo

msrv:
runs-on: ubuntu-latest
Expand Down
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ snapbox = { version = "0.5.9", features = ["diff", "path", "term-svg"] }
tar = { version = "0.4.40", default-features = false }
tempfile = "3.10.1"
thiserror = "1.0.58"
time = { version = "0.3", features = ["parsing", "formatting", "serde"] }
time = { version = "0.3.36", features = ["parsing", "formatting", "serde"] }
toml = "0.8.12"
toml_edit = { version = "0.22.11", features = ["serde"] }
tracing = "0.1.40" # be compatible with rustc_log: https://github.com/rust-lang/rust/blob/e51e98dde6a/compiler/rustc_log/Cargo.toml#L9
Expand Down
1 change: 1 addition & 0 deletions crates/cargo-test-support/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(clippy::disallowed_methods)]

fn main() {
println!("cargo:rustc-check-cfg=cfg(emulate_second_only_system)");
println!(
"cargo:rustc-env=NATIVE_ARCH={}",
std::env::var("TARGET").unwrap()
Expand Down
8 changes: 4 additions & 4 deletions crates/cargo-test-support/containers/apache/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ COPY bar /repos/bar
WORKDIR /repos/bar
RUN git config --global user.email "[email protected]" &&\
git config --global user.name "Test User" &&\
git config --system --add safe.directory '*' &&\
git init -b master . &&\
git add Cargo.toml src &&\
git commit -m "Initial commit" &&\
mv .git ../bar.git &&\
cd ../bar.git &&\
git config --bool core.bare true &&\
rm -rf ../bar
cd .. &&\
git clone --bare bar bar.git &&\
rm -rf bar
WORKDIR /

EXPOSE 443
Expand Down
7 changes: 3 additions & 4 deletions crates/cargo-test-support/containers/sshd/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ RUN git config --global user.email "[email protected]" &&\
git init -b master . &&\
git add Cargo.toml src &&\
git commit -m "Initial commit" &&\
mv .git ../bar.git &&\
cd ../bar.git &&\
git config --bool core.bare true &&\
rm -rf ../bar
cd .. &&\
git clone --bare bar bar.git &&\
rm -rf bar
WORKDIR /
USER root

Expand Down
2 changes: 1 addition & 1 deletion crates/rustfix/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rustfix"
version = "0.8.3"
version = "0.8.4"
authors = [
"Pascal Hertleif <[email protected]>",
"Oliver Schneider <[email protected]>",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{HashSet};
use std::collections::HashSet;

fn main() {
let _: HashSet<()>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$message_type": "diagnostic",
"message": "unused imports: `HashMap`, `VecDeque`",
"code": {
"code": "unused_imports",
Expand All @@ -7,7 +8,7 @@
"level": "warning",
"spans": [
{
"file_name": "src/main.rs",
"file_name": "./tests/everything/multiple-solutions.nightly.rs",
"byte_start": 23,
"byte_end": 30,
"line_start": 1,
Expand All @@ -28,7 +29,7 @@
"expansion": null
},
{
"file_name": "src/main.rs",
"file_name": "./tests/everything/multiple-solutions.nightly.rs",
"byte_start": 41,
"byte_end": 49,
"line_start": 1,
Expand All @@ -51,7 +52,7 @@
],
"children": [
{
"message": "#[warn(unused_imports)] on by default",
"message": "`#[warn(unused_imports)]` on by default",
"code": null,
"level": "note",
"spans": [],
Expand All @@ -64,7 +65,28 @@
"level": "help",
"spans": [
{
"file_name": "src/main.rs",
"file_name": "./tests/everything/multiple-solutions.nightly.rs",
"byte_start": 22,
"byte_end": 23,
"line_start": 1,
"line_end": 1,
"column_start": 23,
"column_end": 24,
"is_primary": true,
"text": [
{
"text": "use std::collections::{HashMap, HashSet, VecDeque};",
"highlight_start": 23,
"highlight_end": 24
}
],
"label": null,
"suggested_replacement": "",
"suggestion_applicability": "MachineApplicable",
"expansion": null
},
{
"file_name": "./tests/everything/multiple-solutions.nightly.rs",
"byte_start": 23,
"byte_end": 32,
"line_start": 1,
Expand All @@ -85,7 +107,7 @@
"expansion": null
},
{
"file_name": "src/main.rs",
"file_name": "./tests/everything/multiple-solutions.nightly.rs",
"byte_start": 39,
"byte_end": 49,
"line_start": 1,
Expand All @@ -104,11 +126,41 @@
"suggested_replacement": "",
"suggestion_applicability": "MachineApplicable",
"expansion": null
},
{
"file_name": "./tests/everything/multiple-solutions.nightly.rs",
"byte_start": 49,
"byte_end": 50,
"line_start": 1,
"line_end": 1,
"column_start": 50,
"column_end": 51,
"is_primary": true,
"text": [
{
"text": "use std::collections::{HashMap, HashSet, VecDeque};",
"highlight_start": 50,
"highlight_end": 51
}
],
"label": null,
"suggested_replacement": "",
"suggestion_applicability": "MachineApplicable",
"expansion": null
}
],
"children": [],
"rendered": null
}
],
"rendered": "warning: unused imports: `HashMap`, `VecDeque`\n --> src/main.rs:1:24\n |\n1 | use std::collections::{HashMap, HashSet, VecDeque};\n | ^^^^^^^ ^^^^^^^^\n |\n = note: #[warn(unused_imports)] on by default\nhelp: remove the unused imports\n |\n1 | use std::collections::{HashSet};\n | -- --\n\n"
"rendered": "warning: unused imports: `HashMap`, `VecDeque`\n --> ./tests/everything/multiple-solutions.nightly.rs:1:24\n |\n1 | use std::collections::{HashMap, HashSet, VecDeque};\n | ^^^^^^^ ^^^^^^^^\n |\n = note: `#[warn(unused_imports)]` on by default\n\n"
}
{
"$message_type": "diagnostic",
"message": "1 warning emitted",
"code": null,
"level": "warning",
"spans": [],
"children": [],
"rendered": "warning: 1 warning emitted\n\n"
}
33 changes: 33 additions & 0 deletions crates/rustfix/tests/parse_and_replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@ mod settings {
pub const BLESS: &str = "RUSTFIX_TEST_BLESS";
}

static mut VERSION: (u32, bool) = (0, false);

// Temporarily copy from `cargo_test_macro::version`.
fn version() -> (u32, bool) {
static INIT: std::sync::Once = std::sync::Once::new();
INIT.call_once(|| {
let output = Command::new("rustc")
.arg("-V")
.output()
.expect("cargo should run");
let stdout = std::str::from_utf8(&output.stdout).expect("utf8");
let vers = stdout.split_whitespace().skip(1).next().unwrap();
let is_nightly = option_env!("CARGO_TEST_DISABLE_NIGHTLY").is_none()
&& (vers.contains("-nightly") || vers.contains("-dev"));
let minor = vers.split('.').skip(1).next().unwrap().parse().unwrap();
unsafe { VERSION = (minor, is_nightly) }
});
unsafe { VERSION }
}

fn compile(file: &Path) -> Result<Output, Error> {
let tmp = tempdir()?;

Expand Down Expand Up @@ -220,7 +240,20 @@ fn assert_fixtures(dir: &str, mode: &str) {
.unwrap();
let mut failures = 0;

let is_not_nightly = !version().1;

for file in &files {
if file
.file_stem()
.unwrap()
.to_str()
.unwrap()
.ends_with(".nightly")
&& is_not_nightly
{
info!("skipped: {file:?}");
continue;
}
if let Err(err) = test_rustfix_with_file(file, mode) {
println!("failed: {}", file.display());
warn!("{:?}", err);
Expand Down
5 changes: 5 additions & 0 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2356,6 +2356,11 @@ fn deprecated_underscore<T>(

fn warn_on_unused(unused: &BTreeSet<String>, warnings: &mut Vec<String>) {
for key in unused {
if key == "lints.rust.unexpected_cfgs.check-cfg" {
// This key is recognized in the following version and wanting to reduce warning noise
// for those users
continue;
}
warnings.push(format!("unused manifest key: {}", key));
if key == "profiles.debug" {
warnings.push("use `[profile.dev]` to configure debug builds".to_string());
Expand Down
6 changes: 3 additions & 3 deletions tests/testsuite/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ fn many_similar_names() {
.build();

p.cargo("bench")
.with_stdout_contains("test bin_bench ... bench: 0 ns/iter (+/- 0)")
.with_stdout_contains("test lib_bench ... bench: 0 ns/iter (+/- 0)")
.with_stdout_contains("test bench_bench ... bench: 0 ns/iter (+/- 0)")
.with_stdout_contains("test bin_bench ... bench:[..]")
.with_stdout_contains("test lib_bench ... bench:[..]")
.with_stdout_contains("test bench_bench ... bench:[..]")
.run();
}

Expand Down
28 changes: 28 additions & 0 deletions tests/testsuite/check_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,34 @@ fn build_script_feature_gate() {
.run();
}

#[cargo_test]
fn config_simple() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2015"

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ["cfg(has_foo)", "cfg(has_bar, values(\"yes\", \"no\"))"] }
"#,
)
.file("src/main.rs", "fn main() {}")
.build();

p.cargo("check")
.with_stderr(
"\
[CHECKING] foo v0.1.0 ([CWD])
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s
",
)
.run();
}

#[cargo_test(nightly, reason = "--check-cfg is unstable")]
fn config_valid() {
let p = project()
Expand Down
15 changes: 13 additions & 2 deletions tests/testsuite/standard_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,19 @@ fn setup() -> Setup {
args.push(env::var("REAL_SYSROOT").unwrap());
} else if args.iter().any(|arg| arg == "--target") {
// build-std target unit
args.push("--sysroot".to_string());
args.push("/path/to/nowhere".to_string());
//
// This `--sysroot` is here to disable the sysroot lookup,
// to ensure nothing is required.
// See https://github.com/rust-lang/wg-cargo-std-aware/issues/31
// for more information on this.
//
// FIXME: this is broken on x86_64-unknown-linux-gnu
// due to https://github.com/rust-lang/rust/pull/124129,
// because it requires lld in the sysroot. See
// https://github.com/rust-lang/rust/issues/125246 for
// more information.
// args.push("--sysroot".to_string());
// args.push("/path/to/nowhere".to_string());
} else {
// host unit, do not use sysroot
}
Expand Down