Skip to content

#![crate_name = EXPR] semantically allows EXPR to be a macro call but otherwise mostly ignores it #122001

@fmease

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 `#![feature(extended_key_value_attributes)] ) was stabilized.
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

A-attributesArea: Attributes (`#[…]`, `#![…]`)A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.P-highHigh priorityT-langRelevant to the language team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions