Rust-clippy: Lint wrong usage of known attributes - spotlight: no_std

Created on 18 Feb 2019  Â·  3Comments  Â·  Source: rust-lang/rust-clippy

When compiling a no_std crate it already happened multiple times that I forgot the ! after the # in #![no_std] (or similar) attribute specifiers making it a useless #[no_std] causing compilation troubles because I accidentally pulled std due to this. The compiler doesn't warn for misusage of known attributes like no_std and I am not sure if it should. But it would be awesome to have a clippy lint for this situation! Would have saved me hours of debugging already - ashamed.

Most helpful comment

This should be an error from the compiler, yes.
We are currently lacking a centralized infra for reporting attributes applied to wrong targets though, so these errors are reported very irregularly.
I hope to implement something like https://github.com/rust-lang/rust/pull/57321, but for attribute targets, some time, so this may be fixed in rustc in the future.

All 3 comments

This is surprising, the compiler errors (or used to error?) for this kind
of mistake in many cases.

But yeah we should def catch any cases like this in clippy, in case we
don't just make this a part of the compiler.

On Mon, Feb 18, 2019, 7:03 PM Hero Bird <[email protected] wrote:

When compiling a no_std crate it already happened multiple times that I
forgot the ! after the # in #![no_std] (or similar) attribute specifiers
causing compilation troubles because I accidentally pulled std due to this.
The compiler doesn't warn for misusage of known attributes like no_std
and I am not sure if it should. But it would be awesome to have a clippy
lint for this situation! Would have saved me hours of debugging already -
ashamed.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/rust-lang/rust-clippy/issues/3782, or mute the thread
https://github.com/notifications/unsubscribe-auth/ABivSB9v0fj5Do_SsBYKDbiXisyreZKJks5vOquMgaJpZM4bA4C0
.

A similar lint is empty_line_after_outer_attr, but I think you had it directly above an item without any newlines, right?

This should be an error from the compiler, yes.
We are currently lacking a centralized infra for reporting attributes applied to wrong targets though, so these errors are reported very irregularly.
I hope to implement something like https://github.com/rust-lang/rust/pull/57321, but for attribute targets, some time, so this may be fixed in rustc in the future.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

matthiaskrgr picture matthiaskrgr  Â·  3Comments

spease picture spease  Â·  3Comments

Luro02 picture Luro02  Â·  3Comments

Riateche picture Riateche  Â·  3Comments

matthiaskrgr picture matthiaskrgr  Â·  3Comments