Skip to content

Commit f1f36db

Browse files
authored
Merge pull request #19828 from github/redsun82/rust-fix-nightly-toolchain
Rust: fix nightly toolchain version for tests using it
2 parents 6773903 + 7f1769e commit f1f36db

File tree

11 files changed

+34
-22
lines changed

11 files changed

+34
-22
lines changed

rust/extractor/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ pub struct Config {
6262
pub qltest: bool,
6363
pub qltest_cargo_check: bool,
6464
pub qltest_dependencies: Vec<String>,
65+
pub qltest_use_nightly: bool,
6566
pub sysroot: Option<PathBuf>,
6667
pub sysroot_src: Option<PathBuf>,
6768
pub rustc_src: Option<PathBuf>,

rust/extractor/src/qltest.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ use std::path::Path;
88
use std::process::Command;
99
use tracing::info;
1010

11+
const EDITION: &str = "2021";
12+
const NIGHTLY: &str = "nightly-2025-06-01";
13+
1114
fn dump_lib() -> anyhow::Result<()> {
1215
let path_iterator = glob("*.rs").context("globbing test sources")?;
1316
let paths = path_iterator
@@ -29,8 +32,11 @@ enum TestCargoManifest<'a> {
2932
uses_proc_macro: bool,
3033
uses_main: bool,
3134
dependencies: &'a [String],
35+
edition: &'a str,
36+
},
37+
Macro {
38+
edition: &'a str,
3239
},
33-
Macro {},
3440
}
3541

3642
impl TestCargoManifest<'_> {
@@ -56,16 +62,26 @@ fn dump_cargo_manifest(dependencies: &[String]) -> anyhow::Result<()> {
5662
uses_proc_macro,
5763
uses_main: fs::exists("main.rs").context("checking existence of main.rs")?,
5864
dependencies,
65+
edition: EDITION,
5966
};
6067
if uses_proc_macro {
6168
TestCargoManifest::Workspace {}.dump("")?;
6269
lib_manifest.dump(".lib")?;
63-
TestCargoManifest::Macro {}.dump(".proc_macro")
70+
TestCargoManifest::Macro { edition: EDITION }.dump(".proc_macro")
6471
} else {
6572
lib_manifest.dump("")
6673
}
6774
}
6875

76+
fn dump_nightly_toolchain() -> anyhow::Result<()> {
77+
fs::write(
78+
"rust-toolchain.toml",
79+
format!("[toolchain]\nchannel = \"{NIGHTLY}\"\n"),
80+
)
81+
.context("writing rust-toolchain.toml")?;
82+
Ok(())
83+
}
84+
6985
fn set_sources(config: &mut Config) -> anyhow::Result<()> {
7086
let path_iterator = glob("**/*.rs").context("globbing test sources")?;
7187
config.inputs = path_iterator
@@ -79,6 +95,9 @@ pub(crate) fn prepare(config: &mut Config) -> anyhow::Result<()> {
7995
dump_lib()?;
8096
set_sources(config)?;
8197
dump_cargo_manifest(&config.qltest_dependencies)?;
98+
if config.qltest_use_nightly {
99+
dump_nightly_toolchain()?;
100+
}
82101
if config.qltest_cargo_check {
83102
let status = Command::new("cargo")
84103
.env("RUSTFLAGS", "-Awarnings")

rust/extractor/src/qltest_cargo.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ members = [".lib", ".proc_macro"]
1111
[package]
1212
name = "test"
1313
version = "0.0.1"
14-
edition = "2021"
14+
edition = "{{ edition }}"
1515
[lib]
1616
path = "{{#uses_proc_macro}}../{{/uses_proc_macro}}lib.rs"
1717
{{#uses_main}}
@@ -32,7 +32,7 @@ proc_macro = { path = "../.proc_macro" }
3232
[package]
3333
name = "proc_macro"
3434
version = "0.0.1"
35-
edition = "2021"
35+
edition = "{{ edition }}"
3636
[lib]
3737
path = "../proc_macro.rs"
3838
proc_macro = true

rust/ql/test/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
target/
2+
3+
# these are all generated, see `rust/extractor/src/qltest.rs` for details
14
Cargo.toml
5+
rust-toolchain.toml
26
lib.rs
3-
target/
47
.proc_macro/
58
.lib/
69

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
qltest_use_nightly: true
12
qltest_dependencies:
23
- poem = { version = "3.1.7" }

rust/ql/test/query-tests/security/CWE-022/rust-toolchain.toml

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
qltest_cargo_check: true
1+
qltest_use_nightly: true
22
qltest_dependencies:
33
- libc = { version = "0.2.11" }

rust/ql/test/query-tests/security/CWE-770/rust-toolchain.toml

Lines changed: 0 additions & 2 deletions
This file was deleted.

rust/ql/test/query-tests/security/CWE-825/CONSISTENCY/PathResolutionConsistency.expected

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
multiplePathResolutions
2-
| deallocation.rs:106:16:106:19 | libc | file://:0:0:0:0 | Crate(libc@0.2.171) |
2+
| deallocation.rs:106:16:106:19 | libc | file://:0:0:0:0 | Crate(libc@0.2.172) |
33
| deallocation.rs:106:16:106:19 | libc | file://:0:0:0:0 | Crate(libc@0.2.173) |
44
| deallocation.rs:106:16:106:27 | ...::malloc | file://:0:0:0:0 | fn malloc |
55
| deallocation.rs:106:16:106:27 | ...::malloc | file://:0:0:0:0 | fn malloc |
6-
| deallocation.rs:112:3:112:6 | libc | file://:0:0:0:0 | Crate(libc@0.2.171) |
6+
| deallocation.rs:112:3:112:6 | libc | file://:0:0:0:0 | Crate(libc@0.2.172) |
77
| deallocation.rs:112:3:112:6 | libc | file://:0:0:0:0 | Crate(libc@0.2.173) |
88
| deallocation.rs:112:3:112:12 | ...::free | file://:0:0:0:0 | fn free |
99
| deallocation.rs:112:3:112:12 | ...::free | file://:0:0:0:0 | fn free |
10-
| deallocation.rs:112:29:112:32 | libc | file://:0:0:0:0 | Crate(libc@0.2.171) |
10+
| deallocation.rs:112:29:112:32 | libc | file://:0:0:0:0 | Crate(libc@0.2.172) |
1111
| deallocation.rs:112:29:112:32 | libc | file://:0:0:0:0 | Crate(libc@0.2.173) |
1212
| deallocation.rs:260:11:260:22 | ...::from | file://:0:0:0:0 | fn from |
1313
| deallocation.rs:260:11:260:22 | ...::from | file://:0:0:0:0 | fn from |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
qltest_cargo_check: true
1+
qltest_use_nightly: true
22
qltest_dependencies:
33
- libc = { version = "0.2.11" }

rust/ql/test/query-tests/security/CWE-825/rust-toolchain.toml

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)