Skip to content

Clippy attributes have no effect on struct fields #60681

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

Open
spease opened this issue May 9, 2019 · 5 comments
Open

Clippy attributes have no effect on struct fields #60681

spease opened this issue May 9, 2019 · 5 comments
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@spease
Copy link

spease commented May 9, 2019

Example:


struct MyTest {
    a: &'static [u64],
}

fn main() -> Result<(), Error> {
    let b = MyTest {
        #[allow(clippy::unreadable_literal)]
        a: &[1234567890],
    };

    Ok(())
}

The #[allow] directive must be placed on the variable assignment to have an effect - where it is now does not seem to cover the field value.

Searched a little bit, but wasn't sure if this goes with any existing issues (not sure if this would be #53012 since I don't think clippy attributes are procedural)

@Centril Centril added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. labels May 9, 2019
@Centril
Copy link
Contributor

Centril commented May 9, 2019

cc @oli-obk

@oli-obk
Copy link
Contributor

oli-obk commented May 10, 2019

This is not a clippy issue:

struct MyTest {
    a: &'static [u64],
}

fn main() -> Result<(), ()> {
    let b = MyTest {
        #[allow(const_err)]
        a: &[0 - 1],
    };

    Ok(())
}

@oli-obk oli-obk added C-bug Category: This is a bug. and removed T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. labels May 10, 2019
@euclio
Copy link
Contributor

euclio commented Dec 23, 2019

Ran into this with #[allow(deprecated)] today.

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=af56b57628284884d1bed6a1abc8aefc

#![deny(warnings)]

struct Foo {
    #[deprecated]
    deprecated: usize,
}

fn main() {
    let foo = Foo {
        #[allow(deprecated)]
        deprecated: 1,
    };
    
    println!("{}", foo.deprecated)
}
error: use of deprecated item 'Foo::deprecated'
  --> src/main.rs:11:9
   |
11 |         deprecated: 1,
   |         ^^^^^^^^^^^^^
   |
note: lint level defined here
  --> src/main.rs:1:9
   |
1  | #![deny(warnings)]
   |         ^^^^^^^^
   = note: `#[deny(deprecated)]` implied by `#[deny(warnings)]`

error: use of deprecated item 'Foo::deprecated'
  --> src/main.rs:14:20
   |
14 |     println!("{}", foo.deprecated)
   |                    ^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

Notably putting the #[allow] on the assignment statement also has no effect. The workaround is to put the #[allow] on fn main().

@Centril Centril added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Dec 23, 2019
@awoimbee
Copy link
Contributor

This issue is still present.
Attributes have no effect on struct fields during assignment.

How things currently work:

#![deny(warnings)]
struct Foo {
    #[deprecated]
    deprecated: usize,
}
fn main() {
    #[allow(deprecated)]
    let foo = Foo {deprecated: 1};
     #[allow(deprecated)]
    let tmp = foo.deprecated;
    println!("{}", tmp);
}

How we would like things to work:

#![deny(warnings)]
struct Foo {
    #[deprecated]
    deprecated: usize,
}
fn main() {
    let foo = Foo {
        #[allow(deprecated)]
        deprecated: 1
     };
     #[allow(deprecated)]
    let tmp = foo.deprecated;
    println!("{}", tmp);
}

@ClementNerma
Copy link

Stil a problem today:

struct Test {
    #[allow(non_snake_case)] // <-- this does nothing
    #[allow(dead_code)] // <-- while this works
    aB: u128,
}

@fmease fmease added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. and removed A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. labels Dec 21, 2024
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. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants