Skip to content

Allow inner lint attributes on block expressions #69703

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
wants to merge 1 commit into from
Closed

Allow inner lint attributes on block expressions #69703

wants to merge 1 commit into from

Conversation

lukas-code
Copy link
Member

follow-up to #69675.

This pull request allows lint attributes on blocks like this:

fn main() {
    let _ = {
        #![allow(unused_variables)]
        let x = ();
    };
}

I think this should be fine, because attributes are already allowed on blocks, if they are the tail expression of another block:

// this compiles on stable
fn main() {
    let _ = {{
        #![allow(unused_variables)]
        let x = ();
    }};
}

This pull request does not allow outer attributes on blocks or inner attributes that are not lint attributes:

fn main() {
    let _ = #[allow(unused_variables)] {}; // error

    let _ = {
        #![cfg(TRUE)] // error
    };
}

@rust-highfive
Copy link
Contributor

r? @varkor

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 4, 2020
@Centril Centril added A-attributes Area: Attributes (`#[…]`, `#![…]`) needs-fcp This change is insta-stable, so needs a completed FCP to proceed. T-lang Relevant to the language team, which will review and decide on the PR/issue. A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. labels Mar 11, 2020
@Centril
Copy link
Contributor

Centril commented Mar 11, 2020

Thank you for your contribution. However, I don't think we should be special casing one type of attribute in terms of stability and this does not seem strongly motivated to me (as there are workarounds). Once we feel comfortable stabilizing stmt_expr_attributes this will also be allowed, but without the special case.

cc @petrochenkov

@petrochenkov
Copy link
Contributor

I agree with the previous comment.

@lukas-code lukas-code closed this Mar 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 (`#[…]`, `#![…]`) A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. needs-fcp This change is insta-stable, so needs a completed FCP to proceed. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants