Skip to content

Commit

Permalink
Fix ICE when suggesting dereferencing binop operands
Browse files Browse the repository at this point in the history
  • Loading branch information
sjwang05 committed Dec 27, 2023
1 parent 15755f3 commit 8a671d9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -891,9 +891,10 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
trait_ref: ty::TraitRef::new(
self.tcx,
inner.trait_ref.def_id,
self.tcx.mk_args(
&[&[l_ty.into(), r_ty.into()], &inner.trait_ref.args[2..]]
.concat(),
self.tcx.mk_args_trait(
l_ty,
iter::once(r_ty.into())
.chain(inner.trait_ref.args.iter().skip(2)),
),
),
..inner
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/binop/binary-op-suggest-deref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,12 @@ fn baz() {
//~^ERROR can't compare `str` with `&String` [E0277]
}

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

fn main() {}
23 changes: 22 additions & 1 deletion tests/ui/binop/binary-op-suggest-deref.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,28 @@ help: consider dereferencing here
LL | _ = partial[..3] == *string_ref;
| +

error: aborting due to 22 previous errors
error[E0277]: no implementation for `i32 & str`
--> $DIR/binary-op-suggest-deref.rs:78:17
|
LL | let _ = FOO & (*"Sized".to_string().into_boxed_str());
| ^ no implementation for `i32 & str`
|
= help: the trait `BitAnd<str>` is not implemented for `i32`
= help: the following other types implement trait `BitAnd<Rhs>`:
<i32 as BitAnd>
<i32 as BitAnd<&i32>>
<&'a i32 as BitAnd<i32>>
<&i32 as BitAnd<&i32>>

error[E0277]: the size for values of type `str` cannot be known at compilation time
--> $DIR/binary-op-suggest-deref.rs:78:17
|
LL | let _ = FOO & (*"Sized".to_string().into_boxed_str());
| ^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `str`

error: aborting due to 24 previous errors

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

0 comments on commit 8a671d9

Please sign in to comment.