Closed
Description
Given the following code:
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=ea6b44e39b5b86350d6426f355610990
trait Set
{
fn set(&mut self, value: i8);
}
impl Set for i8
{
fn set(&mut self, value: i8)
{
*self = value
}
}
fn main()
{
let mut integer = 0i8;
let set: &dyn Set = &mut integer;
set.set(10)
}
The current output is:
error[E0596]: cannot borrow `*set` as mutable, as it is behind a `&` reference
--> src/main.rs:18:3
|
17 | let set: &dyn Set = &mut integer;
| ------------ help: consider changing this to be a mutable reference: `&mut mut integer`
18 | set.set(10)
| ^^^ `set` is a `&` reference, so the data it refers to cannot be borrowed as mutable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0596`.
error: could not compile `playground`
To learn more, run the command again with --verbose.
Ideally the output should look like:
error[E0596]: cannot borrow `*set` as mutable, as it is behind a `&` reference
--> src/main.rs:18:3
|
17 | let set: &dyn Set = &mut integer;
| -------- help: consider changing this to be a mutable reference: `&mut dyn Set`
18 | set.set(10)
| ^^^ `set` is a `&` reference, so the data it refers to cannot be borrowed as mutable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0596`.
error: could not compile `playground`
To learn more, run the command again with --verbose.
The compiler currently does not use type annotations for the help message, and instead asks for a double-mutable reference(?).
This happens on both stable and nightly.