Skip to content

#[inline] attribute causes #[allow(...)] to not work #115823

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
alexcrichton opened this issue Sep 13, 2023 · 1 comment · Fixed by #115825
Closed

#[inline] attribute causes #[allow(...)] to not work #115823

alexcrichton opened this issue Sep 13, 2023 · 1 comment · Fixed by #115825
Labels
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

@alexcrichton
Copy link
Member

Given this code:

pub struct A {
    pub x: u32,
}

pub fn foo(y: u32) -> A {
    A {
        #[allow(unused_comparisons)]
        x: if y < 0 { 1 } else { 2 },
    }
}

no warnings, as expected, are generated:

$ rustc foo.rs --crate-type lib

Given this code (note the addition of #[inline]) however:

pub struct A {
    pub x: u32,
}

#[inline]
pub fn foo(y: u32) -> A {
    A {
        #[allow(unused_comparisons)]
        x: if y < 0 { 1 } else { 2 },
    }
}

a warning is generated:

$ rustc foo.rs --crate-type lib
warning: comparison is useless due to type limits
 --> foo.rs:9:15
  |
9 |         x: if y < 0 { 1 } else { 2 },
  |               ^^^^^
  |
  = note: `#[warn(unused_comparisons)]` on by default

warning: 1 warning emitted
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 13, 2023
@saethlin
Copy link
Member

I think any attribute will reproduce this behavior. #[deny(unsafe_code)] as well as #[allow(dead_code)] seem to do the trick.

@saethlin saethlin added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Sep 13, 2023
@bors bors closed this as completed in e172351 Sep 14, 2023
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Sep 15, 2023
lnicola pushed a commit to lnicola/rust-analyzer that referenced this issue Apr 7, 2024
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this issue Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

Successfully merging a pull request may close this issue.

3 participants