#![crate_name = EXPR]
semantically allows EXPR
to be a macro call but otherwise mostly ignores it #122001
Description
Contrary to #![crate_type = EXPR]
, #![crate_name = EXPR]
does not semantically reject macro calls inside EXPR
.
Instead, it eagerly expands them but otherwise ignores the result (apart from errors).
I presume this regressed when #78835 (
F-extended_key_value_attributes
If so, this is a 1.53→1.54 stable-to-stable regression.
Update: It's a 1.75→1.76 stable-to-stable regression. Regressing PR: #117584.
Thanks ehuss, for the investigation! The result of the expansion used to be used!
Examples
The following examples all pass compilation and rustc completely ignores the crate name that comes from the expansion. This can be observed by for example running rustc file.rs --print=crate-name
prints file
(the file name is assumed to be file.rs
).
(A)
#![crate_name = concat!("alia", "s")] // ignored, crate name is `file`, not `alias`
fn main() {}
(B)
#![crate_name = include_str!("crate_name.txt")] // ignored, crate name is `file`, not `alias`
fn main() {}
where crate_name.txt
exists and consists of alias
.
(C)
#![crate_name = dep::generate!()] // ignored, crate name is `file`, not `alias`
fn main() {}
where we compile file.rs
with --extern=dep -L. --edition=2021
and where dep.rs
is:
#[macro_export]
macro_rules! generate { () => { "alias" } }
Activity