Expected a specific type but found a different type.
Rust is strongly and statically typed. E0308 is emitted when a variable assignment, function return, or expression provides a type different from what was expected.
Forgetting to return a value from a function (or leaving off/including a semicolon unintentionally), passing `String` when `&str` is expected, or expecting `Result<T, E>` vs `T`.
1fn get_number() -> i32 {2 "42" // ERROR E0308: expected `i32`, found `&str`3}4 5fn main() {6 let n = get_number();7}1fn get_number() -> i32 {2 42 // Return an actual i32 literal3}4 5// Or parse string into integer6fn parse_number(s: &str) -> Result<i32, std::num::ParseIntError> {7 s.parse::<i32>()8}Simulate standard system builds to trigger compiler trace records and track memory crashes locally.
The function signature declares a return type of `i32`, but the last expression evaluates to string slice `&str`.