Skip to content

thread_local!() can't take attributes #30756

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

Closed
Manishearth opened this issue Jan 7, 2016 · 3 comments · Fixed by #30759
Closed

thread_local!() can't take attributes #30756

Manishearth opened this issue Jan 7, 2016 · 3 comments · Fixed by #30759

Comments

@Manishearth
Copy link
Member

#![deny(unsafe_code)]

thread_local!(static KEY: u8 = 1);

fn main() {
}

will hit an unsafe_code warning due to an unsafe function internally defined in the thread local macro (the unsafe function is a recent addition). There's no way to allow() it.

The macro should take in attributes.

@Stebalien
Copy link
Contributor

The correct fix for this specific bug is to annotate __gettit with #[allow(unsafe_code)]. Are there any other use cases for passing attributes through?

@sfackler
Copy link
Member

dead_code possibly.

@nodakai
Copy link
Contributor

nodakai commented Jan 23, 2016

For now, we can artificially add an inner module:

#![deny(unsafe_code)]

mod inner {
#![allow(unsafe_code)]
thread_local!(pub static KEY: u8 = 1);
}
use inner::KEY;

fn main() {
    KEY.with(|x| { x == &0u8 });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants