Skip to content

Commit 8a671d9

Browse files
committed
Fix ICE when suggesting dereferencing binop operands
1 parent 15755f3 commit 8a671d9

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -891,9 +891,10 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
891891
trait_ref: ty::TraitRef::new(
892892
self.tcx,
893893
inner.trait_ref.def_id,
894-
self.tcx.mk_args(
895-
&[&[l_ty.into(), r_ty.into()], &inner.trait_ref.args[2..]]
896-
.concat(),
894+
self.tcx.mk_args_trait(
895+
l_ty,
896+
iter::once(r_ty.into())
897+
.chain(inner.trait_ref.args.iter().skip(2)),
897898
),
898899
),
899900
..inner

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

+8
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,12 @@ fn baz() {
7272
//~^ERROR can't compare `str` with `&String` [E0277]
7373
}
7474

75+
fn qux() {
76+
// Issue #119352
77+
const FOO: i32 = 42;
78+
let _ = FOO & (*"Sized".to_string().into_boxed_str());
79+
//~^ ERROR the size for values of type `str` cannot be known at compilation time
80+
//~| ERROR no implementation for `i32 & str` [E0277]
81+
}
82+
7583
fn main() {}

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

+22-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,28 @@ help: consider dereferencing here
300300
LL | _ = partial[..3] == *string_ref;
301301
| +
302302

303-
error: aborting due to 22 previous errors
303+
error[E0277]: no implementation for `i32 & str`
304+
--> $DIR/binary-op-suggest-deref.rs:78:17
305+
|
306+
LL | let _ = FOO & (*"Sized".to_string().into_boxed_str());
307+
| ^ no implementation for `i32 & str`
308+
|
309+
= help: the trait `BitAnd<str>` is not implemented for `i32`
310+
= help: the following other types implement trait `BitAnd<Rhs>`:
311+
<i32 as BitAnd>
312+
<i32 as BitAnd<&i32>>
313+
<&'a i32 as BitAnd<i32>>
314+
<&i32 as BitAnd<&i32>>
315+
316+
error[E0277]: the size for values of type `str` cannot be known at compilation time
317+
--> $DIR/binary-op-suggest-deref.rs:78:17
318+
|
319+
LL | let _ = FOO & (*"Sized".to_string().into_boxed_str());
320+
| ^ doesn't have a size known at compile-time
321+
|
322+
= help: the trait `Sized` is not implemented for `str`
323+
324+
error: aborting due to 24 previous errors
304325

305326
Some errors have detailed explanations: E0277, E0308, E0369.
306327
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)