Skip to content

Commit d9ef5b9

Browse files
committed
fix method receiver lint test cases
1 parent 6fab4ea commit d9ef5b9

9 files changed

Lines changed: 33 additions & 18 deletions

library/core/src/num/f128.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@ impl f128 {
13231323
/// assert!((-3.0f128).clamp(-2.0, 1.0) == -2.0);
13241324
/// assert!((0.0f128).clamp(-2.0, 1.0) == 0.0);
13251325
/// assert!((2.0f128).clamp(-2.0, 1.0) == 1.0);
1326-
/// assert!((f128::NAN).clamp(-2.0, 1.0).is_nan());
1326+
/// assert!(f128::NAN.clamp(-2.0, 1.0).is_nan());
13271327
///
13281328
/// // These always returns zero, but the sign (which is ignored by `==`) is non-deterministic.
13291329
/// assert!((0.0f128).clamp(-0.0, -0.0) == 0.0);

library/core/src/num/f16.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,7 @@ impl f16 {
13071307
/// assert!((-3.0f16).clamp(-2.0, 1.0) == -2.0);
13081308
/// assert!((0.0f16).clamp(-2.0, 1.0) == 0.0);
13091309
/// assert!((2.0f16).clamp(-2.0, 1.0) == 1.0);
1310-
/// assert!((f16::NAN).clamp(-2.0, 1.0).is_nan());
1310+
/// assert!(f16::NAN.clamp(-2.0, 1.0).is_nan());
13111311
///
13121312
/// // These always returns zero, but the sign (which is ignored by `==`) is non-deterministic.
13131313
/// assert!((0.0f16).clamp(-0.0, -0.0) == 0.0);

library/core/src/num/f32.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,7 @@ impl f32 {
14891489
/// assert!((-3.0f32).clamp(-2.0, 1.0) == -2.0);
14901490
/// assert!((0.0f32).clamp(-2.0, 1.0) == 0.0);
14911491
/// assert!((2.0f32).clamp(-2.0, 1.0) == 1.0);
1492-
/// assert!((f32::NAN).clamp(-2.0, 1.0).is_nan());
1492+
/// assert!(f32::NAN.clamp(-2.0, 1.0).is_nan());
14931493
///
14941494
/// // These always returns zero, but the sign (which is ignored by `==`) is non-deterministic.
14951495
/// assert!((0.0f32).clamp(-0.0, -0.0) == 0.0);

library/core/src/num/f64.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,7 @@ impl f64 {
14871487
/// assert!((-3.0f64).clamp(-2.0, 1.0) == -2.0);
14881488
/// assert!((0.0f64).clamp(-2.0, 1.0) == 0.0);
14891489
/// assert!((2.0f64).clamp(-2.0, 1.0) == 1.0);
1490-
/// assert!((f64::NAN).clamp(-2.0, 1.0).is_nan());
1490+
/// assert!(f64::NAN.clamp(-2.0, 1.0).is_nan());
14911491
///
14921492
/// // These always returns zero, but the sign (which is ignored by `==`) is non-deterministic.
14931493
/// assert!((0.0f64).clamp(-0.0, -0.0) == 0.0);

library/core/src/num/int_macros.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2570,7 +2570,7 @@ macro_rules! int_impl {
25702570
///
25712571
/// ```
25722572
#[doc = concat!("assert_eq!(1", stringify!($SelfT), ".overflowing_add_unsigned(2), (3, false));")]
2573-
#[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN).overflowing_add_unsigned(", stringify!($UnsignedT), "::MAX), (", stringify!($SelfT), "::MAX, false));")]
2573+
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.overflowing_add_unsigned(", stringify!($UnsignedT), "::MAX), (", stringify!($SelfT), "::MAX, false));")]
25742574
#[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX - 2).overflowing_add_unsigned(3), (", stringify!($SelfT), "::MIN, true));")]
25752575
/// ```
25762576
#[stable(feature = "mixed_integer_ops", since = "1.66.0")]
@@ -2677,7 +2677,7 @@ macro_rules! int_impl {
26772677
///
26782678
/// ```
26792679
#[doc = concat!("assert_eq!(1", stringify!($SelfT), ".overflowing_sub_unsigned(2), (-1, false));")]
2680-
#[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX).overflowing_sub_unsigned(", stringify!($UnsignedT), "::MAX), (", stringify!($SelfT), "::MIN, false));")]
2680+
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.overflowing_sub_unsigned(", stringify!($UnsignedT), "::MAX), (", stringify!($SelfT), "::MIN, false));")]
26812681
#[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 2).overflowing_sub_unsigned(3), (", stringify!($SelfT), "::MAX, true));")]
26822682
/// ```
26832683
#[stable(feature = "mixed_integer_ops", since = "1.66.0")]
@@ -3010,7 +3010,7 @@ macro_rules! int_impl {
30103010
/// ```
30113011
#[doc = concat!("assert_eq!(10", stringify!($SelfT), ".overflowing_abs(), (10, false));")]
30123012
#[doc = concat!("assert_eq!((-10", stringify!($SelfT), ").overflowing_abs(), (10, false));")]
3013-
#[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN).overflowing_abs(), (", stringify!($SelfT), "::MIN, true));")]
3013+
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.overflowing_abs(), (", stringify!($SelfT), "::MIN, true));")]
30143014
/// ```
30153015
#[stable(feature = "no_panic_abs", since = "1.13.0")]
30163016
#[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]

library/core/src/num/uint_macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ macro_rules! uint_impl {
11251125
/// ```
11261126
///
11271127
/// ```should_panic
1128-
#[doc = concat!("let _ = (", stringify!($SelfT), "::MAX).strict_sub_signed(-1);")]
1128+
#[doc = concat!("let _ = ", stringify!($SelfT), "::MAX.strict_sub_signed(-1);")]
11291129
/// ```
11301130
#[stable(feature = "strict_overflow_ops", since = "1.91.0")]
11311131
#[rustc_const_stable(feature = "strict_overflow_ops", since = "1.91.0")]
@@ -2433,7 +2433,7 @@ macro_rules! uint_impl {
24332433
///
24342434
/// ```
24352435
#[doc = concat!("assert_eq!(2", stringify!($SelfT), ".saturating_mul(10), 20);")]
2436-
#[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX).saturating_mul(10), ", stringify!($SelfT),"::MAX);")]
2436+
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.saturating_mul(10), ", stringify!($SelfT),"::MAX);")]
24372437
/// ```
24382438
#[stable(feature = "wrapping", since = "1.7.0")]
24392439
#[rustc_const_stable(feature = "const_saturating_int_methods", since = "1.47.0")]

tests/ui/lint/unused-parens-method-receiver-issue-151985.fixed

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@ fn main() {
1313
x.method(); //~ ERROR unnecessary parentheses around method receiver
1414

1515
// Necessary parens - should NOT warn
16-
let _ = (1..10).sum::<i32>(); // Range expression
17-
let _ = (1_i32 + 2).abs(); // Binary expression
18-
let _ = (-1_i32).abs(); // Unary expression
19-
let _ = (true as i32).abs(); // Cast expression
20-
let _ = (&42).clone(); // AddrOf expression
21-
let _ = (&mut 42).clone(); // AddrOf mut expression
16+
let _ = (1..10).sum::<i32>(); // Range expression
17+
let _ = (1_i32 + 2).abs(); // Binary expression
18+
let _ = (-1_i32).abs(); // Unary expression
19+
let _ = (true as i32).abs(); // Cast expression
20+
let _ = (&42).clone(); // AddrOf expression
21+
let _ = (&mut 42).clone(); // AddrOf mut expression
2222

2323
// Block expressions - should NOT warn
24-
let _ = ({ 1_i32 }).abs(); // Block expression
24+
let _ = ({ 1_i32 }).abs(); // Block expression
2525
let _ = (unsafe { std::mem::zeroed::<i32>() }).abs(); // Unsafe block expression
26+
27+
// lint for path with multiple segments
28+
let _ = std::cmp::Ordering::Equal.is_eq(); //~ ERROR unnecessary parentheses around method receiver
2629
}

tests/ui/lint/unused-parens-method-receiver-issue-151985.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ fn main() {
2525
let _ = (unsafe { std::mem::zeroed::<i32>() }).abs(); // Unsafe block expression
2626

2727
// lint for path with multiple segments
28-
let _ = (Float::MIN_POSITIVE).midpoint(-Float::MAX);
28+
let _ = (std::cmp::Ordering::Equal).is_eq(); //~ ERROR unnecessary parentheses around method receiver
2929
}

tests/ui/lint/unused-parens-method-receiver-issue-151985.stderr

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,17 @@ LL - (x).method();
1515
LL + x.method();
1616
|
1717

18-
error: aborting due to 1 previous error
18+
error: unnecessary parentheses around method receiver
19+
--> $DIR/unused-parens-method-receiver-issue-151985.rs:28:13
20+
|
21+
LL | let _ = (std::cmp::Ordering::Equal).is_eq();
22+
| ^ ^
23+
|
24+
help: remove these parentheses
25+
|
26+
LL - let _ = (std::cmp::Ordering::Equal).is_eq();
27+
LL + let _ = std::cmp::Ordering::Equal.is_eq();
28+
|
29+
30+
error: aborting due to 2 previous errors
1931

0 commit comments

Comments
 (0)