Open
Description
Hi, I tried to search for a similar issue but couldn't find one. I hope I haven't missed any. Though this issue seems quite obvious. Thanks a lot for your time and work!
I tried this code: (minimal reproducible)
#[derive(Debug,Default)]
struct Something {
value: i32,
}
impl Something {
pub fn new() -> Self {
let mut something = des();
something.value = 100; // comment out and everything works just fine
something
}
}
fn des<T: Default>() -> T {
T::default()
}
fn main() {
let deserialized = Something::new();
println!("deserialized = {:?}", deserialized);
}
I expected to see this happen: infer the type automatically and compile successfully, like rust-analyser
Instead, this happened:
error[E0282]: type annotations needed
--> src/main.rs:10:13
|
10 | let mut something = des();
| ^^^^^^^^^^^^^
11 | something.value = 100; // comment out and everything works just fine
| --------- type must be known at this point
|
help: consider giving `something` an explicit type
|
10 | let mut something: /* Type */ = des();
| ++++++++++++
For more information about this error, try `rustc --explain E0282`.
error: could not compile `playground` (bin "playground") due to 1 previous error
Meta
rustc --version --verbose
:
rustc 1.85.1 (4eb161250 2025-03-15)
binary: rustc
commit-hash: 4eb161250e340c8f48f66e2b929ef4a5bed7c181
commit-date: 2025-03-15
host: aarch64-apple-darwin
release: 1.85.1
LLVM version: 19.1.7