diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index a5fe0c694b151..8652b6e478f57 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -910,7 +910,10 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { steps -= 1; } if steps == 0 { - msg = msg.trim_end_matches(" and dereferencing instead"); + return ( + msg.trim_end_matches(" and dereferencing instead"), + vec![(prefix_span, String::new())], + ); } let derefs = "*".repeat(steps); let needs_parens = steps > 0 @@ -933,7 +936,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { format!("{derefs}"), )] }; - suggestion.push((prefix_span, "".to_string())); + if !prefix_span.is_empty() { + suggestion.push((prefix_span, String::new())); + } (msg, suggestion) }; @@ -949,6 +954,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { suggestion, Applicability::MachineApplicable, ); + return true; } else if let Some(lsteps) = lsteps && lsteps > 0 { @@ -958,6 +964,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { suggestion, Applicability::MachineApplicable, ); + return true; } else if let Some(rsteps) = rsteps && rsteps > 0 { @@ -967,6 +974,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { suggestion, Applicability::MachineApplicable, ); + return true; } } } diff --git a/tests/ui/binop/binary-op-suggest-deref.stderr b/tests/ui/binop/binary-op-suggest-deref.stderr index 33dcb47e5c263..d65b64a059142 100644 --- a/tests/ui/binop/binary-op-suggest-deref.stderr +++ b/tests/ui/binop/binary-op-suggest-deref.stderr @@ -16,16 +16,6 @@ LL | _ = foo == 0; | ^^ no implementation for `&&{integer} == {integer}` | = help: the trait `PartialEq<{integer}>` is not implemented for `&&{integer}` - = help: the following other types implement trait `PartialEq`: - isize - i8 - i16 - i32 - i64 - i128 - usize - u8 - and 6 others help: consider dereferencing here | LL | _ = **foo == 0; @@ -38,16 +28,6 @@ LL | _ = foo == &0; | ^^ no implementation for `&{integer} == {integer}` | = help: the trait `PartialEq<{integer}>` is not implemented for `&{integer}` - = help: the following other types implement trait `PartialEq`: - isize - i8 - i16 - i32 - i64 - i128 - usize - u8 - and 6 others = note: required for `&&{integer}` to implement `PartialEq<&{integer}>` help: consider dereferencing here | @@ -61,16 +41,6 @@ LL | _ = &&&&foo == 0; | ^^ no implementation for `&&&&&&{integer} == {integer}` | = help: the trait `PartialEq<{integer}>` is not implemented for `&&&&&&{integer}` - = help: the following other types implement trait `PartialEq`: - isize - i8 - i16 - i32 - i64 - i128 - usize - u8 - and 6 others help: consider removing the borrows and dereferencing instead | LL - _ = &&&&foo == 0; @@ -84,16 +54,6 @@ LL | _ = *foo == 0; | ^^ no implementation for `&{integer} == {integer}` | = help: the trait `PartialEq<{integer}>` is not implemented for `&{integer}` - = help: the following other types implement trait `PartialEq`: - isize - i8 - i16 - i32 - i64 - i128 - usize - u8 - and 6 others help: consider dereferencing here | LL | _ = **foo == 0; @@ -106,16 +66,6 @@ LL | _ = &&foo == &&0; | ^^ no implementation for `&&{integer} == {integer}` | = help: the trait `PartialEq<{integer}>` is not implemented for `&&{integer}` - = help: the following other types implement trait `PartialEq`: - isize - i8 - i16 - i32 - i64 - i128 - usize - u8 - and 6 others = note: required for `&&&{integer}` to implement `PartialEq<&{integer}>` = note: 1 redundant requirement hidden = note: required for `&&&&{integer}` to implement `PartialEq<&&{integer}>` @@ -132,7 +82,6 @@ LL | _ = &Box::new(42) == 42; | ^^ no implementation for `&Box<{integer}> == {integer}` | = help: the trait `PartialEq<{integer}>` is not implemented for `&Box<{integer}>` - = help: the trait `PartialEq` is implemented for `Box` help: consider removing the borrow and dereferencing instead | LL - _ = &Box::new(42) == 42; @@ -146,7 +95,6 @@ LL | _ = &Box::new(&Box::new(&42)) == 42; | ^^ no implementation for `&Box<&Box<&{integer}>> == {integer}` | = help: the trait `PartialEq<{integer}>` is not implemented for `&Box<&Box<&{integer}>>` - = help: the trait `PartialEq` is implemented for `Box` help: consider removing the borrow and dereferencing instead | LL - _ = &Box::new(&Box::new(&42)) == 42; @@ -160,16 +108,6 @@ LL | _ = 0 == foo; | ^^ no implementation for `{integer} == &&{integer}` | = help: the trait `PartialEq<&&{integer}>` is not implemented for `{integer}` - = help: the following other types implement trait `PartialEq`: - isize - i8 - i16 - i32 - i64 - i128 - usize - u8 - and 6 others help: consider dereferencing here | LL | _ = 0 == **foo; @@ -182,16 +120,6 @@ LL | _ = &0 == foo; | ^^ no implementation for `{integer} == &{integer}` | = help: the trait `PartialEq<&{integer}>` is not implemented for `{integer}` - = help: the following other types implement trait `PartialEq`: - isize - i8 - i16 - i32 - i64 - i128 - usize - u8 - and 6 others = note: required for `&{integer}` to implement `PartialEq<&&{integer}>` help: consider dereferencing here | @@ -205,16 +133,6 @@ LL | _ = 0 == &&&&foo; | ^^ no implementation for `{integer} == &&&&&&{integer}` | = help: the trait `PartialEq<&&&&&&{integer}>` is not implemented for `{integer}` - = help: the following other types implement trait `PartialEq`: - isize - i8 - i16 - i32 - i64 - i128 - usize - u8 - and 6 others help: consider removing the borrows and dereferencing instead | LL - _ = 0 == &&&&foo; @@ -228,16 +146,6 @@ LL | _ = 0 == *foo; | ^^ no implementation for `{integer} == &{integer}` | = help: the trait `PartialEq<&{integer}>` is not implemented for `{integer}` - = help: the following other types implement trait `PartialEq`: - isize - i8 - i16 - i32 - i64 - i128 - usize - u8 - and 6 others help: consider dereferencing here | LL | _ = 0 == **foo; @@ -250,16 +158,6 @@ LL | _ = &&0 == &&foo; | ^^ no implementation for `{integer} == &&{integer}` | = help: the trait `PartialEq<&&{integer}>` is not implemented for `{integer}` - = help: the following other types implement trait `PartialEq`: - isize - i8 - i16 - i32 - i64 - i128 - usize - u8 - and 6 others = note: required for `&{integer}` to implement `PartialEq<&&&{integer}>` = note: 1 redundant requirement hidden = note: required for `&&{integer}` to implement `PartialEq<&&&&{integer}>` @@ -276,8 +174,6 @@ LL | _ = &Box::new(Box::new(42)) == &foo; | ^^ no implementation for `Box> == &&{integer}` | = help: the trait `PartialEq<&&{integer}>` is not implemented for `Box>` - = help: the trait `PartialEq` is implemented for `Box>` - = help: for that trait implementation, expected `Box>`, found `&&{integer}` = note: required for `&Box>` to implement `PartialEq<&&&{integer}>` help: consider dereferencing both sides | @@ -292,8 +188,6 @@ LL | _ = &Box::new(42) == &foo; | ^^ no implementation for `Box<{integer}> == &&{integer}` | = help: the trait `PartialEq<&&{integer}>` is not implemented for `Box<{integer}>` - = help: the trait `PartialEq` is implemented for `Box<{integer}>` - = help: for that trait implementation, expected `Box<{integer}>`, found `&&{integer}` = note: required for `&Box<{integer}>` to implement `PartialEq<&&&{integer}>` help: consider dereferencing both sides | @@ -308,8 +202,6 @@ LL | _ = &Box::new(Box::new(Box::new(Box::new(42)))) == &foo; | ^^ no implementation for `Box>>> == &&{integer}` | = help: the trait `PartialEq<&&{integer}>` is not implemented for `Box>>>` - = help: the trait `PartialEq` is implemented for `Box>>>` - = help: for that trait implementation, expected `Box>>>`, found `&&{integer}` = note: required for `&Box>>>` to implement `PartialEq<&&&{integer}>` help: consider dereferencing both sides | @@ -324,16 +216,6 @@ LL | _ = &foo == &Box::new(Box::new(Box::new(Box::new(42)))); | ^^ no implementation for `&&{integer} == Box>>>` | = help: the trait `PartialEq>>>>` is not implemented for `&&{integer}` - = help: the following other types implement trait `PartialEq`: - isize - i8 - i16 - i32 - i64 - i128 - usize - u8 - and 6 others = note: required for `&&&{integer}` to implement `PartialEq<&Box>>>>` help: consider dereferencing both sides | @@ -401,11 +283,6 @@ LL | _ = string_ref == partial[..3]; | ^^ no implementation for `&String == str` | = help: the trait `PartialEq` is not implemented for `&String` - = help: the following other types implement trait `PartialEq`: - >> - - > - > help: consider dereferencing here | LL | _ = *string_ref == partial[..3]; @@ -418,15 +295,6 @@ LL | _ = partial[..3] == string_ref; | ^^ no implementation for `str == &String` | = help: the trait `PartialEq<&String>` is not implemented for `str` - = help: the following other types implement trait `PartialEq`: - >> - > - > - > - - <&'a str as PartialEq> - <&'a str as PartialEq> - <&'b str as PartialEq>> help: consider dereferencing here | LL | _ = partial[..3] == *string_ref; diff --git a/tests/ui/dst/issue-113447.stderr b/tests/ui/dst/issue-113447.stderr index cd3afe2d0207d..4d0ed33a643a8 100644 --- a/tests/ui/dst/issue-113447.stderr +++ b/tests/ui/dst/issue-113447.stderr @@ -5,25 +5,11 @@ LL | let _ = &[0u8] == [0xAA]; | ^^ no implementation for `&[u8; 1] == [{integer}; 1]` | = help: the trait `PartialEq<[{integer}; 1]>` is not implemented for `&[u8; 1]` - = help: the following other types implement trait `PartialEq`: - <[A; N] as PartialEq<[B; N]>> - <[A; N] as PartialEq<[B]>> - <[A; N] as PartialEq<&[B]>> - <[A; N] as PartialEq<&mut [B]>> - <[T] as PartialEq>> - <[A] as PartialEq<[B]>> - <[B] as PartialEq<[A; N]>> - <&[u8] as PartialEq> - and 4 others help: consider removing the borrow | LL - let _ = &[0u8] == [0xAA]; LL + let _ = [0u8] == [0xAA]; | -help: convert the array to a `&[u8]` slice instead - | -LL | let _ = &[0u8] == &[0xAA][..]; - | + ++++ error: aborting due to 1 previous error