-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
lint reasons (RFC 2383, part 1) #54683
Changes from all commits
630c6a5
dc0609c
f90de11
f66ea66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#![warn(nonstandard_style, reason = "the standard should be respected")] | ||
//~^ ERROR lint reasons are experimental | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error[E0658]: lint reasons are experimental (see issue #54503) | ||
--> $DIR/feature-gate-lint-reasons.rs:1:28 | ||
| | ||
LL | #![warn(nonstandard_style, reason = "the standard should be respected")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: add #![feature(lint_reasons)] to the crate attributes to enable | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#![feature(lint_reasons)] | ||
|
||
// run-pass | ||
|
||
// Empty (and reason-only) lint attributes are legal—although we may want to | ||
// lint them in the future (Issue #55112). | ||
|
||
#![allow()] | ||
#![warn(reason = "observationalism")] | ||
|
||
#[forbid()] | ||
fn devoir() {} | ||
|
||
#[deny(reason = "ultion")] | ||
fn waldgrave() {} | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#![feature(lint_reasons)] | ||
|
||
#![warn(absolute_paths_not_starting_with_crate, reason = 0)] | ||
//~^ ERROR malformed lint attribute | ||
//~| HELP reason must be a string literal | ||
#![warn(anonymous_parameters, reason = b"consider these, for we have condemned them")] | ||
//~^ ERROR malformed lint attribute | ||
//~| HELP reason must be a string literal | ||
#![warn(bare_trait_objects, reasons = "leaders to no sure land, guides their bearings lost")] | ||
//~^ ERROR malformed lint attribute | ||
#![warn(box_pointers, blerp = "or in league with robbers have reversed the signposts")] | ||
//~^ ERROR malformed lint attribute | ||
#![warn(elided_lifetimes_in_paths, reason("disrespectful to ancestors", "irresponsible to heirs"))] | ||
//~^ ERROR malformed lint attribute | ||
#![warn(ellipsis_inclusive_range_patterns, reason = "born barren", reason = "a freak growth")] | ||
//~^ ERROR malformed lint attribute | ||
//~| HELP reason in lint attribute must come last | ||
#![warn(keyword_idents, reason = "root in rubble", macro_use_extern_crate)] | ||
//~^ ERROR malformed lint attribute | ||
//~| HELP reason in lint attribute must come last | ||
#![warn(missing_copy_implementations, reason)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, let's make this an error (it would have been a no-op if you hadn't pointed this out). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... well, actually, I guess I could see a case that, if empty lint attributes ( (Presumably the only sane reason for empty lint attributes to exist is for the sake of the base case of some recursive macro, and if we care about that, then we should also care about a macro that's otherwise identical but also includes a reason.) |
||
//~^ WARN unknown lint | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
error[E0452]: malformed lint attribute | ||
--> $DIR/reasons-erroneous.rs:3:58 | ||
| | ||
LL | #![warn(absolute_paths_not_starting_with_crate, reason = 0)] | ||
| ^ | ||
| | ||
= help: reason must be a string literal | ||
|
||
error[E0452]: malformed lint attribute | ||
--> $DIR/reasons-erroneous.rs:6:40 | ||
| | ||
LL | #![warn(anonymous_parameters, reason = b"consider these, for we have condemned them")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: reason must be a string literal | ||
|
||
error[E0452]: malformed lint attribute | ||
--> $DIR/reasons-erroneous.rs:9:29 | ||
| | ||
LL | #![warn(bare_trait_objects, reasons = "leaders to no sure land, guides their bearings lost")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0452]: malformed lint attribute | ||
--> $DIR/reasons-erroneous.rs:11:23 | ||
| | ||
LL | #![warn(box_pointers, blerp = "or in league with robbers have reversed the signposts")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0452]: malformed lint attribute | ||
--> $DIR/reasons-erroneous.rs:13:36 | ||
| | ||
LL | #![warn(elided_lifetimes_in_paths, reason("disrespectful to ancestors", "irresponsible to heirs"))] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0452]: malformed lint attribute | ||
--> $DIR/reasons-erroneous.rs:15:44 | ||
| | ||
LL | #![warn(ellipsis_inclusive_range_patterns, reason = "born barren", reason = "a freak growth")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: reason in lint attribute must come last | ||
|
||
error[E0452]: malformed lint attribute | ||
--> $DIR/reasons-erroneous.rs:18:25 | ||
| | ||
LL | #![warn(keyword_idents, reason = "root in rubble", macro_use_extern_crate)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: reason in lint attribute must come last | ||
|
||
warning: unknown lint: `reason` | ||
--> $DIR/reasons-erroneous.rs:21:39 | ||
| | ||
LL | #![warn(missing_copy_implementations, reason)] | ||
| ^^^^^^ | ||
| | ||
= note: #[warn(unknown_lints)] on by default | ||
|
||
error: aborting due to 7 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0452`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#![feature(lint_reasons)] | ||
|
||
#![forbid( | ||
unsafe_code, | ||
//~^ NOTE `forbid` level set here | ||
reason = "our errors & omissions insurance policy doesn't cover unsafe Rust" | ||
)] | ||
|
||
use std::ptr; | ||
|
||
fn main() { | ||
let a_billion_dollar_mistake = ptr::null(); | ||
|
||
#[allow(unsafe_code)] | ||
//~^ ERROR allow(unsafe_code) overruled by outer forbid(unsafe_code) | ||
//~| NOTE overruled by previous forbid | ||
//~| NOTE our errors & omissions insurance policy doesn't cover unsafe Rust | ||
unsafe { | ||
*a_billion_dollar_mistake | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error[E0453]: allow(unsafe_code) overruled by outer forbid(unsafe_code) | ||
--> $DIR/reasons-forbidden.rs:14:13 | ||
| | ||
LL | unsafe_code, | ||
| ----------- `forbid` level set here | ||
... | ||
LL | #[allow(unsafe_code)] | ||
| ^^^^^^^^^^^ overruled by previous forbid | ||
| | ||
= note: our errors & omissions insurance policy doesn't cover unsafe Rust | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0453`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will panic on
#[allow()]
, no?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... right. 😰 😥 💀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this trigger
unused_attributes
? (As recently discussed for empty derives and inappropriate#[must_use]
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels reasonable to me to trigger unused_attributes for empty allow; esp. if we do it for empty derives.