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 #54503.
This commit is contained in:
Zack M. Davis 2018-09-29 17:25:26 -07:00
parent f32f1113c9
commit 630c6a544f
8 changed files with 211 additions and 20 deletions

View file

@ -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() {}

View file

@ -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`.

View file

@ -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
}
}

View file

@ -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`.

View file

@ -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
}

View file

@ -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)]