Skip to content

Commit 0f0245e

Browse files
committed
fix: manual_unwrap_or_default
Suggesting error when expression is none
1 parent cdd6336 commit 0f0245e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

clippy_lints/src/manual_unwrap_or_default.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,17 @@ fn handle<'tcx>(cx: &LateContext<'tcx>, if_let_or_match: IfLetOrMatch<'tcx>, exp
131131
},
132132
};
133133

134+
// // We check if the expression is not a None variant
135+
if let Some(none_def_id) = cx.tcx.lang_items().option_none_variant() {
136+
if let ExprKind::Path(QPath::Resolved(_, path)) = &condition.kind {
137+
if let Some(def_id) = path.res.opt_def_id() {
138+
if cx.tcx.parent(def_id) == none_def_id {
139+
return;
140+
}
141+
}
142+
}
143+
}
144+
134145
// We check if the return type of the expression implements Default.
135146
let expr_type = cx.typeck_results().expr_ty(expr);
136147
if let Some(default_trait_id) = cx.tcx.get_diagnostic_item(sym::Default)

0 commit comments

Comments
 (0)