Skip to content

Rust: fix nightly toolchain version for tests using it #19828

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

Merged
merged 1 commit into from
Jun 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rust/extractor/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub struct Config {
pub qltest: bool,
pub qltest_cargo_check: bool,
pub qltest_dependencies: Vec<String>,
pub qltest_use_nightly: bool,
pub sysroot: Option<PathBuf>,
pub sysroot_src: Option<PathBuf>,
pub rustc_src: Option<PathBuf>,
Expand Down
23 changes: 21 additions & 2 deletions rust/extractor/src/qltest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ use std::path::Path;
use std::process::Command;
use tracing::info;

const EDITION: &str = "2021";
const NIGHTLY: &str = "nightly-2025-06-01";

fn dump_lib() -> anyhow::Result<()> {
let path_iterator = glob("*.rs").context("globbing test sources")?;
let paths = path_iterator
Expand All @@ -29,8 +32,11 @@ enum TestCargoManifest<'a> {
uses_proc_macro: bool,
uses_main: bool,
dependencies: &'a [String],
edition: &'a str,
},
Macro {
edition: &'a str,
},
Macro {},
}

impl TestCargoManifest<'_> {
Expand All @@ -56,16 +62,26 @@ fn dump_cargo_manifest(dependencies: &[String]) -> anyhow::Result<()> {
uses_proc_macro,
uses_main: fs::exists("main.rs").context("checking existence of main.rs")?,
dependencies,
edition: EDITION,
};
if uses_proc_macro {
TestCargoManifest::Workspace {}.dump("")?;
lib_manifest.dump(".lib")?;
TestCargoManifest::Macro {}.dump(".proc_macro")
TestCargoManifest::Macro { edition: EDITION }.dump(".proc_macro")
} else {
lib_manifest.dump("")
}
}

fn dump_nightly_toolchain() -> anyhow::Result<()> {
fs::write(
"rust-toolchain.toml",
format!("[toolchain]\nchannel = \"{NIGHTLY}\"\n"),
)
.context("writing rust-toolchain.toml")?;
Ok(())
}

fn set_sources(config: &mut Config) -> anyhow::Result<()> {
let path_iterator = glob("**/*.rs").context("globbing test sources")?;
config.inputs = path_iterator
Expand All @@ -79,6 +95,9 @@ pub(crate) fn prepare(config: &mut Config) -> anyhow::Result<()> {
dump_lib()?;
set_sources(config)?;
dump_cargo_manifest(&config.qltest_dependencies)?;
if config.qltest_use_nightly {
dump_nightly_toolchain()?;
}
if config.qltest_cargo_check {
let status = Command::new("cargo")
.env("RUSTFLAGS", "-Awarnings")
Expand Down
4 changes: 2 additions & 2 deletions rust/extractor/src/qltest_cargo.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ members = [".lib", ".proc_macro"]
[package]
name = "test"
version = "0.0.1"
edition = "2021"
edition = "{{ edition }}"
[lib]
path = "{{#uses_proc_macro}}../{{/uses_proc_macro}}lib.rs"
{{#uses_main}}
Expand All @@ -32,7 +32,7 @@ proc_macro = { path = "../.proc_macro" }
[package]
name = "proc_macro"
version = "0.0.1"
edition = "2021"
edition = "{{ edition }}"
[lib]
path = "../proc_macro.rs"
proc_macro = true
Expand Down
5 changes: 4 additions & 1 deletion rust/ql/test/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
target/

# these are all generated, see `rust/extractor/src/qltest.rs` for details
Cargo.toml
rust-toolchain.toml
lib.rs
target/
.proc_macro/
.lib/

1 change: 1 addition & 0 deletions rust/ql/test/query-tests/security/CWE-022/options.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
qltest_use_nightly: true
qltest_dependencies:
- poem = { version = "3.1.7" }

This file was deleted.

2 changes: 1 addition & 1 deletion rust/ql/test/query-tests/security/CWE-770/options.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
qltest_cargo_check: true
qltest_use_nightly: true
qltest_dependencies:
- libc = { version = "0.2.11" }

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
multiplePathResolutions
| deallocation.rs:106:16:106:19 | libc | file://:0:0:0:0 | Crate(libc@0.2.171) |
| deallocation.rs:106:16:106:19 | libc | file://:0:0:0:0 | Crate(libc@0.2.172) |
| deallocation.rs:106:16:106:19 | libc | file://:0:0:0:0 | Crate(libc@0.2.173) |
| deallocation.rs:106:16:106:27 | ...::malloc | file://:0:0:0:0 | fn malloc |
| deallocation.rs:106:16:106:27 | ...::malloc | file://:0:0:0:0 | fn malloc |
| deallocation.rs:112:3:112:6 | libc | file://:0:0:0:0 | Crate(libc@0.2.171) |
| deallocation.rs:112:3:112:6 | libc | file://:0:0:0:0 | Crate(libc@0.2.172) |
| deallocation.rs:112:3:112:6 | libc | file://:0:0:0:0 | Crate(libc@0.2.173) |
| deallocation.rs:112:3:112:12 | ...::free | file://:0:0:0:0 | fn free |
| deallocation.rs:112:3:112:12 | ...::free | file://:0:0:0:0 | fn free |
| deallocation.rs:112:29:112:32 | libc | file://:0:0:0:0 | Crate(libc@0.2.171) |
| deallocation.rs:112:29:112:32 | libc | file://:0:0:0:0 | Crate(libc@0.2.172) |
| deallocation.rs:112:29:112:32 | libc | file://:0:0:0:0 | Crate(libc@0.2.173) |
| deallocation.rs:260:11:260:22 | ...::from | file://:0:0:0:0 | fn from |
| deallocation.rs:260:11:260:22 | ...::from | file://:0:0:0:0 | fn from |
Expand Down
2 changes: 1 addition & 1 deletion rust/ql/test/query-tests/security/CWE-825/options.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
qltest_cargo_check: true
qltest_use_nightly: true
qltest_dependencies:
- libc = { version = "0.2.11" }

This file was deleted.