@@ -3,9 +3,7 @@ use std::{fmt, iter, mem};
33use itertools:: Itertools ;
44use rustc_data_structures:: fx:: FxIndexSet ;
55use rustc_errors:: codes:: * ;
6- use rustc_errors:: {
7- Applicability , Diag , ErrorGuaranteed , MultiSpan , StashKey , a_or_an, listify, pluralize,
8- } ;
6+ use rustc_errors:: { Applicability , Diag , ErrorGuaranteed , MultiSpan , a_or_an, listify, pluralize} ;
97use rustc_hir:: def:: { CtorOf , DefKind , Res } ;
108use rustc_hir:: def_id:: DefId ;
119use rustc_hir:: intravisit:: Visitor ;
@@ -2193,62 +2191,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21932191 }
21942192 }
21952193
2196- pub ( super ) fn collect_unused_stmts_for_coerce_return_ty (
2197- & self ,
2198- errors_causecode : Vec < ( Span , ObligationCauseCode < ' tcx > ) > ,
2199- ) {
2200- for ( span, code) in errors_causecode {
2201- self . dcx ( ) . try_steal_modify_and_emit_err ( span, StashKey :: MaybeForgetReturn , |err| {
2202- if let Some ( fn_sig) = self . body_fn_sig ( )
2203- && let ObligationCauseCode :: WhereClauseInExpr ( _, _, binding_hir_id, ..) = code
2204- && !fn_sig. output ( ) . is_unit ( )
2205- {
2206- let mut block_num = 0 ;
2207- let mut found_semi = false ;
2208- for ( hir_id, node) in self . tcx . hir_parent_iter ( binding_hir_id) {
2209- // Don't proceed into parent bodies
2210- if hir_id. owner != binding_hir_id. owner {
2211- break ;
2212- }
2213- match node {
2214- hir:: Node :: Stmt ( stmt) => {
2215- if let hir:: StmtKind :: Semi ( expr) = stmt. kind {
2216- let expr_ty = self . typeck_results . borrow ( ) . expr_ty ( expr) ;
2217- let return_ty = fn_sig. output ( ) ;
2218- if !matches ! ( expr. kind, hir:: ExprKind :: Ret ( ..) )
2219- && self . may_coerce ( expr_ty, return_ty)
2220- {
2221- found_semi = true ;
2222- }
2223- }
2224- }
2225- hir:: Node :: Block ( _block) => {
2226- if found_semi {
2227- block_num += 1 ;
2228- }
2229- }
2230- hir:: Node :: Item ( item) => {
2231- if let hir:: ItemKind :: Fn { .. } = item. kind {
2232- break ;
2233- }
2234- }
2235- _ => { }
2236- }
2237- }
2238- if block_num > 1 && found_semi {
2239- err. span_suggestion_verbose (
2240- // use the span of the *whole* expr
2241- self . tcx . hir ( ) . span ( binding_hir_id) . shrink_to_lo ( ) ,
2242- "you might have meant to return this to infer its type parameters" ,
2243- "return " ,
2244- Applicability :: MaybeIncorrect ,
2245- ) ;
2246- }
2247- }
2248- } ) ;
2249- }
2250- }
2251-
22522194 /// Given a vector of fulfillment errors, try to adjust the spans of the
22532195 /// errors to more accurately point at the cause of the failure.
22542196 ///
0 commit comments