I wrote something like the following code:
// fn function_that_doesnt_exist() -> String {
// String::new()
// }
fn test(s: &str) {
println!("{}", s);
}
fn test2(s: String) {
println!("{}", s);
}
fn main() {
let s = function_that_doesnt_exist();
test(&s);
test2(s);
}
https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=4be367b5c1d5a1d3d6eb20001c171825
Notice that the actual error is the missing function_that_doesnt_exist, but the compiler confusingly reports errors about str not having a size known at compile time, presumably because it infers the type of s as str. When I was writing this code, I missed the message about the missing function, so I was left scratching my head for a bit. It might be nice to silence such errors when the type of the variable is unknowable.
I wrote something like the following code:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=4be367b5c1d5a1d3d6eb20001c171825
Notice that the actual error is the missing
function_that_doesnt_exist, but the compiler confusingly reports errors aboutstrnot having a size known at compile time, presumably because it infers the type ofsasstr. When I was writing this code, I missed the message about the missing function, so I was left scratching my head for a bit. It might be nice to silence such errors when the type of the variable is unknowable.