Auto merge of #54683 - zackmdavis:critique_of_pure_lints, r=petrochenkov
lint reasons (RFC 2883, part 1) This implements the `reason =` functionality described in [the RFC](https://github.com/rust-lang/rfcs/blob/master/text/2383-lint-reasons.md) under a `lint_reasons` feature gate. 
This commit is contained in:
commit
18311a6c47
12 changed files with 304 additions and 20 deletions
4
src/test/ui/feature-gates/feature-gate-lint-reasons.rs
Normal file
4
src/test/ui/feature-gates/feature-gate-lint-reasons.rs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#![warn(nonstandard_style, reason = "the standard should be respected")]
|
||||
//~^ ERROR lint reasons are experimental
|
||||
|
||||
fn main() {}
|
||||
11
src/test/ui/feature-gates/feature-gate-lint-reasons.stderr
Normal file
11
src/test/ui/feature-gates/feature-gate-lint-reasons.stderr
Normal file
|
|
@ -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`.
|
||||
17
src/test/ui/lint/empty-lint-attributes.rs
Normal file
17
src/test/ui/lint/empty-lint-attributes.rs
Normal file
|
|
@ -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() {}
|
||||
24
src/test/ui/lint/reasons-erroneous.rs
Normal file
24
src/test/ui/lint/reasons-erroneous.rs
Normal file
|
|
@ -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)]
|
||||
//~^ WARN unknown lint
|
||||
|
||||
fn main() {}
|
||||
61
src/test/ui/lint/reasons-erroneous.stderr
Normal file
61
src/test/ui/lint/reasons-erroneous.stderr
Normal file
|
|
@ -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`.
|
||||
21
src/test/ui/lint/reasons-forbidden.rs
Normal file
21
src/test/ui/lint/reasons-forbidden.rs
Normal file
|
|
@ -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
|
||||
}
|
||||
}
|
||||
14
src/test/ui/lint/reasons-forbidden.stderr
Normal file
14
src/test/ui/lint/reasons-forbidden.stderr
Normal file
|
|
@ -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`.
|
||||
33
src/test/ui/lint/reasons.rs
Normal file
33
src/test/ui/lint/reasons.rs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
// compile-pass
|
||||
|
||||
#![feature(lint_reasons)]
|
||||
|
||||
#![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
|
||||
}
|
||||
28
src/test/ui/lint/reasons.stderr
Normal file
28
src/test/ui/lint/reasons.stderr
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
warning: hidden lifetime parameters in types are deprecated
|
||||
--> $DIR/reasons.rs:21: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:5: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:30: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:9:5
|
||||
|
|
||||
LL | nonstandard_style,
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
= note: #[warn(non_snake_case)] implied by #[warn(nonstandard_style)]
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue