@@ -33,7 +33,9 @@ use rustc_span::{self, BytePos, MultiSpan, Span};
3333use rustc_trait_selection:: infer:: InferCtxtExt as _;
3434use rustc_trait_selection:: opaque_types:: InferCtxtExt as _;
3535use rustc_trait_selection:: traits:: error_reporting:: InferCtxtExt as _;
36- use rustc_trait_selection:: traits:: { self , ObligationCauseCode , TraitEngine , TraitEngineExt } ;
36+ use rustc_trait_selection:: traits:: {
37+ self , ObligationCauseCode , StatementAsExpression , TraitEngine , TraitEngineExt ,
38+ } ;
3739
3840use std:: collections:: hash_map:: Entry ;
3941use std:: slice;
@@ -1061,7 +1063,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10611063 & self ,
10621064 blk : & ' tcx hir:: Block < ' tcx > ,
10631065 expected_ty : Ty < ' tcx > ,
1064- ) -> Option < ( Span , bool ) > {
1066+ ) -> Option < ( Span , StatementAsExpression ) > {
10651067 // Be helpful when the user wrote `{... expr;}` and
10661068 // taking the `;` off is enough to fix the error.
10671069 let last_stmt = blk. stmts . last ( ) ?;
@@ -1078,49 +1080,45 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10781080 ) ;
10791081 let last_hir_id = self . tcx . hir ( ) . local_def_id_to_hir_id ( last_def_id. expect_local ( ) ) ;
10801082 let exp_hir_id = self . tcx . hir ( ) . local_def_id_to_hir_id ( exp_def_id. expect_local ( ) ) ;
1081- if let (
1082- hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy { bounds : last_bounds, .. } ) ,
1083- hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy { bounds : exp_bounds, .. } ) ,
1084- ) = (
1083+ match (
10851084 & self . tcx . hir ( ) . expect_item ( last_hir_id) . kind ,
10861085 & self . tcx . hir ( ) . expect_item ( exp_hir_id) . kind ,
10871086 ) {
1088- debug ! ( "{:?} {:?}" , last_bounds, exp_bounds) ;
1089- last_bounds. iter ( ) . zip ( exp_bounds. iter ( ) ) . all ( |( left, right) | {
1087+ (
1088+ hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy { bounds : last_bounds, .. } ) ,
1089+ hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy { bounds : exp_bounds, .. } ) ,
1090+ ) if last_bounds. iter ( ) . zip ( exp_bounds. iter ( ) ) . all ( |( left, right) | {
10901091 match ( left, right) {
10911092 (
10921093 hir:: GenericBound :: Trait ( tl, ml) ,
10931094 hir:: GenericBound :: Trait ( tr, mr) ,
1094- ) => {
1095- tl. trait_ref . trait_def_id ( ) == tr. trait_ref . trait_def_id ( )
1096- && ml == mr
1095+ ) if tl. trait_ref . trait_def_id ( ) == tr. trait_ref . trait_def_id ( )
1096+ && ml == mr =>
1097+ {
1098+ true
10971099 }
10981100 (
10991101 hir:: GenericBound :: LangItemTrait ( langl, _, _, argsl) ,
11001102 hir:: GenericBound :: LangItemTrait ( langr, _, _, argsr) ,
1101- ) => {
1103+ ) if langl == langr => {
11021104 // FIXME: consider the bounds!
11031105 debug ! ( "{:?} {:?}" , argsl, argsr) ;
1104- langl == langr
1106+ true
11051107 }
11061108 _ => false ,
11071109 }
1108- } )
1109- } else {
1110- false
1110+ } ) =>
1111+ {
1112+ StatementAsExpression :: NeedsBoxing
1113+ }
1114+ _ => StatementAsExpression :: CorrectType ,
11111115 }
11121116 }
1113- _ => false ,
1117+ _ => StatementAsExpression :: CorrectType ,
11141118 } ;
1115- debug ! (
1116- "needs_box {:?} {:?} {:?}" ,
1117- needs_box,
1118- last_expr_ty. kind( ) ,
1119- self . can_sub( self . param_env, last_expr_ty, expected_ty)
1120- ) ;
11211119 if ( matches ! ( last_expr_ty. kind( ) , ty:: Error ( _) )
11221120 || self . can_sub ( self . param_env , last_expr_ty, expected_ty) . is_err ( ) )
1123- && ! needs_box
1121+ && matches ! ( needs_box, StatementAsExpression :: CorrectType )
11241122 {
11251123 return None ;
11261124 }
0 commit comments