fix: Missing non-exhaustive let diagnostics inside async or unsafe block

This commit is contained in:
Shoyu Vanilla 2024-08-12 23:19:03 +09:00
parent e66f3db9fa
commit 3bb7f35ec4
2 changed files with 46 additions and 2 deletions

View File

@ -117,7 +117,7 @@ fn validate_body(&mut self, db: &dyn HirDatabase) {
Expr::If { .. } => {
self.check_for_unnecessary_else(id, expr, db);
}
Expr::Block { .. } => {
Expr::Block { .. } | Expr::Async { .. } | Expr::Unsafe { .. } => {
self.validate_block(db, expr);
}
_ => {}
@ -254,7 +254,12 @@ fn validate_match(
}
fn validate_block(&mut self, db: &dyn HirDatabase, expr: &Expr) {
let Expr::Block { statements, .. } = expr else { return };
let (Expr::Block { statements, .. }
| Expr::Async { statements, .. }
| Expr::Unsafe { statements, .. }) = expr
else {
return;
};
let pattern_arena = Arena::new();
let cx = MatchCheckCtx::new(self.owner.module(db.upcast()), self.owner, db);
for stmt in &**statements {

View File

@ -41,6 +41,45 @@ fn option_exhaustive() {
fn main() {
let Some(_) | None = Some(5);
}
"#,
);
}
#[test]
fn option_nonexhaustive_inside_blocks() {
check_diagnostics(
r#"
//- minicore: option
fn main() {
'_a: {
let None = Some(5);
//^^^^ error: non-exhaustive pattern: `Some(_)` not covered
}
}
"#,
);
check_diagnostics(
r#"
//- minicore: future, option
fn main() {
let _ = async {
let None = Some(5);
//^^^^ error: non-exhaustive pattern: `Some(_)` not covered
};
}
"#,
);
check_diagnostics(
r#"
//- minicore: option
fn main() {
unsafe {
let None = Some(5);
//^^^^ error: non-exhaustive pattern: `Some(_)` not covered
}
}
"#,
);
}