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

Cold Structs #54044

Closed
cramertj opened this issue Sep 7, 2018 · 2 comments · Fixed by #73461
Closed

Cold Structs #54044

cramertj opened this issue Sep 7, 2018 · 2 comments · Fixed by #73461
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`)

Comments

@cramertj
Copy link
Member

cramertj commented Sep 7, 2018

#[cold]
struct DonnerParty;

fn main() {
    #[cold] 5;
}

Is it intentional that this work? If so, what is it supposed to do? The reference lists it as a function-only attribute, but I've always known it to work on expressions like loops as well.

@petrochenkov
Copy link
Contributor

A lot of attributes (most of them?) are not validated in any way, neither locations, nor syntax.
So, something like this works as well:

#[cold(foo = 10)]
fn f() {}

This is a known issue, but I'm not sure there's a single issue about the attribute validation problem in general.

@Havvy
Copy link
Contributor

Havvy commented Sep 8, 2018

I'll add a line saying that the attribute is allowed on other places in the reference. That said, it'd be nice to make it a warning in the 2018 edition, error by default in the 2021 edition, and removed completely in the 2024 edition.

@petrochenkov Having an actual list of said attributes would be useful for said documentation purposes.

@cramertj You can't put attributes on expressions, only statements or blocks. Are you saying #[cold] has an effect when placed on loops? If so, that should definitely be documented as well. I did touch that section recently, mainly by removing it and making new sections for the attributes it contains. https://havvy.net/rust-reference/attributes.html#cold-attribute but I only added information about putting the attribute on associated functions.

@Havvy Havvy added the A-attributes Area: Attributes (`#[…]`, `#![…]`) label Sep 8, 2018
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Sep 7, 2020
…acement, r=matthewjasper

Validate built-in attribute placement

Closes rust-lang#54584, closes rust-lang#47725, closes rust-lang#54044.

I've changed silently ignoring some incorrectly placed attributes to errors.  I'm not sure what the policy is since this can theoretically break code (should they be warnings instead? does it warrant a crater run?).
@bors bors closed this as completed in dbb73f8 Sep 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants