Skip to content
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

Make UI test annotations mandatory #11421

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion tests/compile-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fn base_config(test_dir: &str) -> (Config, Args) {
..Config::rustc(Path::new("tests").join(test_dir))
};
config.comment_defaults.base().exit_status = None.into();
config.comment_defaults.base().require_annotations = None.into();
config.comment_defaults.base().require_annotations = Some(Spanned::dummy(true)).into();
config
.comment_defaults
.base()
Expand Down
37 changes: 18 additions & 19 deletions tests/ui/absurd-extreme-comparisons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,45 @@ fn main() {
const Z: u32 = 0;
let u: u32 = 42;
u <= 0;
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
//~^ absurd_extreme_comparisons
u <= Z;
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
//~^ absurd_extreme_comparisons
u < Z;
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
//~^ absurd_extreme_comparisons
Z >= u;
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
//~^ absurd_extreme_comparisons
Z > u;
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
//~^ absurd_extreme_comparisons
u > u32::MAX;
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
//~^ absurd_extreme_comparisons
u >= u32::MAX;
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
//~^ absurd_extreme_comparisons
u32::MAX < u;
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
//~^ absurd_extreme_comparisons
u32::MAX <= u;
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
//~^ absurd_extreme_comparisons
1-1 > u;
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
//~^ absurd_extreme_comparisons
u >= !0;
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
//~^ absurd_extreme_comparisons
u <= 12 - 2*6;
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
//~^ absurd_extreme_comparisons
let i: i8 = 0;
i < -127 - 1;
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
//~^ absurd_extreme_comparisons
i8::MAX >= i;
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
//~^ absurd_extreme_comparisons
3-7 < i32::MIN;
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
//~^ absurd_extreme_comparisons
let b = false;
b >= true;
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
//~^ absurd_extreme_comparisons
false > b;
//~^ ERROR: this comparison involving the minimum or maximum element for this type con
//~^ absurd_extreme_comparisons
u > 0; // ok
// this is handled by clippy::unit_cmp
() < {};
//~^ ERROR: <-comparison of unit values detected. This will always be false
//~| NOTE: `#[deny(clippy::unit_cmp)]` on by default
//~^ unit_cmp
}

use std::cmp::{Ordering, PartialEq, PartialOrd};
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/allow_attributes.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use proc_macros::{external, with_span};

// Should lint
#[expect(dead_code)]
//~^ allow_attributes
struct T1;

struct T2; // Should not lint
Expand All @@ -19,6 +20,7 @@ struct T3;
struct T4;
// `panic = "unwind"` should always be true
#[cfg_attr(panic = "unwind", expect(dead_code))]
//~^ allow_attributes
struct CfgT;

#[allow(clippy::allow_attributes, unused)]
Expand Down Expand Up @@ -50,6 +52,8 @@ fn ignore_inner_attr() {
#[clippy::msrv = "1.81"]
fn msrv_1_81() {
#[expect(unused)]
//~^ allow_attributes
//~| allow_attributes
let x = 1;
}

Expand Down
4 changes: 4 additions & 0 deletions tests/ui/allow_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use proc_macros::{external, with_span};

// Should lint
#[allow(dead_code)]
//~^ allow_attributes
struct T1;

struct T2; // Should not lint
Expand All @@ -19,6 +20,7 @@ struct T3;
struct T4;
// `panic = "unwind"` should always be true
#[cfg_attr(panic = "unwind", allow(dead_code))]
//~^ allow_attributes
struct CfgT;

#[allow(clippy::allow_attributes, unused)]
Expand Down Expand Up @@ -50,6 +52,8 @@ fn ignore_inner_attr() {
#[clippy::msrv = "1.81"]
fn msrv_1_81() {
#[allow(unused)]
//~^ allow_attributes
//~| allow_attributes
let x = 1;
}

Expand Down
6 changes: 3 additions & 3 deletions tests/ui/allow_attributes.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ LL | #[allow(dead_code)]
= help: to override `-D warnings` add `#[allow(clippy::allow_attributes)]`

error: #[allow] attribute found
--> tests/ui/allow_attributes.rs:21:30
--> tests/ui/allow_attributes.rs:22:30
|
LL | #[cfg_attr(panic = "unwind", allow(dead_code))]
| ^^^^^ help: replace it with: `expect`

error: #[allow] attribute found
--> tests/ui/allow_attributes.rs:52:7
--> tests/ui/allow_attributes.rs:54:7
|
LL | #[allow(unused)]
| ^^^^^ help: replace it with: `expect`

error: #[allow] attribute found
--> tests/ui/allow_attributes.rs:52:7
--> tests/ui/allow_attributes.rs:54:7
|
LL | #[allow(unused)]
| ^^^^^ help: replace it with: `expect`
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/allow_attributes_without_reason.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
#![deny(clippy::allow_attributes_without_reason)]
#![allow(unfulfilled_lint_expectations, clippy::duplicated_attributes)]


extern crate proc_macros;
use proc_macros::{external, with_span};

// These should trigger the lint
#[allow(dead_code)]

#[allow(dead_code, deprecated)]

#[expect(dead_code)]

// These should be fine
#[allow(dead_code, reason = "This should be allowed")]
#[warn(dyn_drop, reason = "Warnings can also have reasons")]
Expand Down Expand Up @@ -45,6 +49,8 @@ pub fn trigger_fp_result() -> Result<(), &'static str> {
#[clippy::msrv = "1.81"]
fn msrv_1_81() {
#[allow(unused)]


let _ = 1;
}

Expand Down
10 changes: 5 additions & 5 deletions tests/ui/allow_attributes_without_reason.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,39 @@ LL | #![deny(clippy::allow_attributes_without_reason)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: `allow` attribute without specifying a reason
--> tests/ui/allow_attributes_without_reason.rs:9:1
--> tests/ui/allow_attributes_without_reason.rs:10:1
|
LL | #[allow(dead_code)]
| ^^^^^^^^^^^^^^^^^^^
|
= help: try adding a reason at the end with `, reason = ".."`

error: `allow` attribute without specifying a reason
--> tests/ui/allow_attributes_without_reason.rs:10:1
--> tests/ui/allow_attributes_without_reason.rs:12:1
|
LL | #[allow(dead_code, deprecated)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: try adding a reason at the end with `, reason = ".."`

error: `expect` attribute without specifying a reason
--> tests/ui/allow_attributes_without_reason.rs:11:1
--> tests/ui/allow_attributes_without_reason.rs:14:1
|
LL | #[expect(dead_code)]
| ^^^^^^^^^^^^^^^^^^^^
|
= help: try adding a reason at the end with `, reason = ".."`

error: `allow` attribute without specifying a reason
--> tests/ui/allow_attributes_without_reason.rs:47:5
--> tests/ui/allow_attributes_without_reason.rs:51:5
|
LL | #[allow(unused)]
| ^^^^^^^^^^^^^^^^
|
= help: try adding a reason at the end with `, reason = ".."`

error: `allow` attribute without specifying a reason
--> tests/ui/allow_attributes_without_reason.rs:47:5
--> tests/ui/allow_attributes_without_reason.rs:51:5
|
LL | #[allow(unused)]
| ^^^^^^^^^^^^^^^^
Expand Down
27 changes: 27 additions & 0 deletions tests/ui/almost_complete_range.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,42 @@ fn main() {
#[rustfmt::skip]
{
let _ = ('a') ..='z';
//~^ almost_complete_range
let _ = 'A' ..= ('Z');
//~^ almost_complete_range
let _ = ((('0'))) ..= ('9');
//~^ almost_complete_range
}

let _ = 'b'..'z';
let _ = 'B'..'Z';
let _ = '1'..'9';

let _ = (b'a')..=(b'z');
//~^ almost_complete_range
let _ = b'A'..=b'Z';
//~^ almost_complete_range
let _ = b'0'..=b'9';
//~^ almost_complete_range

let _ = b'b'..b'z';
let _ = b'B'..b'Z';
let _ = b'1'..b'9';

let _ = inline!('a')..='z';
//~^ almost_complete_range
let _ = inline!('A')..='Z';
//~^ almost_complete_range
let _ = inline!('0')..='9';
//~^ almost_complete_range

let _ = match 0u8 {
b'a'..=b'z' if true => 1,
//~^ almost_complete_range
b'A'..=b'Z' if true => 2,
//~^ almost_complete_range
b'0'..=b'9' if true => 3,
//~^ almost_complete_range
b'b'..b'z' => 4,
b'B'..b'Z' => 5,
b'1'..b'9' => 6,
Expand All @@ -47,8 +59,11 @@ fn main() {

let _ = match 'x' {
'a'..='z' if true => 1,
//~^ almost_complete_range
'A'..='Z' if true => 2,
//~^ almost_complete_range
'0'..='9' if true => 3,
//~^ almost_complete_range
'b'..'z' => 4,
'B'..'Z' => 5,
'1'..'9' => 6,
Expand All @@ -62,30 +77,42 @@ fn main() {
);
inline!(
let _ = 'a'..='z';
//~^ almost_complete_range
let _ = 'A'..='Z';
//~^ almost_complete_range
let _ = '0'..='9';
//~^ almost_complete_range
);
}

#[clippy::msrv = "1.25"]
fn _under_msrv() {
let _ = match 'a' {
'a'...'z' => 1,
//~^ almost_complete_range
'A'...'Z' => 2,
//~^ almost_complete_range
'0'...'9' => 3,
//~^ almost_complete_range
_ => 4,
};
}

#[clippy::msrv = "1.26"]
fn _meets_msrv() {
let _ = 'a'..='z';
//~^ almost_complete_range
let _ = 'A'..='Z';
//~^ almost_complete_range
let _ = '0'..='9';
//~^ almost_complete_range
let _ = match 'a' {
'a'..='z' => 1,
//~^ almost_complete_range
'A'..='Z' => 1,
//~^ almost_complete_range
'0'..='9' => 3,
//~^ almost_complete_range
_ => 4,
};
}
Loading
Loading