Skip to content

Commit 32d7890

Browse files
committed
Fix ICE
1 parent 90af6f1 commit 32d7890

File tree

3 files changed

+10
-148
lines changed

3 files changed

+10
-148
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,10 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
910910
steps -= 1;
911911
}
912912
if steps == 0 {
913-
msg = msg.trim_end_matches(" and dereferencing instead");
913+
return (
914+
msg.trim_end_matches(" and dereferencing instead"),
915+
vec![(prefix_span, String::new())],
916+
);
914917
}
915918
let derefs = "*".repeat(steps);
916919
let needs_parens = steps > 0
@@ -933,7 +936,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
933936
format!("{derefs}"),
934937
)]
935938
};
936-
suggestion.push((prefix_span, "".to_string()));
939+
if !prefix_span.is_empty() {
940+
suggestion.push((prefix_span, String::new()));
941+
}
937942
(msg, suggestion)
938943
};
939944

@@ -949,6 +954,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
949954
suggestion,
950955
Applicability::MachineApplicable,
951956
);
957+
return true;
952958
} else if let Some(lsteps) = lsteps
953959
&& lsteps > 0
954960
{
@@ -958,6 +964,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
958964
suggestion,
959965
Applicability::MachineApplicable,
960966
);
967+
return true;
961968
} else if let Some(rsteps) = rsteps
962969
&& rsteps > 0
963970
{
@@ -967,6 +974,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
967974
suggestion,
968975
Applicability::MachineApplicable,
969976
);
977+
return true;
970978
}
971979
}
972980
}

tests/ui/binop/binary-op-suggest-deref.stderr

-132
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,6 @@ LL | _ = foo == 0;
1616
| ^^ no implementation for `&&{integer} == {integer}`
1717
|
1818
= help: the trait `PartialEq<{integer}>` is not implemented for `&&{integer}`
19-
= help: the following other types implement trait `PartialEq<Rhs>`:
20-
isize
21-
i8
22-
i16
23-
i32
24-
i64
25-
i128
26-
usize
27-
u8
28-
and 6 others
2919
help: consider dereferencing here
3020
|
3121
LL | _ = **foo == 0;
@@ -38,16 +28,6 @@ LL | _ = foo == &0;
3828
| ^^ no implementation for `&{integer} == {integer}`
3929
|
4030
= help: the trait `PartialEq<{integer}>` is not implemented for `&{integer}`
41-
= help: the following other types implement trait `PartialEq<Rhs>`:
42-
isize
43-
i8
44-
i16
45-
i32
46-
i64
47-
i128
48-
usize
49-
u8
50-
and 6 others
5131
= note: required for `&&{integer}` to implement `PartialEq<&{integer}>`
5232
help: consider dereferencing here
5333
|
@@ -61,16 +41,6 @@ LL | _ = &&&&foo == 0;
6141
| ^^ no implementation for `&&&&&&{integer} == {integer}`
6242
|
6343
= help: the trait `PartialEq<{integer}>` is not implemented for `&&&&&&{integer}`
64-
= help: the following other types implement trait `PartialEq<Rhs>`:
65-
isize
66-
i8
67-
i16
68-
i32
69-
i64
70-
i128
71-
usize
72-
u8
73-
and 6 others
7444
help: consider removing the borrows and dereferencing instead
7545
|
7646
LL - _ = &&&&foo == 0;
@@ -84,16 +54,6 @@ LL | _ = *foo == 0;
8454
| ^^ no implementation for `&{integer} == {integer}`
8555
|
8656
= help: the trait `PartialEq<{integer}>` is not implemented for `&{integer}`
87-
= help: the following other types implement trait `PartialEq<Rhs>`:
88-
isize
89-
i8
90-
i16
91-
i32
92-
i64
93-
i128
94-
usize
95-
u8
96-
and 6 others
9757
help: consider dereferencing here
9858
|
9959
LL | _ = **foo == 0;
@@ -106,16 +66,6 @@ LL | _ = &&foo == &&0;
10666
| ^^ no implementation for `&&{integer} == {integer}`
10767
|
10868
= help: the trait `PartialEq<{integer}>` is not implemented for `&&{integer}`
109-
= help: the following other types implement trait `PartialEq<Rhs>`:
110-
isize
111-
i8
112-
i16
113-
i32
114-
i64
115-
i128
116-
usize
117-
u8
118-
and 6 others
11969
= note: required for `&&&{integer}` to implement `PartialEq<&{integer}>`
12070
= note: 1 redundant requirement hidden
12171
= note: required for `&&&&{integer}` to implement `PartialEq<&&{integer}>`
@@ -132,7 +82,6 @@ LL | _ = &Box::new(42) == 42;
13282
| ^^ no implementation for `&Box<{integer}> == {integer}`
13383
|
13484
= help: the trait `PartialEq<{integer}>` is not implemented for `&Box<{integer}>`
135-
= help: the trait `PartialEq` is implemented for `Box<T, A>`
13685
help: consider removing the borrow and dereferencing instead
13786
|
13887
LL - _ = &Box::new(42) == 42;
@@ -146,7 +95,6 @@ LL | _ = &Box::new(&Box::new(&42)) == 42;
14695
| ^^ no implementation for `&Box<&Box<&{integer}>> == {integer}`
14796
|
14897
= help: the trait `PartialEq<{integer}>` is not implemented for `&Box<&Box<&{integer}>>`
149-
= help: the trait `PartialEq` is implemented for `Box<T, A>`
15098
help: consider removing the borrow and dereferencing instead
15199
|
152100
LL - _ = &Box::new(&Box::new(&42)) == 42;
@@ -160,16 +108,6 @@ LL | _ = 0 == foo;
160108
| ^^ no implementation for `{integer} == &&{integer}`
161109
|
162110
= help: the trait `PartialEq<&&{integer}>` is not implemented for `{integer}`
163-
= help: the following other types implement trait `PartialEq<Rhs>`:
164-
isize
165-
i8
166-
i16
167-
i32
168-
i64
169-
i128
170-
usize
171-
u8
172-
and 6 others
173111
help: consider dereferencing here
174112
|
175113
LL | _ = 0 == **foo;
@@ -182,16 +120,6 @@ LL | _ = &0 == foo;
182120
| ^^ no implementation for `{integer} == &{integer}`
183121
|
184122
= help: the trait `PartialEq<&{integer}>` is not implemented for `{integer}`
185-
= help: the following other types implement trait `PartialEq<Rhs>`:
186-
isize
187-
i8
188-
i16
189-
i32
190-
i64
191-
i128
192-
usize
193-
u8
194-
and 6 others
195123
= note: required for `&{integer}` to implement `PartialEq<&&{integer}>`
196124
help: consider dereferencing here
197125
|
@@ -205,16 +133,6 @@ LL | _ = 0 == &&&&foo;
205133
| ^^ no implementation for `{integer} == &&&&&&{integer}`
206134
|
207135
= help: the trait `PartialEq<&&&&&&{integer}>` is not implemented for `{integer}`
208-
= help: the following other types implement trait `PartialEq<Rhs>`:
209-
isize
210-
i8
211-
i16
212-
i32
213-
i64
214-
i128
215-
usize
216-
u8
217-
and 6 others
218136
help: consider removing the borrows and dereferencing instead
219137
|
220138
LL - _ = 0 == &&&&foo;
@@ -228,16 +146,6 @@ LL | _ = 0 == *foo;
228146
| ^^ no implementation for `{integer} == &{integer}`
229147
|
230148
= help: the trait `PartialEq<&{integer}>` is not implemented for `{integer}`
231-
= help: the following other types implement trait `PartialEq<Rhs>`:
232-
isize
233-
i8
234-
i16
235-
i32
236-
i64
237-
i128
238-
usize
239-
u8
240-
and 6 others
241149
help: consider dereferencing here
242150
|
243151
LL | _ = 0 == **foo;
@@ -250,16 +158,6 @@ LL | _ = &&0 == &&foo;
250158
| ^^ no implementation for `{integer} == &&{integer}`
251159
|
252160
= help: the trait `PartialEq<&&{integer}>` is not implemented for `{integer}`
253-
= help: the following other types implement trait `PartialEq<Rhs>`:
254-
isize
255-
i8
256-
i16
257-
i32
258-
i64
259-
i128
260-
usize
261-
u8
262-
and 6 others
263161
= note: required for `&{integer}` to implement `PartialEq<&&&{integer}>`
264162
= note: 1 redundant requirement hidden
265163
= note: required for `&&{integer}` to implement `PartialEq<&&&&{integer}>`
@@ -276,8 +174,6 @@ LL | _ = &Box::new(Box::new(42)) == &foo;
276174
| ^^ no implementation for `Box<Box<{integer}>> == &&{integer}`
277175
|
278176
= help: the trait `PartialEq<&&{integer}>` is not implemented for `Box<Box<{integer}>>`
279-
= help: the trait `PartialEq` is implemented for `Box<Box<{integer}>>`
280-
= help: for that trait implementation, expected `Box<Box<{integer}>>`, found `&&{integer}`
281177
= note: required for `&Box<Box<{integer}>>` to implement `PartialEq<&&&{integer}>`
282178
help: consider dereferencing both sides
283179
|
@@ -292,8 +188,6 @@ LL | _ = &Box::new(42) == &foo;
292188
| ^^ no implementation for `Box<{integer}> == &&{integer}`
293189
|
294190
= help: the trait `PartialEq<&&{integer}>` is not implemented for `Box<{integer}>`
295-
= help: the trait `PartialEq` is implemented for `Box<{integer}>`
296-
= help: for that trait implementation, expected `Box<{integer}>`, found `&&{integer}`
297191
= note: required for `&Box<{integer}>` to implement `PartialEq<&&&{integer}>`
298192
help: consider dereferencing both sides
299193
|
@@ -308,8 +202,6 @@ LL | _ = &Box::new(Box::new(Box::new(Box::new(42)))) == &foo;
308202
| ^^ no implementation for `Box<Box<Box<Box<{integer}>>>> == &&{integer}`
309203
|
310204
= help: the trait `PartialEq<&&{integer}>` is not implemented for `Box<Box<Box<Box<{integer}>>>>`
311-
= help: the trait `PartialEq` is implemented for `Box<Box<Box<Box<{integer}>>>>`
312-
= help: for that trait implementation, expected `Box<Box<Box<Box<{integer}>>>>`, found `&&{integer}`
313205
= note: required for `&Box<Box<Box<Box<{integer}>>>>` to implement `PartialEq<&&&{integer}>`
314206
help: consider dereferencing both sides
315207
|
@@ -324,16 +216,6 @@ LL | _ = &foo == &Box::new(Box::new(Box::new(Box::new(42))));
324216
| ^^ no implementation for `&&{integer} == Box<Box<Box<Box<{integer}>>>>`
325217
|
326218
= help: the trait `PartialEq<Box<Box<Box<Box<{integer}>>>>>` is not implemented for `&&{integer}`
327-
= help: the following other types implement trait `PartialEq<Rhs>`:
328-
isize
329-
i8
330-
i16
331-
i32
332-
i64
333-
i128
334-
usize
335-
u8
336-
and 6 others
337219
= note: required for `&&&{integer}` to implement `PartialEq<&Box<Box<Box<Box<{integer}>>>>>`
338220
help: consider dereferencing both sides
339221
|
@@ -401,11 +283,6 @@ LL | _ = string_ref == partial[..3];
401283
| ^^ no implementation for `&String == str`
402284
|
403285
= help: the trait `PartialEq<str>` is not implemented for `&String`
404-
= help: the following other types implement trait `PartialEq<Rhs>`:
405-
<String as PartialEq<Cow<'a, str>>>
406-
<String as PartialEq>
407-
<String as PartialEq<str>>
408-
<String as PartialEq<&'a str>>
409286
help: consider dereferencing here
410287
|
411288
LL | _ = *string_ref == partial[..3];
@@ -418,15 +295,6 @@ LL | _ = partial[..3] == string_ref;
418295
| ^^ no implementation for `str == &String`
419296
|
420297
= help: the trait `PartialEq<&String>` is not implemented for `str`
421-
= help: the following other types implement trait `PartialEq<Rhs>`:
422-
<str as PartialEq<Cow<'a, str>>>
423-
<str as PartialEq<OsString>>
424-
<str as PartialEq<OsStr>>
425-
<str as PartialEq<String>>
426-
<str as PartialEq>
427-
<&'a str as PartialEq<OsString>>
428-
<&'a str as PartialEq<String>>
429-
<&'b str as PartialEq<Cow<'a, str>>>
430298
help: consider dereferencing here
431299
|
432300
LL | _ = partial[..3] == *string_ref;

tests/ui/dst/issue-113447.stderr

-14
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,11 @@ LL | let _ = &[0u8] == [0xAA];
55
| ^^ no implementation for `&[u8; 1] == [{integer}; 1]`
66
|
77
= help: the trait `PartialEq<[{integer}; 1]>` is not implemented for `&[u8; 1]`
8-
= help: the following other types implement trait `PartialEq<Rhs>`:
9-
<[A; N] as PartialEq<[B; N]>>
10-
<[A; N] as PartialEq<[B]>>
11-
<[A; N] as PartialEq<&[B]>>
12-
<[A; N] as PartialEq<&mut [B]>>
13-
<[T] as PartialEq<Vec<U, A>>>
14-
<[A] as PartialEq<[B]>>
15-
<[B] as PartialEq<[A; N]>>
16-
<&[u8] as PartialEq<Bytes>>
17-
and 4 others
188
help: consider removing the borrow
199
|
2010
LL - let _ = &[0u8] == [0xAA];
2111
LL + let _ = [0u8] == [0xAA];
2212
|
23-
help: convert the array to a `&[u8]` slice instead
24-
|
25-
LL | let _ = &[0u8] == &[0xAA][..];
26-
| + ++++
2713

2814
error: aborting due to 1 previous error
2915

0 commit comments

Comments
 (0)