manual_unwrap_or_default
suggested fix fails to compile due to missing type annotation
#12670
Labels
C-bug
Category: Clippy is not doing the correct thing
I-suggestion-causes-error
Issue: The suggestions provided by this Lint cause an ICE/error when applied
L-suspicious
Lint: Belongs in the suspicious lint group
Summary
It's possible to bind an
if let
expression to a variable where the only indication of the variable's type comes from a call toSomeType::default()
. If this code triggers themanual_unwrap_or_default
lint, the suggested fix avoids the call toSomeType::default()
but does not insert a type annotation, causing a compile error due to the now-ambiguous type.This is a really contrived case which I doubt has much chance of showing up in a real project, but
cargo clippy --fix
still shouldn't break your code.Reproducer
Run
cargo clippy --fix
on a new binary crate with thismain.rs
:Clippy should attempt to change this to:
rustc
asks itself, "What type is a piece ofNone
?":Version
Additional Labels
@rustbot label +I-suggestion-causes-error
The text was updated successfully, but these errors were encountered: