-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Explain error with
&mut self
for unsized trait impls
- Loading branch information
Showing
3 changed files
with
43 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
trait Modify { | ||
fn modify(&mut self) ; | ||
} | ||
|
||
impl<T> Modify for T { | ||
fn modify(&mut self) {} | ||
} | ||
|
||
trait Foo { | ||
fn mute(&mut self) { | ||
self.modify(); //~ ERROR cannot borrow `self` as mutable | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable | ||
--> $DIR/issue-93078.rs:11:9 | ||
| | ||
LL | self.modify(); | ||
| ^^^^^^^^^^^^^ cannot borrow as mutable | ||
| | ||
= note: as `Self` may be unsized, this call attempts to take `&mut &mut self` | ||
= note: however, `&mut self` expands to `self: &mut Self`, therefore `self` cannot be borrowed mutably | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0596`. |