forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introducing lint reason annotations (RFC 2383)
This is just for the `reason =` name-value meta-item; the `#[expect(lint)]` attribute also described in the RFC is a problem for another day. The place where we were directly calling `emit()` on a match block (whose arms returned a mutable reference to a diagnostic-builder) was admittedly cute, but no longer plausibly natural after adding the if-let to the end of the `LintSource::Node` arm. This regards rust-lang#54503.
- Loading branch information
1 parent
f32f111
commit 630c6a5
Showing
8 changed files
with
211 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#![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)] | ||
//~^ WARN unknown lint | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
error[E0452]: malformed lint attribute | ||
--> $DIR/reasons-erroneous.rs:1: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:4: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:7: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:9:23 | ||
| | ||
LL | #![warn(box_pointers, blerp = "or in league with robbers have reversed the signposts")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0452]: malformed lint attribute | ||
--> $DIR/reasons-erroneous.rs:11:36 | ||
| | ||
LL | #![warn(elided_lifetimes_in_paths, reason("disrespectful to ancestors", "irresponsible to heirs"))] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: unknown lint: `reason` | ||
--> $DIR/reasons-erroneous.rs:13:44 | ||
| | ||
LL | #![warn(ellipsis_inclusive_range_patterns, reason)] | ||
| ^^^^^^ | ||
| | ||
= note: #[warn(unknown_lints)] on by default | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0452`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#![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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:12: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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// compile-pass | ||
|
||
#![warn(elided_lifetimes_in_paths, | ||
//~^ NOTE lint level defined here | ||
reason = "explicit anonymous lifetimes aid reasoning about ownership")] | ||
#![warn( | ||
nonstandard_style, | ||
//~^ NOTE lint level defined here | ||
reason = r#"people shouldn't have to change their usual style habits | ||
to contribute to our project"# | ||
)] | ||
#![allow(unused, reason = "unused code has never killed anypony")] | ||
|
||
use std::fmt; | ||
|
||
pub struct CheaterDetectionMechanism {} | ||
|
||
impl fmt::Debug for CheaterDetectionMechanism { | ||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||
//~^ WARN hidden lifetime parameters in types are deprecated | ||
//~| NOTE explicit anonymous lifetimes aid | ||
//~| HELP indicate the anonymous lifetime | ||
fmt.debug_struct("CheaterDetectionMechanism").finish() | ||
} | ||
} | ||
|
||
fn main() { | ||
let Social_exchange_psychology = CheaterDetectionMechanism {}; | ||
//~^ WARN should have a snake case name such as | ||
//~| NOTE people shouldn't have to change their usual style habits | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
warning: hidden lifetime parameters in types are deprecated | ||
--> $DIR/reasons.rs:19:29 | ||
| | ||
LL | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||
| ^^^^^^^^^^^^^^- help: indicate the anonymous lifetime: `<'_>` | ||
| | ||
= note: explicit anonymous lifetimes aid reasoning about ownership | ||
note: lint level defined here | ||
--> $DIR/reasons.rs:3:9 | ||
| | ||
LL | #![warn(elided_lifetimes_in_paths, | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: variable `Social_exchange_psychology` should have a snake case name such as `social_exchange_psychology` | ||
--> $DIR/reasons.rs:28:9 | ||
| | ||
LL | let Social_exchange_psychology = CheaterDetectionMechanism {}; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: people shouldn't have to change their usual style habits | ||
to contribute to our project | ||
note: lint level defined here | ||
--> $DIR/reasons.rs:7:5 | ||
| | ||
LL | nonstandard_style, | ||
| ^^^^^^^^^^^^^^^^^ | ||
= note: #[warn(non_snake_case)] implied by #[warn(nonstandard_style)] | ||
|