-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More precisely point out what is immutable for E0596
- Loading branch information
1 parent
e9addfd
commit fc0abde
Showing
7 changed files
with
133 additions
and
9 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
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,22 @@ | ||
mod some_library { | ||
pub fn foo(_: &mut [i32]) {} | ||
pub fn bar<'a>() -> &'a [i32] { | ||
&[] | ||
} | ||
pub fn bar_mut<'a>() -> &'a mut [i32] { | ||
&mut [] | ||
} | ||
} | ||
|
||
struct Foo { | ||
pub x: i32, | ||
} | ||
|
||
fn foo() { | ||
let foo = Foo { x: 0 }; | ||
let _y: &mut Foo = &mut &foo; //~ ERROR cannot borrow data in a `&` reference as mutable | ||
} | ||
|
||
fn main() { | ||
some_library::foo(&mut some_library::bar()); //~ ERROR cannot borrow data in a `&` reference as mutable | ||
} |
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,31 @@ | ||
error[E0596]: cannot borrow data in a `&` reference as mutable | ||
--> $DIR/issue_113842.rs:17:24 | ||
| | ||
LL | let _y: &mut Foo = &mut &foo; | ||
| ^^^^^---- | ||
| | | ||
| cannot borrow as mutable | ||
| | ||
help: this expression is of type `&Foo`, which is an immutable reference | ||
--> $DIR/issue_113842.rs:17:29 | ||
| | ||
LL | let _y: &mut Foo = &mut &foo; | ||
| ^^^^ | ||
|
||
error[E0596]: cannot borrow data in a `&` reference as mutable | ||
--> $DIR/issue_113842.rs:21:23 | ||
| | ||
LL | some_library::foo(&mut some_library::bar()); | ||
| ^^^^^------------------- | ||
| | | ||
| cannot borrow as mutable | ||
| | ||
help: this expression is of type `&[i32]`, which is an immutable reference | ||
--> $DIR/issue_113842.rs:21:28 | ||
| | ||
LL | some_library::foo(&mut some_library::bar()); | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0596`. |
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
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