Skip to content

Commit a660516

Browse files
authored
Rollup merge of rust-lang#117596 - thomcc:core_macro_diag_items, r=Nilstrieb
Add diagnostic items for a few of core's builtin macros Specifically, `env`, `option_env`, and `include`. There are a number of reasons why people might want to look at these in lints (For example, to ensure that things behave consistently, detect things that might make builds less reproducible, etc). Concretely, in PL/Rust (well, `plrustc`) we have lints that forbid these (which I'd like to [add to clippy as restriction lints](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Landing.20a.20flotilla.20of.20lints.3F) eventually), and `dylint` also has [lints that look for `env!`/`option_env!`](https://github.com/trailofbits/dylint/blob/109a07e9f27a9651ef33b6677ccaddd21466e97a/examples/general/env_cargo_path/src/lib.rs) (although perhaps not `include`), which would benefit from this. My experience is that it's pretty annoying to (robustly) check uses of builtin macros without these IME, although that's perhaps just my own fault (e.g. I could be doing it wrong). At `@Nilstrieb's` suggestion, I've added a comment that explains why these are here, even though they are not used in the compiler. This is mostly to discourage removal, although it's not a big deal if it happens (I'm certainly not suggesting the presence of these be in any way stable). --- In theory this is a library PR (in that it's in library/core), but I'm going to roll compiler because the existence of this or not is much more likely something they care about rather than libs. Hopefully nobody objects to this. r? compiler
2 parents 629ee74 + 65bec86 commit a660516

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

library/core/src/macros/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,7 @@ pub(crate) mod builtin {
10441044
#[stable(feature = "rust1", since = "1.0.0")]
10451045
#[rustc_builtin_macro]
10461046
#[macro_export]
1047+
#[rustc_diagnostic_item = "env_macro"] // useful for external lints
10471048
macro_rules! env {
10481049
($name:expr $(,)?) => {{ /* compiler built-in */ }};
10491050
($name:expr, $error_msg:expr $(,)?) => {{ /* compiler built-in */ }};
@@ -1074,6 +1075,7 @@ pub(crate) mod builtin {
10741075
#[stable(feature = "rust1", since = "1.0.0")]
10751076
#[rustc_builtin_macro]
10761077
#[macro_export]
1078+
#[rustc_diagnostic_item = "option_env_macro"] // useful for external lints
10771079
macro_rules! option_env {
10781080
($name:expr $(,)?) => {{ /* compiler built-in */ }};
10791081
}
@@ -1479,6 +1481,7 @@ pub(crate) mod builtin {
14791481
#[stable(feature = "rust1", since = "1.0.0")]
14801482
#[rustc_builtin_macro]
14811483
#[macro_export]
1484+
#[rustc_diagnostic_item = "include_macro"] // useful for external lints
14821485
macro_rules! include {
14831486
($file:expr $(,)?) => {{ /* compiler built-in */ }};
14841487
}

0 commit comments

Comments
 (0)