Skip to content

Commit

Permalink
Change how spans are emitted in the builtin macro lints
Browse files Browse the repository at this point in the history
  • Loading branch information
thomcc committed Nov 2, 2023
1 parent 1d8882a commit 6c2b8dc
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 7 deletions.
20 changes: 14 additions & 6 deletions plrustc/plrustc/src/lints/builtin_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ impl PlrustBuiltinMacros {
if let Some((s, ..)) = utils::check_span_against_macro_diags(cx, span, &fs_diagnostic_items)
{
self.lint_fs(cx, s);
return;
if span != s {
self.lint_fs(cx, span);
}
}
let fs_def_paths: &[&[Symbol]] = &[
&[sym!(core), sym!(macros), sym!(builtin), sym!(include)],
Expand All @@ -48,15 +50,19 @@ impl PlrustBuiltinMacros {
];
if let Some((s, ..)) = utils::check_span_against_macro_def_paths(cx, span, &fs_def_paths) {
self.lint_fs(cx, s);
return;
if span != s {
self.lint_fs(cx, span);
}
}

let env_diagnostic_items = [sym!(env_macro), sym!(option_env_macro)];
if let Some((s, ..)) =
utils::check_span_against_macro_diags(cx, span, &env_diagnostic_items)
{
self.lint_env(cx, s);
return;
self.lint_env(cx, span);
if span != s {
self.lint_fs(cx, span);
}
}
let env_def_paths: &[&[Symbol]] = &[
&[sym!(core), sym!(macros), sym!(builtin), sym!(env)],
Expand All @@ -67,8 +73,10 @@ impl PlrustBuiltinMacros {
&[sym!(core), sym!(option_env)],
];
if let Some((s, ..)) = utils::check_span_against_macro_def_paths(cx, span, &env_def_paths) {
self.lint_env(cx, s);
return;
self.lint_env(cx, span);
if span != s {
self.lint_fs(cx, span);
}
}
}
}
Expand Down
124 changes: 123 additions & 1 deletion plrustc/plrustc/uitests/fs_macros.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,77 +6,199 @@ LL | const _A: &str = include_str!("fs_macros_included_file.txt");
|
= note: `-F plrust-filesystem-macros` implied by `-F plrust-lints`

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:3:18
|
LL | const _A: &str = include_str!("fs_macros_included_file.txt");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `include_str` (in Nightly builds, run with -Z macro-backtrace for more info)

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:5:19
|
LL | const _B: &[u8] = include_bytes!("fs_macros_included_file.txt");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:5:19
|
LL | const _B: &[u8] = include_bytes!("fs_macros_included_file.txt");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info)

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:7:18
|
LL | const _C: &str = core::include_str!("fs_macros_included_file.txt");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:7:18
|
LL | const _C: &str = core::include_str!("fs_macros_included_file.txt");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `core::include_str` (in Nightly builds, run with -Z macro-backtrace for more info)

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:8:19
|
LL | const _D: &[u8] = core::include_bytes!("fs_macros_included_file.txt");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:8:19
|
LL | const _D: &[u8] = core::include_bytes!("fs_macros_included_file.txt");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `core::include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info)

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:16:18
|
LL | const _E: &str = indirect!(include_str);
| ^^^^^^^^^^^^^^^^^^^^^^

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:12:9
|
LL | $callme!("fs_macros_included_file.txt")
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | const _E: &str = indirect!(include_str);
| ---------------------- in this macro invocation
|
= note: this error originates in the macro `include_str` which comes from the expansion of the macro `indirect` (in Nightly builds, run with -Z macro-backtrace for more info)

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:17:19
|
LL | const _F: &[u8] = indirect!(include_bytes);
| ^^^^^^^^^^^^^^^^^^^^^^^^

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:12:9
|
LL | $callme!("fs_macros_included_file.txt")
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | const _F: &[u8] = indirect!(include_bytes);
| ------------------------ in this macro invocation
|
= note: this error originates in the macro `include_bytes` which comes from the expansion of the macro `indirect` (in Nightly builds, run with -Z macro-backtrace for more info)

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:31:18
|
LL | const _G: &str = in_macro!();
| ^^^^^^^^^^^

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:21:9
|
LL | include_str!("fs_macros_included_file.txt")
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | const _G: &str = in_macro!();
| ----------- in this macro invocation
|
= note: this error originates in the macro `include_str` which comes from the expansion of the macro `in_macro` (in Nightly builds, run with -Z macro-backtrace for more info)

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:32:28
|
LL | const _H: &str = in_macro!(include_str!("fs_macros_included_file.txt"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:32:28
|
LL | const _H: &str = in_macro!(include_str!("fs_macros_included_file.txt"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `include_str` (in Nightly builds, run with -Z macro-backtrace for more info)

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:33:29
|
LL | const _I: &[u8] = in_macro!(include_bytes!("fs_macros_included_file.txt"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:33:29
|
LL | const _I: &[u8] = in_macro!(include_bytes!("fs_macros_included_file.txt"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info)

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:34:19
|
LL | const _J: &[u8] = in_macro!(include_bytes, "fs_macros_included_file.txt");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:27:9
|
LL | $mac!($arg)
| ^^^^^^^^^^^
...
LL | const _J: &[u8] = in_macro!(include_bytes, "fs_macros_included_file.txt");
| ------------------------------------------------------- in this macro invocation
|
= note: this error originates in the macro `include_bytes` which comes from the expansion of the macro `in_macro` (in Nightly builds, run with -Z macro-backtrace for more info)

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:37:18
|
LL | const _L: &str = sneaky!("fs_macros_included_file.txt");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:37:18
|
LL | const _L: &str = sneaky!("fs_macros_included_file.txt");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `sneaky` (in Nightly builds, run with -Z macro-backtrace for more info)

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:38:18
|
LL | const _M: &str = in_macro!(sneaky, "fs_macros_included_file.txt");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:27:9
|
LL | $mac!($arg)
| ^^^^^^^^^^^
...
LL | const _M: &str = in_macro!(sneaky, "fs_macros_included_file.txt");
| ------------------------------------------------ in this macro invocation
|
= note: this error originates in the macro `sneaky` which comes from the expansion of the macro `in_macro` (in Nightly builds, run with -Z macro-backtrace for more info)

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:41:21
|
LL | format!("{:?}", in_macro!())
| ^^^^^^^^^^^

error: aborting due to 13 previous errors
error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:21:9
|
LL | include_str!("fs_macros_included_file.txt")
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | format!("{:?}", in_macro!())
| ----------- in this macro invocation
|
= note: this error originates in the macro `include_str` which comes from the expansion of the macro `in_macro` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 26 previous errors

0 comments on commit 6c2b8dc

Please sign in to comment.