Skip to content

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

Closed
@alexcrichton

Description

@alexcrichton

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions