File tree Expand file tree Collapse file tree 2 files changed +46
-2
lines changed
src/tools/rust-analyzer/crates
ide-diagnostics/src/handlers Expand file tree Collapse file tree 2 files changed +46
-2
lines changed Original file line number Diff line number Diff line change @@ -117,7 +117,7 @@ impl ExprValidator {
117117 Expr :: If { .. } => {
118118 self . check_for_unnecessary_else ( id, expr, db) ;
119119 }
120- Expr :: Block { .. } => {
120+ Expr :: Block { .. } | Expr :: Async { .. } | Expr :: Unsafe { .. } => {
121121 self . validate_block ( db, expr) ;
122122 }
123123 _ => { }
@@ -254,7 +254,12 @@ impl ExprValidator {
254254 }
255255
256256 fn validate_block ( & mut self , db : & dyn HirDatabase , expr : & Expr ) {
257- let Expr :: Block { statements, .. } = expr else { return } ;
257+ let ( Expr :: Block { statements, .. }
258+ | Expr :: Async { statements, .. }
259+ | Expr :: Unsafe { statements, .. } ) = expr
260+ else {
261+ return ;
262+ } ;
258263 let pattern_arena = Arena :: new ( ) ;
259264 let cx = MatchCheckCtx :: new ( self . owner . module ( db. upcast ( ) ) , self . owner , db) ;
260265 for stmt in & * * statements {
Original file line number Diff line number Diff line change @@ -41,6 +41,45 @@ fn main() {
4141fn main() {
4242 let Some(_) | None = Some(5);
4343}
44+ "# ,
45+ ) ;
46+ }
47+
48+ #[ test]
49+ fn option_nonexhaustive_inside_blocks ( ) {
50+ check_diagnostics (
51+ r#"
52+ //- minicore: option
53+ fn main() {
54+ '_a: {
55+ let None = Some(5);
56+ //^^^^ error: non-exhaustive pattern: `Some(_)` not covered
57+ }
58+ }
59+ "# ,
60+ ) ;
61+
62+ check_diagnostics (
63+ r#"
64+ //- minicore: future, option
65+ fn main() {
66+ let _ = async {
67+ let None = Some(5);
68+ //^^^^ error: non-exhaustive pattern: `Some(_)` not covered
69+ };
70+ }
71+ "# ,
72+ ) ;
73+
74+ check_diagnostics (
75+ r#"
76+ //- minicore: option
77+ fn main() {
78+ unsafe {
79+ let None = Some(5);
80+ //^^^^ error: non-exhaustive pattern: `Some(_)` not covered
81+ }
82+ }
4483"# ,
4584 ) ;
4685 }
You can’t perform that action at this time.
0 commit comments