- Notifications
You must be signed in to change notification settings - Fork 13.8k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Code
struct Foo; impl Foo { fn generic<T>(self) -> Option<T> { None } } fn bar() -> Option<i32> { if true { Foo.generic(); } None }
Current output
Compiling playground v0.0.1 (/playground) error[E0282]: type annotations needed --> src/lib.rs:11:13 | 11 | Foo.generic(); | ^^^^^^^ cannot infer type of the type parameter `T` declared on the method `generic` | help: consider specifying the generic argument | 11 | Foo.generic::<T>(); | +++++ help: you might have meant to return this to infer its type parameters | 11 | Foo.return generic(); | ++++++ For more information about this error, try `rustc --explain E0282`. error: could not compile `playground` (lib) due to 1 previous error
Desired output
Compiling playground v0.0.1 (/playground) error[E0282]: type annotations needed --> src/lib.rs:11:13 | 11 | Foo.generic(); | ^^^^^^^ cannot infer type of the type parameter `T` declared on the method `generic` | help: consider specifying the generic argument | 11 | Foo.generic::<T>(); | +++++ help: you might have meant to return this to infer its type parameters | 11 | return Foo.generic(); | ++++++ For more information about this error, try `rustc --explain E0282`. error: could not compile `playground` (lib) due to 1 previous error
Rationale and extra context
The suggested return is incorrect.
Discovered by shrodingerskittenn on the rust community discord.
Other cases
No response
Rust Version
Stable version: 1.79.0 on the playground
Anything else?
No response
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.