mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 06:41:48 +00:00
Merge #5787
5787: Fix missing match arm false positive r=matklad a=CAD97 If the type of the match expression is `{unknown}`, don't do exhaustiveness checks, as it could be an uninhabited type. Co-authored-by: CAD97 <cad97@cad97.com>
This commit is contained in:
commit
3932874794
2 changed files with 19 additions and 2 deletions
|
@ -223,10 +223,10 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
|
||||||
db.body_with_source_map(self.owner.into());
|
db.body_with_source_map(self.owner.into());
|
||||||
|
|
||||||
let match_expr_ty = match infer.type_of_expr.get(match_expr) {
|
let match_expr_ty = match infer.type_of_expr.get(match_expr) {
|
||||||
Some(ty) => ty,
|
|
||||||
// If we can't resolve the type of the match expression
|
// If we can't resolve the type of the match expression
|
||||||
// we cannot perform exhaustiveness checks.
|
// we cannot perform exhaustiveness checks.
|
||||||
None => return,
|
None | Some(Ty::Unknown) => return,
|
||||||
|
Some(ty) => ty,
|
||||||
};
|
};
|
||||||
|
|
||||||
let cx = MatchCheckCtx { match_expr, body, infer: infer.clone(), db };
|
let cx = MatchCheckCtx { match_expr, body, infer: infer.clone(), db };
|
||||||
|
|
|
@ -1335,6 +1335,23 @@ fn panic(a: Category, b: Category) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unknown_type() {
|
||||||
|
check_diagnostics(
|
||||||
|
r#"
|
||||||
|
enum Option<T> { Some(T), None }
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
// `Never` is deliberately not defined so that it's an uninferred type.
|
||||||
|
match Option::<Never>::None {
|
||||||
|
None => (),
|
||||||
|
Some(never) => match never {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
mod false_negatives {
|
mod false_negatives {
|
||||||
//! The implementation of match checking here is a work in progress. As we roll this out, we
|
//! The implementation of match checking here is a work in progress. As we roll this out, we
|
||||||
//! prefer false negatives to false positives (ideally there would be no false positives). This
|
//! prefer false negatives to false positives (ideally there would be no false positives). This
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue