Skip to content

Attributes at the beginning of a file have confusing semantics #2568

Closed
@catamorphism

Description

@catamorphism

I was trying to add a #warn attribute to a test case in order to turn a warning into an error, and I spent an embarrassingly large amount of time trying to debug why the warning still seemed to be treated as a warning. The reason was that I put: #[warn(err_non_implicitly_copyable_typarams)]

at the very beginning of the file, which of course meant it applied to only the first item in the file -- which wasn't the one containing the code that triggers the warning. I'd forgotten that attributes only apply to the next item, not the whole file (or module). But I'm sure I'm not the only one who will get confused by this.

I'm not sure what a good solution would be, but I thought I would report it as a potential source of confusion. Maybe when the compiler prints a lint warning or error, it could also print something like "Printing a warning because this is the default setting for item fn quux(...", or "Printing an error because the item class foo {... has a #[warn(err_no_cats_allowed)] attribute"?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-attributesArea: Attributes (`#[…]`, `#![…]`)A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions