@@ -43,7 +43,7 @@ use crate::{
4343} ;
4444
4545use super :: {
46- BreakableContext , Diverges , Expectation , InferenceContext , InferenceDiagnostic ,
46+ BreakableContext , Diverges , Expectation , InferenceContext , InferenceDiagnostic , ReturnKind ,
4747 cast:: CastCheck , find_breakable,
4848} ;
4949
@@ -576,7 +576,7 @@ impl<'db> InferenceContext<'_, 'db> {
576576 self . types . types . never
577577 }
578578 & Expr :: Return { expr } => self . infer_expr_return ( tgt_expr, expr) ,
579- & Expr :: Become { expr } => self . infer_expr_become ( expr) ,
579+ & Expr :: Become { expr } => self . infer_expr_become ( tgt_expr , expr) ,
580580 Expr :: Yield { expr } => {
581581 if let Some ( ( resume_ty, yield_ty) ) = self . resume_yield_tys {
582582 if let Some ( expr) = expr {
@@ -1454,7 +1454,10 @@ impl<'db> InferenceContext<'_, 'db> {
14541454 }
14551455 }
14561456 None => {
1457- // FIXME: diagnose return outside of function
1457+ self . push_diagnostic ( InferenceDiagnostic :: ReturnOutsideFunction {
1458+ expr : ret,
1459+ kind : ReturnKind :: ReturnExpr ,
1460+ } ) ;
14581461 if let Some ( expr) = expr {
14591462 self . infer_expr_no_expect ( expr, ExprIsRead :: Yes ) ;
14601463 }
@@ -1463,7 +1466,7 @@ impl<'db> InferenceContext<'_, 'db> {
14631466 self . types . types . never
14641467 }
14651468
1466- fn infer_expr_become ( & mut self , expr : ExprId ) -> Ty < ' db > {
1469+ fn infer_expr_become ( & mut self , tgt_expr : ExprId , expr : ExprId ) -> Ty < ' db > {
14671470 match & self . return_coercion {
14681471 Some ( return_coercion) => {
14691472 let ret_ty = return_coercion. expected_ty ( ) ;
@@ -1476,7 +1479,10 @@ impl<'db> InferenceContext<'_, 'db> {
14761479 _ = self . demand_eqtype ( expr. into ( ) , call_expr_ty, ret_ty) ;
14771480 }
14781481 None => {
1479- // FIXME: diagnose `become` outside of functions
1482+ self . push_diagnostic ( InferenceDiagnostic :: ReturnOutsideFunction {
1483+ expr : tgt_expr,
1484+ kind : ReturnKind :: BecomeExpr ,
1485+ } ) ;
14801486 self . infer_expr_no_expect ( expr, ExprIsRead :: Yes ) ;
14811487 }
14821488 }
0 commit comments