@@ -45,7 +45,7 @@ use rustc_hir::intravisit::{self, Visitor};
4545use rustc_hir:: Expr ;
4646use rustc_hir_analysis:: astconv:: AstConv ;
4747use rustc_infer:: infer:: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
48- use rustc_infer:: infer:: { Coercion , InferOk , InferResult , TyCtxtInferExt } ;
48+ use rustc_infer:: infer:: { Coercion , InferOk , InferResult } ;
4949use rustc_infer:: traits:: Obligation ;
5050use rustc_middle:: lint:: in_external_macro;
5151use rustc_middle:: ty:: adjustment:: {
@@ -1565,9 +1565,6 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
15651565 && let hir:: ExprKind :: Loop ( loop_blk, ..) = expression. kind {
15661566 intravisit:: walk_block ( & mut visitor, loop_blk) ;
15671567 }
1568- if let Some ( expr) = expression {
1569- self . note_result_coercion ( fcx, & mut err, expr, expected, found) ;
1570- }
15711568 }
15721569 ObligationCauseCode :: ReturnValue ( id) => {
15731570 err = self . report_return_mismatched_types (
@@ -1584,9 +1581,6 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
15841581 let id = fcx. tcx . hir ( ) . parent_id ( id) ;
15851582 unsized_return = self . is_return_ty_unsized ( fcx, id) ;
15861583 }
1587- if let Some ( expr) = expression {
1588- self . note_result_coercion ( fcx, & mut err, expr, expected, found) ;
1589- }
15901584 }
15911585 _ => {
15921586 err = fcx. err_ctxt ( ) . report_mismatched_types (
@@ -1626,44 +1620,6 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
16261620 }
16271621 }
16281622
1629- fn note_result_coercion (
1630- & self ,
1631- fcx : & FnCtxt < ' _ , ' tcx > ,
1632- err : & mut Diagnostic ,
1633- expr : & hir:: Expr < ' tcx > ,
1634- expected : Ty < ' tcx > ,
1635- found : Ty < ' tcx > ,
1636- ) {
1637- let ty:: Adt ( e, substs_e) = expected. kind ( ) else { return ; } ;
1638- let ty:: Adt ( f, substs_f) = found. kind ( ) else { return ; } ;
1639- if e. did ( ) != f. did ( ) {
1640- return ;
1641- }
1642- if Some ( e. did ( ) ) != fcx. tcx . get_diagnostic_item ( sym:: Result ) {
1643- return ;
1644- }
1645- let e = substs_e. type_at ( 1 ) ;
1646- let f = substs_f. type_at ( 1 ) ;
1647- if fcx
1648- . infcx
1649- . type_implements_trait (
1650- fcx. tcx . get_diagnostic_item ( sym:: Into ) . unwrap ( ) ,
1651- [ fcx. tcx . erase_regions ( f) , fcx. tcx . erase_regions ( e) ] ,
1652- fcx. param_env ,
1653- )
1654- . must_apply_modulo_regions ( )
1655- {
1656- err. multipart_suggestion (
1657- "you can rely on the implicit conversion that `?` does to transform the error type" ,
1658- vec ! [
1659- ( expr. span. shrink_to_lo( ) , "Ok(" . to_string( ) ) ,
1660- ( expr. span. shrink_to_hi( ) , "?)" . to_string( ) ) ,
1661- ] ,
1662- Applicability :: MaybeIncorrect ,
1663- ) ;
1664- }
1665- }
1666-
16671623 fn note_unreachable_loop_return (
16681624 & self ,
16691625 err : & mut Diagnostic ,
0 commit comments