@@ -1864,35 +1864,42 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18641864 && let ExprBindingObligation ( _, _, hir_id, ..) = code
18651865 && !fn_sig. output ( ) . is_unit ( )
18661866 {
1867- let mut block_num = 0 ;
1868- let mut found_semi = false ;
1869- for ( _, node) in self . tcx . hir ( ) . parent_iter ( hir_id) {
1870- match node {
1871- hir:: Node :: Stmt ( stmt) => if let hir:: StmtKind :: Semi ( ref expr) = stmt. kind {
1867+ let mut block_num = 0 ;
1868+ let mut found_semi = false ;
1869+ for ( _, node) in self . tcx . hir ( ) . parent_iter ( hir_id) {
1870+ match node {
1871+ hir:: Node :: Stmt ( stmt) => {
1872+ if let hir:: StmtKind :: Semi ( ref expr) = stmt. kind {
18721873 let expr_ty = self . typeck_results . borrow ( ) . expr_ty ( expr) ;
18731874 let return_ty = fn_sig. output ( ) ;
1874- if !matches ! ( expr. kind, hir:: ExprKind :: Ret ( ..) ) &&
1875- self . can_coerce ( expr_ty, return_ty) {
1875+ if !matches ! ( expr. kind, hir:: ExprKind :: Ret ( ..) )
1876+ && self . can_coerce ( expr_ty, return_ty)
1877+ {
18761878 found_semi = true ;
18771879 }
1878- } ,
1879- hir:: Node :: Block ( _block) => if found_semi {
1880+ }
1881+ }
1882+ hir:: Node :: Block ( _block) => {
1883+ if found_semi {
18801884 block_num += 1 ;
18811885 }
1882- hir:: Node :: Item ( item) => if let hir:: ItemKind :: Fn ( ..) = item. kind {
1886+ }
1887+ hir:: Node :: Item ( item) => {
1888+ if let hir:: ItemKind :: Fn ( ..) = item. kind {
18831889 break ;
18841890 }
1885- _ => { }
18861891 }
1892+ _ => { }
18871893 }
1888- if block_num > 1 && found_semi {
1889- diag. span_suggestion_verbose (
1890- span. shrink_to_lo ( ) ,
1891- "you might have meant to return this to infer its type parameters" ,
1892- "return " ,
1893- Applicability :: MaybeIncorrect ,
1894- ) ;
1895- }
1894+ }
1895+ if block_num > 1 && found_semi {
1896+ diag. span_suggestion_verbose (
1897+ span. shrink_to_lo ( ) ,
1898+ "you might have meant to return this to infer its type parameters" ,
1899+ "return " ,
1900+ Applicability :: MaybeIncorrect ,
1901+ ) ;
1902+ }
18961903 }
18971904 diag. emit ( ) ;
18981905 }
0 commit comments