Closed
Description
This doesn't compile (error: match arms have incompatible types: expected &int, found &mut int (values differ in mutability)
)
fn main() {
let mut x: int = 1;
let opt: Option<int> = None;
let rx: &int =
match opt {
Some(_) => {
&x
},
None => {
&mut x
},
};
println!("{}", *rx);
}
But this works:
fn main() {
let mut x: int = 1;
let opt: Option<int> = None;
let rx: &int =
match opt {
Some(_) => {
&x
},
None => {
let y: &int = &mut x;
y
},
};
println!("{}", *rx);
}
Should this "cast" be able to happen implicitly?
Metadata
Metadata
Assignees
Labels
No labels