Skip to content

inner macro attributes no longer compile on rust 1.52 #85015

Closed
@tylerhawkes

Description

@tylerhawkes

Code

I have some proprietary code similar to this that has worked up through rust 1.51. Looking at the linked issues it looks like it should have never compiled in the first place. Whether this is fixed or not, I'll be moving the attributes out to their module definitions so that I can move on.

Cargo.toml:

[package]
name = "broken"
version = "0.1.0"
authors = ["Tyler Hawkes"]
edition = "2018"
[dependencies]
is_not = "*"

src/lib.rs

mod compile;
mod do_not_compile;
#[is_not::is]
pub use compile::compile_fn;
#[is_not::not]
pub use do_not_compile::compile_fn;

src/compile.rs (generated by build.rs)

#![is_not::is]
pub fn compile_fn() {
    println!("compiled")
}

src/do_not_compile.rs (generated by build.rs)

#![is_not::not]
pub fn compile_fn() {
    println!("compiled")
}

I expected to have the code compile with these 3 warnings (though I don't get them with my other code):

warning: function is never used: `compile_fn`
 --> src/do_not_compile.rs:3:8
  |
3 | pub fn compile_fn() {
  |        ^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: unused attribute
 --> src/compile.rs:1:1
  |
1 | #![is_not::is]
  | ^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_attributes)]` on by default

warning: unused attribute
 --> src/do_not_compile.rs:1:1
  |
1 | #![is_not::not]
  | ^^^^^^^^^^^^^^^

warning: 3 warnings emitted

Instead, the code doesn't compile referencing error E0658

error[E0658]: inner macro attributes are unstable
 --> src/compile.rs:1:4
  |
1 | #![is_not::is]
  |    ^^^^^^^^^^
  |
  = note: see issue #54726 <https://github.com/rust-lang/rust/issues/54726> for more information

error[E0658]: non-inline modules in proc macro input are unstable
 --> src/lib.rs:1:1
  |
1 | mod compile;
  | ^^^^^^^^^^^^
  |
  = note: see issue #54727 <https://github.com/rust-lang/rust/issues/54727> for more information

error[E0658]: inner macro attributes are unstable
 --> src/do_not_compile.rs:1:4
  |
1 | #![is_not::not]
  |    ^^^^^^^^^^^
  |
  = note: see issue #54726 <https://github.com/rust-lang/rust/issues/54726> for more information

error[E0658]: non-inline modules in proc macro input are unstable
 --> src/lib.rs:2:1
  |
2 | mod do_not_compile;
  | ^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #54727 <https://github.com/rust-lang/rust/issues/54727> for more information

Version it worked on

It most recently worked on: Rust 1.51

Version with regression

rustc --version --verbose:

rustc 1.52.0 (88f19c6da 2021-05-03)
binary: rustc
commit-hash: 88f19c6dab716c6281af7602e30f413e809c5974
commit-date: 2021-05-03
host: x86_64-unknown-linux-gnu
release: 1.52.0
LLVM version: 12.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions