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

#[allow(non_snake_case)] ignored #6541

Open
sivizius opened this issue Nov 13, 2020 · 9 comments
Open

#[allow(non_snake_case)] ignored #6541

sivizius opened this issue Nov 13, 2020 · 9 comments
Labels
A-diagnostics diagnostics / error reporting C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now

Comments

@sivizius
Copy link

The linter ignores #[allow(non_snake_case)] and warns about »… should have snake_case name, e.g. `…`«. In fact, this lint is redundant to the rustc-lint.

@lnicola
Copy link
Member

lnicola commented Nov 13, 2020

I think this wasn't completely implemented in #6421, CC @popzxc

Sample code:

#![allow(non_snake_case)]

fn main() {
    #[allow(non_snake_case)]
    let FOO_BAR = 42;
    drop(FOO_BAR);
}

image

It's also shown twice, not sure why.

In fact, this lint is redundant to the rustc-lint.

It's not. This one works as you type, but for cargo check you need to save the file you're editing. In the long run, all of them will be supported directly by rust-analyzer.

@popzxc
Copy link
Contributor

popzxc commented Nov 13, 2020

Yep, the support of this attribute is very basic, thus it is kind of expected.
Proper solution will require collecting attributes applied to the item up to the crate root, which is not a trivial task (given the fact that currently there is no API to do so).

@lnicola
Copy link
Member

lnicola commented Nov 13, 2020

Shouldn't #[allow(non_snake_case)] on the declaration work?

@popzxc
Copy link
Contributor

popzxc commented Nov 13, 2020

In theory, yes. However I could have skipped checking for attribute somewhere.

Anyway, unfortunately it doesn't seem that I'd be free from main work in the following couple of weeks to fix this :(

@flodiebold flodiebold added the S-actionable Someone could pick this issue up and work on it right now label Dec 21, 2020
@Veykril Veykril added the A-diagnostics diagnostics / error reporting label May 25, 2022
@lowr
Copy link
Contributor

lowr commented Feb 3, 2023

There have been bug reports on this: #13521, #14080. We currently don't (or, more precisely, can't) honor #[allow()]s on let statements, because we don't have a means to analyze attributes on statements and expressions at all iiuc.

@Veykril Veykril added the C-bug Category: bug label Feb 3, 2023
tgeoghegan added a commit to divviup/libprio-rs that referenced this issue Feb 3, 2023
We suppress variable name convention lints in a couple of spots. While
that works for `rustc`, unfortunately the variable names still trip a
different lint in `rust-analyzer` (see [1]). Fortunately, there's a
workaround: hoist the `#[allow()]` up to the enclosing item (in our
case, functions) instead of the individual line.

[1]: rust-lang/rust-analyzer#6541
tgeoghegan added a commit to divviup/libprio-rs that referenced this issue Feb 3, 2023
We suppress variable name convention lints in a couple of spots. While
that works for `rustc`, unfortunately the variable names still trip a
different lint in `rust-analyzer` (see [1]). Fortunately, there's a
workaround: hoist the `#[allow()]` up to the enclosing item (in our
case, functions) instead of the individual line.

[1]: rust-lang/rust-analyzer#6541
@HKalbasi
Copy link
Member

The #[allow] on expressions has been implemented in #14990, but the #![allow] is still not implemented.

@dladeira
Copy link

dladeira commented Mar 10, 2024

Hey, I'm not sure if this is a problem on my end, but when adding #[allow(non_camel_case_types)] to a struct, the warning still shows. It's only when at the top of the file I declare #![allow(non_snake_case)], does it go away.

Code for reference:

#[allow(non_camel_case_types)]
struct ResponseData {
    deviceName: String,
    _id: String,
    focus: i128
}

Am I doing something wrong? Is this intended?

@alibektas
Copy link
Member

alibektas commented Mar 10, 2024

Can it be that you confuse what both lints are responsible for or did I misunderstand you? See what both non_* do on the following example

#![allow(dead_code)]
#![allow(non_snake_case)]

#[allow(non_camel_case_types)]
struct responseData {
    deviceName: String,
    _id: String,
    focus: i128,
}

The problem with your snippet is non_snake_case and not non_camel_case_types so it makes sense that warning still shows when there is no #[allow(no_snake_case)]

@dladeira
Copy link

My bad, I got confused. It works now, thank you for clarifying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics diagnostics / error reporting C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

No branches or pull requests

9 participants