Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proc-macro definition attributes are accepted in arbitrary non-item positions #52329

Closed
petrochenkov opened this issue Jul 12, 2018 · 3 comments
Labels
A-decl-macros-1-2 Area: Declarative macros 1.2 A-decl-macros-2-0 Area: Declarative macros 2.0 (#39412) E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@petrochenkov
Copy link
Contributor

For example,

#![feature(proc_macro)]

fn main() {
    #[proc_macro]
    let x = 10;
    #[proc_macro_attribute]
    let x = 11;
    #[proc_macro_derive]
    let x = 12;
}

A lot of stable built-in attributes have this issue as well, but if we can fix it in this specific case, then why not.
I think these kinds of checks are usually performed in librustc/hir/check_attr.rs.

@petrochenkov petrochenkov added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. A-decl-macros-2-0 Area: Declarative macros 2.0 (#39412) A-decl-macros-1-2 Area: Declarative macros 1.2 labels Jul 12, 2018
@csmoe
Copy link
Member

csmoe commented Jul 13, 2018

For some built-in attributes like:

#[cfg(feature = "backtrace")]
let log_backtrace = {
let panics = update_panic_count(0);
if panics >= 2 {
Some(backtrace::PrintFormat::Full)
} else {
backtrace::log_enabled()
}
};

#[cfg(target_os = "freebsd")]
let e = libc::pthread_attr_get_np(libc::pthread_self(), &mut attr);
#[cfg(not(target_os = "freebsd"))]
let e = libc::pthread_getattr_np(libc::pthread_self(), &mut attr);

are they legal in this issue?

@petrochenkov
Copy link
Contributor Author

@csmoe
Yes, a number of attributes is valid in non-item positions.
This issue is only about three #[proc_macro*] attributes.

@petrochenkov
Copy link
Contributor Author

Closing, see #52367 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-decl-macros-1-2 Area: Declarative macros 1.2 A-decl-macros-2-0 Area: Declarative macros 2.0 (#39412) E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

2 participants