In the following snippet, the &i8
type annotation in the type of failing
does not have the agreement of the compiler. An _
in its place does. Why? And what would be the correct type in that place?
use std::ops::{AddAssign, SubAssign};
fn main() {
//let failing: fn(&mut i8, _) = if true {
let failing: fn(&mut i8, &i8) = if true {
SubAssign::sub_assign
} else {
AddAssign::add_assign
};
let mut n = 0i8;
failing(&mut n, &0i8);
}
Errors:
Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
--> src/main.rs:6:9
|
6 | SubAssign::sub_assign
| ^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
|
= note: expected fn pointer `for<'r, 's> fn(&'r mut i8, &'s i8)`
found fn pointer `for<'r> fn(&'r mut i8, &i8)`
error[E0308]: mismatched types
--> src/main.rs:8:9
|
8 | AddAssign::add_assign
| ^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
|
= note: expected fn pointer `for<'r, 's> fn(&'r mut i8, &'s i8)`
found fn pointer `for<'r> fn(&'r mut i8, &i8)`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground`
To learn more, run the command again with --verbose.