@@ -43,20 +43,9 @@ pub enum BodyValidationDiagnostic {
43
43
expected : usize ,
44
44
found : usize ,
45
45
} ,
46
- RemoveThisSemicolon {
47
- expr : ExprId ,
48
- } ,
49
- MissingOkOrSomeInTailExpr {
50
- expr : ExprId ,
51
- required : String ,
52
- } ,
53
46
MissingMatchArms {
54
47
match_expr : ExprId ,
55
48
} ,
56
- AddReferenceHere {
57
- arg_expr : ExprId ,
58
- mutability : Mutability ,
59
- } ,
60
49
}
61
50
62
51
impl BodyValidationDiagnostic {
@@ -116,30 +105,6 @@ impl ExprValidator {
116
105
} ) ;
117
106
}
118
107
}
119
- let body_expr = & body[ body. body_expr ] ;
120
- if let Expr :: Block { statements, tail, .. } = body_expr {
121
- if let Some ( t) = tail {
122
- self . validate_results_in_tail_expr ( body. body_expr , * t, db) ;
123
- } else if let Some ( Statement :: Expr { expr : id, .. } ) = statements. last ( ) {
124
- self . validate_missing_tail_expr ( body. body_expr , * id) ;
125
- }
126
- }
127
-
128
- let infer = & self . infer ;
129
- let diagnostics = & mut self . diagnostics ;
130
-
131
- infer
132
- . expr_type_mismatches ( )
133
- . filter_map ( |( expr, mismatch) | {
134
- let ( expr_without_ref, mutability) =
135
- check_missing_refs ( infer, expr, & mismatch. expected ) ?;
136
-
137
- Some ( ( expr_without_ref, mutability) )
138
- } )
139
- . for_each ( |( arg_expr, mutability) | {
140
- diagnostics
141
- . push ( BodyValidationDiagnostic :: AddReferenceHere { arg_expr, mutability } ) ;
142
- } ) ;
143
108
}
144
109
145
110
fn validate_call (
@@ -330,66 +295,6 @@ impl ExprValidator {
330
295
}
331
296
pattern
332
297
}
333
-
334
- fn validate_results_in_tail_expr ( & mut self , body_id : ExprId , id : ExprId , db : & dyn HirDatabase ) {
335
- // the mismatch will be on the whole block currently
336
- let mismatch = match self . infer . type_mismatch_for_expr ( body_id) {
337
- Some ( m) => m,
338
- None => return ,
339
- } ;
340
-
341
- let core_result_path = path ! [ core:: result:: Result ] ;
342
- let core_option_path = path ! [ core:: option:: Option ] ;
343
-
344
- let resolver = self . owner . resolver ( db. upcast ( ) ) ;
345
- let core_result_enum = match resolver. resolve_known_enum ( db. upcast ( ) , & core_result_path) {
346
- Some ( it) => it,
347
- _ => return ,
348
- } ;
349
- let core_option_enum = match resolver. resolve_known_enum ( db. upcast ( ) , & core_option_path) {
350
- Some ( it) => it,
351
- _ => return ,
352
- } ;
353
-
354
- let ( params, required) = match mismatch. expected . kind ( Interner ) {
355
- TyKind :: Adt ( AdtId ( hir_def:: AdtId :: EnumId ( enum_id) ) , parameters)
356
- if * enum_id == core_result_enum =>
357
- {
358
- ( parameters, "Ok" . to_string ( ) )
359
- }
360
- TyKind :: Adt ( AdtId ( hir_def:: AdtId :: EnumId ( enum_id) ) , parameters)
361
- if * enum_id == core_option_enum =>
362
- {
363
- ( parameters, "Some" . to_string ( ) )
364
- }
365
- _ => return ,
366
- } ;
367
-
368
- if params. len ( Interner ) > 0 && params. at ( Interner , 0 ) . ty ( Interner ) == Some ( & mismatch. actual )
369
- {
370
- self . diagnostics
371
- . push ( BodyValidationDiagnostic :: MissingOkOrSomeInTailExpr { expr : id, required } ) ;
372
- }
373
- }
374
-
375
- fn validate_missing_tail_expr ( & mut self , body_id : ExprId , possible_tail_id : ExprId ) {
376
- let mismatch = match self . infer . type_mismatch_for_expr ( body_id) {
377
- Some ( m) => m,
378
- None => return ,
379
- } ;
380
-
381
- let possible_tail_ty = match self . infer . type_of_expr . get ( possible_tail_id) {
382
- Some ( ty) => ty,
383
- None => return ,
384
- } ;
385
-
386
- if !mismatch. actual . is_unit ( ) || mismatch. expected != * possible_tail_ty {
387
- return ;
388
- }
389
-
390
- self . diagnostics
391
- . push ( BodyValidationDiagnostic :: RemoveThisSemicolon { expr : possible_tail_id } ) ;
392
- }
393
298
}
394
299
395
300
struct FilterMapNextChecker {
0 commit comments