Skip to content

Commit

Permalink
Fix ICE
Browse files Browse the repository at this point in the history
  • Loading branch information
sjwang05 committed Nov 30, 2023
1 parent 90af6f1 commit 32d7890
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
};

Expand All @@ -949,6 +954,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
suggestion,
Applicability::MachineApplicable,
);
return true;
} else if let Some(lsteps) = lsteps
&& lsteps > 0
{
Expand All @@ -958,6 +964,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
suggestion,
Applicability::MachineApplicable,
);
return true;
} else if let Some(rsteps) = rsteps
&& rsteps > 0
{
Expand All @@ -967,6 +974,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
suggestion,
Applicability::MachineApplicable,
);
return true;
}
}
}
Expand Down
132 changes: 0 additions & 132 deletions tests/ui/binop/binary-op-suggest-deref.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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<Rhs>`:
isize
i8
i16
i32
i64
i128
usize
u8
and 6 others
help: consider dereferencing here
|
LL | _ = **foo == 0;
Expand All @@ -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<Rhs>`:
isize
i8
i16
i32
i64
i128
usize
u8
and 6 others
= note: required for `&&{integer}` to implement `PartialEq<&{integer}>`
help: consider dereferencing here
|
Expand All @@ -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<Rhs>`:
isize
i8
i16
i32
i64
i128
usize
u8
and 6 others
help: consider removing the borrows and dereferencing instead
|
LL - _ = &&&&foo == 0;
Expand All @@ -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<Rhs>`:
isize
i8
i16
i32
i64
i128
usize
u8
and 6 others
help: consider dereferencing here
|
LL | _ = **foo == 0;
Expand All @@ -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<Rhs>`:
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}>`
Expand All @@ -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<T, A>`
help: consider removing the borrow and dereferencing instead
|
LL - _ = &Box::new(42) == 42;
Expand All @@ -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<T, A>`
help: consider removing the borrow and dereferencing instead
|
LL - _ = &Box::new(&Box::new(&42)) == 42;
Expand All @@ -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<Rhs>`:
isize
i8
i16
i32
i64
i128
usize
u8
and 6 others
help: consider dereferencing here
|
LL | _ = 0 == **foo;
Expand All @@ -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<Rhs>`:
isize
i8
i16
i32
i64
i128
usize
u8
and 6 others
= note: required for `&{integer}` to implement `PartialEq<&&{integer}>`
help: consider dereferencing here
|
Expand All @@ -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<Rhs>`:
isize
i8
i16
i32
i64
i128
usize
u8
and 6 others
help: consider removing the borrows and dereferencing instead
|
LL - _ = 0 == &&&&foo;
Expand All @@ -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<Rhs>`:
isize
i8
i16
i32
i64
i128
usize
u8
and 6 others
help: consider dereferencing here
|
LL | _ = 0 == **foo;
Expand All @@ -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<Rhs>`:
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}>`
Expand All @@ -276,8 +174,6 @@ LL | _ = &Box::new(Box::new(42)) == &foo;
| ^^ 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<Box<{integer}>>`
= help: for that trait implementation, expected `Box<Box<{integer}>>`, found `&&{integer}`
= note: required for `&Box<Box<{integer}>>` to implement `PartialEq<&&&{integer}>`
help: consider dereferencing both sides
|
Expand All @@ -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
|
Expand All @@ -308,8 +202,6 @@ LL | _ = &Box::new(Box::new(Box::new(Box::new(42)))) == &foo;
| ^^ no implementation for `Box<Box<Box<Box<{integer}>>>> == &&{integer}`
|
= help: the trait `PartialEq<&&{integer}>` is not implemented for `Box<Box<Box<Box<{integer}>>>>`
= help: the trait `PartialEq` is implemented for `Box<Box<Box<Box<{integer}>>>>`
= help: for that trait implementation, expected `Box<Box<Box<Box<{integer}>>>>`, found `&&{integer}`
= note: required for `&Box<Box<Box<Box<{integer}>>>>` to implement `PartialEq<&&&{integer}>`
help: consider dereferencing both sides
|
Expand All @@ -324,16 +216,6 @@ LL | _ = &foo == &Box::new(Box::new(Box::new(Box::new(42))));
| ^^ no implementation for `&&{integer} == Box<Box<Box<Box<{integer}>>>>`
|
= help: the trait `PartialEq<Box<Box<Box<Box<{integer}>>>>>` is not implemented for `&&{integer}`
= help: the following other types implement trait `PartialEq<Rhs>`:
isize
i8
i16
i32
i64
i128
usize
u8
and 6 others
= note: required for `&&&{integer}` to implement `PartialEq<&Box<Box<Box<Box<{integer}>>>>>`
help: consider dereferencing both sides
|
Expand Down Expand Up @@ -401,11 +283,6 @@ LL | _ = string_ref == partial[..3];
| ^^ no implementation for `&String == str`
|
= help: the trait `PartialEq<str>` is not implemented for `&String`
= help: the following other types implement trait `PartialEq<Rhs>`:
<String as PartialEq<Cow<'a, str>>>
<String as PartialEq>
<String as PartialEq<str>>
<String as PartialEq<&'a str>>
help: consider dereferencing here
|
LL | _ = *string_ref == partial[..3];
Expand All @@ -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<Rhs>`:
<str as PartialEq<Cow<'a, str>>>
<str as PartialEq<OsString>>
<str as PartialEq<OsStr>>
<str as PartialEq<String>>
<str as PartialEq>
<&'a str as PartialEq<OsString>>
<&'a str as PartialEq<String>>
<&'b str as PartialEq<Cow<'a, str>>>
help: consider dereferencing here
|
LL | _ = partial[..3] == *string_ref;
Expand Down
14 changes: 0 additions & 14 deletions tests/ui/dst/issue-113447.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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<Rhs>`:
<[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<Vec<U, A>>>
<[A] as PartialEq<[B]>>
<[B] as PartialEq<[A; N]>>
<&[u8] as PartialEq<Bytes>>
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

Expand Down

0 comments on commit 32d7890

Please sign in to comment.