Add regression test for negative case

This commit is contained in:
Esteban Küber 2019-05-23 10:32:01 -07:00
parent 1e3302d85f
commit 7fbbcfaafd
2 changed files with 47 additions and 4 deletions

View File

@ -1,5 +1,17 @@
fn change_opt(opt: &mut Option<String>){
fn suggestion(opt: &mut Option<String>) {
opt = None; //~ ERROR mismatched types
}
fn no_suggestion(opt: &mut Result<String, ()>) {
opt = None //~ ERROR mismatched types
}
fn suggestion2(opt: &mut Option<String>) {
opt = Some(String::new())//~ ERROR mismatched types
}
fn no_suggestion2(opt: &mut Option<String>) {
opt = Some(42)//~ ERROR mismatched types
}
fn main() {}

View File

@ -1,16 +1,47 @@
error[E0308]: mismatched types
--> $DIR/mut-ref-reassignment.rs:2:11
|
LL | opt = None
LL | opt = None;
| ^^^^ expected mutable reference, found enum `std::option::Option`
|
= note: expected type `&mut std::option::Option<std::string::String>`
found type `std::option::Option<_>`
help: consider dereferencing here to assign to the mutable borrowed piece of memory
|
LL | *opt = None
LL | *opt = None;
| ^^^^
error: aborting due to previous error
error[E0308]: mismatched types
--> $DIR/mut-ref-reassignment.rs:6:11
|
LL | opt = None
| ^^^^ expected mutable reference, found enum `std::option::Option`
|
= note: expected type `&mut std::result::Result<std::string::String, ()>`
found type `std::option::Option<_>`
error[E0308]: mismatched types
--> $DIR/mut-ref-reassignment.rs:10:11
|
LL | opt = Some(String::new())
| ^^^^^^^^^^^^^^^^^^^ expected mutable reference, found enum `std::option::Option`
|
= note: expected type `&mut std::option::Option<std::string::String>`
found type `std::option::Option<std::string::String>`
help: consider dereferencing here to assign to the mutable borrowed piece of memory
|
LL | *opt = Some(String::new())
| ^^^^
error[E0308]: mismatched types
--> $DIR/mut-ref-reassignment.rs:14:11
|
LL | opt = Some(42)
| ^^^^^^^^ expected mutable reference, found enum `std::option::Option`
|
= note: expected type `&mut std::option::Option<std::string::String>`
found type `std::option::Option<{integer}>`
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0308`.