-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add and update tests for
IndexMut
help message
- Loading branch information
1 parent
764d472
commit 24abef3
Showing
4 changed files
with
76 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
error[E0596]: cannot borrow data in a `&` reference as mutable | ||
--> $DIR/index-mut-help.rs:21:5 | ||
| | ||
LL | map["peter"].clear(); //~ ERROR | ||
| ^^^^^^^^^^^^ cannot borrow as mutable | ||
|
||
error[E0594]: cannot assign to data in a `&` reference | ||
--> $DIR/index-mut-help.rs:22:5 | ||
| | ||
LL | map["peter"] = "0".to_string(); //~ ERROR | ||
| ^^^^^^^^^^^^ cannot assign | ||
|
||
error[E0596]: cannot borrow data in a `&` reference as mutable | ||
--> $DIR/index-mut-help.rs:23:13 | ||
| | ||
LL | let _ = &mut map["peter"]; //~ ERROR | ||
| ^^^^^^^^^^^^^^^^^ cannot borrow as mutable | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
Some errors occurred: E0594, E0596. | ||
For more information about an error, try `rustc --explain E0594`. |
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,24 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// When mutably indexing a type that implements `Index` but not `IndexMut`, a | ||
// special 'help' message is added to the output. | ||
|
||
|
||
fn main() { | ||
use std::collections::HashMap; | ||
|
||
let mut map = HashMap::new(); | ||
map.insert("peter", "23".to_string()); | ||
|
||
map["peter"].clear(); //~ ERROR | ||
map["peter"] = "0".to_string(); //~ ERROR | ||
let _ = &mut map["peter"]; //~ ERROR | ||
} |
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,28 @@ | ||
error[E0596]: cannot borrow immutable indexed content as mutable | ||
--> $DIR/index-mut-help.rs:21:5 | ||
| | ||
LL | map["peter"].clear(); //~ ERROR | ||
| ^^^^^^^^^^^^ cannot borrow as mutable | ||
| | ||
= help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `std::collections::HashMap<&str, std::string::String>` | ||
|
||
error[E0594]: cannot assign to immutable indexed content | ||
--> $DIR/index-mut-help.rs:22:5 | ||
| | ||
LL | map["peter"] = "0".to_string(); //~ ERROR | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot borrow as mutable | ||
| | ||
= help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `std::collections::HashMap<&str, std::string::String>` | ||
|
||
error[E0596]: cannot borrow immutable indexed content as mutable | ||
--> $DIR/index-mut-help.rs:23:18 | ||
| | ||
LL | let _ = &mut map["peter"]; //~ ERROR | ||
| ^^^^^^^^^^^^ cannot borrow as mutable | ||
| | ||
= help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `std::collections::HashMap<&str, std::string::String>` | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
Some errors occurred: E0594, E0596. | ||
For more information about an error, try `rustc --explain E0594`. |
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