@@ -1864,35 +1864,42 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1864
1864
&& let ExprBindingObligation ( _, _, hir_id, ..) = code
1865
1865
&& !fn_sig. output ( ) . is_unit ( )
1866
1866
{
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 {
1872
1873
let expr_ty = self . typeck_results . borrow ( ) . expr_ty ( expr) ;
1873
1874
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
+ {
1876
1878
found_semi = true ;
1877
1879
}
1878
- } ,
1879
- hir:: Node :: Block ( _block) => if found_semi {
1880
+ }
1881
+ }
1882
+ hir:: Node :: Block ( _block) => {
1883
+ if found_semi {
1880
1884
block_num += 1 ;
1881
1885
}
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 {
1883
1889
break ;
1884
1890
}
1885
- _ => { }
1886
1891
}
1892
+ _ => { }
1887
1893
}
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
+ }
1896
1903
}
1897
1904
diag. emit ( ) ;
1898
1905
}
0 commit comments