Skip to content

Commit e821311

Browse files
committed
And add `boundary_toolchains` test
1 parent 41e383f commit e821311

File tree

6 files changed

+69
-9
lines changed

6 files changed

+69
-9
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use dylint_internal::{
2+
clippy_utils::set_toolchain_channel, find_and_replace, rustup::SanitizeEnvironment,
3+
testing::new_template,
4+
};
5+
use tempfile::tempdir;
6+
use test_log::test;
7+
8+
// smoelius: The channel date is one day later than the `rustc --version` date.
9+
const BOUNDARIES: [(&str, &str); 2] = [("2022-07-14", "2022-07-15"), ("2022-09-08", "2022-09-09")];
10+
11+
#[test]
12+
fn boundary_toolchain() {
13+
for (before, after) in BOUNDARIES {
14+
for date in [before, after] {
15+
let channel = format!("nightly-{}", date);
16+
17+
let tempdir = tempdir().unwrap();
18+
19+
new_template(tempdir.path()).unwrap();
20+
21+
find_and_replace(
22+
&tempdir.path().join("Cargo.toml"),
23+
&[r#"s/\r?\nclippy_utils = [^\r\n]*//"#],
24+
)
25+
.unwrap();
26+
27+
set_toolchain_channel(tempdir.path(), &channel).unwrap();
28+
29+
dylint_internal::cargo::test(&format!("with channel `{}`", channel), false)
30+
.sanitize_environment()
31+
.current_dir(&tempdir)
32+
.success()
33+
.unwrap();
34+
}
35+
}
36+
}

driver/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ fn zero_mir_opt_level(config: &mut rustc_interface::Config) {
136136
config.opts.debugging_opts.mir_opt_level.zero();
137137
}
138138

139+
// Relevant PR and merge commit:
140+
// * https://github.com/rust-lang/rust/pull/98975
141+
// * https://github.com/rust-lang/rust/commit/0ed9c64c3e63acac9bd77abce62501696c390450
139142
#[rustversion::since(2022-07-14)]
140143
fn zero_mir_opt_level(config: &mut rustc_interface::Config) {
141144
config.opts.unstable_opts.mir_opt_level = Some(0);

utils/linting/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ repository = "https://github.com/trailofbits/dylint"
99

1010
[dependencies]
1111
paste = "1.0.9"
12+
rustversion = "1.0.9"

utils/linting/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ rustc_session::declare_lint_pass!(Name => [NAME]);
5959
`impl_late_lint!`, etc. are like `declare_late_lint!`, etc. except:
6060

6161
- each calls [`impl_lint_pass!`] instead of `declare_lint_pass!`;
62-
- each requires an additional argument to specify the default value of the lint's [`LintPass`] structure.
62+
- each requires an additional argument to specify the value of the lint's [`LintPass`] structure.
6363

6464
That is, `impl_late_lint!`'s additional argument is what goes here:
6565

utils/linting/src/lib.rs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,28 @@ macro_rules! dylint_library {
2121
};
2222
}
2323

24+
#[rustversion::before(2022-09-08)]
25+
#[macro_export]
26+
macro_rules! __make_closure {
27+
($pass:expr) => {
28+
|| Box::new($pass)
29+
};
30+
}
31+
32+
// Relevant PR and merge commit:
33+
// * https://github.com/rust-lang/rust/pull/101501
34+
// * https://github.com/rust-lang/rust/commit/87788097b776f8e3662f76627944230684b671bd
35+
#[rustversion::since(2022-09-08)]
36+
#[macro_export]
37+
macro_rules! __make_closure {
38+
($pass:expr) => {
39+
|_| Box::new($pass)
40+
};
41+
}
42+
2443
#[macro_export]
2544
macro_rules! __declare_and_register_lint {
26-
($(#[$attr:meta])* $vis:vis $NAME:ident, $Level:ident, $desc:expr, $register_pass_method:ident, $default:expr) => {
45+
($(#[$attr:meta])* $vis:vis $NAME:ident, $Level:ident, $desc:expr, $register_pass_method:ident, $pass:expr) => {
2746
$crate::dylint_library!();
2847

2948
extern crate rustc_lint;
@@ -32,7 +51,7 @@ macro_rules! __declare_and_register_lint {
3251
#[no_mangle]
3352
pub fn register_lints(_sess: &rustc_session::Session, lint_store: &mut rustc_lint::LintStore) {
3453
lint_store.register_lints(&[$NAME]);
35-
lint_store.$register_pass_method(|| Box::new($default));
54+
lint_store.$register_pass_method($crate::__make_closure!($pass));
3655
}
3756

3857
rustc_session::declare_lint!($(#[$attr])* $vis $NAME, $Level, $desc);
@@ -41,8 +60,8 @@ macro_rules! __declare_and_register_lint {
4160

4261
#[macro_export]
4362
macro_rules! impl_pre_expansion_lint {
44-
($(#[$attr:meta])* $vis:vis $NAME:ident, $Level:ident, $desc:expr, $default:expr) => {
45-
$crate::__declare_and_register_lint!($(#[$attr])* $vis $NAME, $Level, $desc, register_pre_expansion_pass, $default);
63+
($(#[$attr:meta])* $vis:vis $NAME:ident, $Level:ident, $desc:expr, $pass:expr) => {
64+
$crate::__declare_and_register_lint!($(#[$attr])* $vis $NAME, $Level, $desc, register_pre_expansion_pass, $pass);
4665
$crate::paste::paste! {
4766
rustc_session::impl_lint_pass!([< $NAME:camel >] => [$NAME]);
4867
}
@@ -51,8 +70,8 @@ macro_rules! impl_pre_expansion_lint {
5170

5271
#[macro_export]
5372
macro_rules! impl_early_lint {
54-
($(#[$attr:meta])* $vis:vis $NAME:ident, $Level:ident, $desc:expr, $default:expr) => {
55-
$crate::__declare_and_register_lint!($(#[$attr])* $vis $NAME, $Level, $desc, register_early_pass, $default);
73+
($(#[$attr:meta])* $vis:vis $NAME:ident, $Level:ident, $desc:expr, $pass:expr) => {
74+
$crate::__declare_and_register_lint!($(#[$attr])* $vis $NAME, $Level, $desc, register_early_pass, $pass);
5675
$crate::paste::paste! {
5776
rustc_session::impl_lint_pass!([< $NAME:camel >] => [$NAME]);
5877
}
@@ -61,8 +80,8 @@ macro_rules! impl_early_lint {
6180

6281
#[macro_export]
6382
macro_rules! impl_late_lint {
64-
($(#[$attr:meta])* $vis:vis $NAME:ident, $Level:ident, $desc:expr, $default:expr) => {
65-
$crate::__declare_and_register_lint!($(#[$attr])* $vis $NAME, $Level, $desc, register_late_pass, $default);
83+
($(#[$attr:meta])* $vis:vis $NAME:ident, $Level:ident, $desc:expr, $pass:expr) => {
84+
$crate::__declare_and_register_lint!($(#[$attr])* $vis $NAME, $Level, $desc, register_late_pass, $pass);
6685
$crate::paste::paste! {
6786
rustc_session::impl_lint_pass!([< $NAME:camel >] => [$NAME]);
6887
}

0 commit comments

Comments
 (0)