Open
Description
Code
trait Trait {}
impl Trait for Vec<i32> {}
fn foo(_: impl Trait) {}
fn main() {
foo(&mut vec![1]);
}
Current output
error[E0277]: the trait bound `&mut Vec<{integer}>: Trait` is not satisfied
--> src/main.rs:8:9
|
8 | foo(&mut vec![1]);
| --- ^^^^^^^^^^^^ the trait `Trait` is not implemented for `&mut Vec<{integer}>`
| |
| required by a bound introduced by this call
|
note: required by a bound in `foo`
--> src/main.rs:5:16
|
5 | fn foo(_: impl Trait) {}
| ^^^^^ required by this bound in `foo`
help: consider removing the leading `&`-reference
|
8 - foo(&mut vec![1]);
8 + foo(mut vec![1]);
|
For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` (bin "playground") due to 1 previous error
Desired output
error[E0277]: the trait bound `&mut Vec<{integer}>: Trait` is not satisfied
--> src/main.rs:8:9
|
8 | foo(&mut vec![1]);
| --- ^^^^^^^^^^^^ the trait `Trait` is not implemented for `&mut Vec<{integer}>`
| |
| required by a bound introduced by this call
|
note: required by a bound in `foo`
--> src/main.rs:5:16
|
5 | fn foo(_: impl Trait) {}
| ^^^^^ required by this bound in `foo`
help: consider removing the leading `&mut`-reference
|
8 - foo(&mut vec![1]);
8 + foo(vec![1]);
|
For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` (bin "playground") due to 1 previous error
Rationale and extra context
The suggested mut vec![]
is invalid. The presence of the trait and the presence of the vec macro seem to both be required for this bug to occur.
Other cases
Rust Version
Reproducible on the playground with 1.90.0-nightly (2025-07-05 5adb489a8034f7b56b29)
Anything else?
No response