Skip to content

Commit 7fbbcfa

Browse files
committed
Add regression test for negative case
1 parent 1e3302d commit 7fbbcfa

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1-
fn change_opt(opt: &mut Option<String>){
1+
fn suggestion(opt: &mut Option<String>) {
2+
opt = None; //~ ERROR mismatched types
3+
}
4+
5+
fn no_suggestion(opt: &mut Result<String, ()>) {
26
opt = None //~ ERROR mismatched types
37
}
48

9+
fn suggestion2(opt: &mut Option<String>) {
10+
opt = Some(String::new())//~ ERROR mismatched types
11+
}
12+
13+
fn no_suggestion2(opt: &mut Option<String>) {
14+
opt = Some(42)//~ ERROR mismatched types
15+
}
16+
517
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,47 @@
11
error[E0308]: mismatched types
22
--> $DIR/mut-ref-reassignment.rs:2:11
33
|
4-
LL | opt = None
4+
LL | opt = None;
55
| ^^^^ expected mutable reference, found enum `std::option::Option`
66
|
77
= note: expected type `&mut std::option::Option<std::string::String>`
88
found type `std::option::Option<_>`
99
help: consider dereferencing here to assign to the mutable borrowed piece of memory
1010
|
11-
LL | *opt = None
11+
LL | *opt = None;
1212
| ^^^^
1313

14-
error: aborting due to previous error
14+
error[E0308]: mismatched types
15+
--> $DIR/mut-ref-reassignment.rs:6:11
16+
|
17+
LL | opt = None
18+
| ^^^^ expected mutable reference, found enum `std::option::Option`
19+
|
20+
= note: expected type `&mut std::result::Result<std::string::String, ()>`
21+
found type `std::option::Option<_>`
22+
23+
error[E0308]: mismatched types
24+
--> $DIR/mut-ref-reassignment.rs:10:11
25+
|
26+
LL | opt = Some(String::new())
27+
| ^^^^^^^^^^^^^^^^^^^ expected mutable reference, found enum `std::option::Option`
28+
|
29+
= note: expected type `&mut std::option::Option<std::string::String>`
30+
found type `std::option::Option<std::string::String>`
31+
help: consider dereferencing here to assign to the mutable borrowed piece of memory
32+
|
33+
LL | *opt = Some(String::new())
34+
| ^^^^
35+
36+
error[E0308]: mismatched types
37+
--> $DIR/mut-ref-reassignment.rs:14:11
38+
|
39+
LL | opt = Some(42)
40+
| ^^^^^^^^ expected mutable reference, found enum `std::option::Option`
41+
|
42+
= note: expected type `&mut std::option::Option<std::string::String>`
43+
found type `std::option::Option<{integer}>`
44+
45+
error: aborting due to 4 previous errors
1546

1647
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)