@@ -903,11 +903,13 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
903903 ) ;
904904 }
905905 self . check_rvalue ( mir, rv, location) ;
906- let trait_ref = ty:: TraitRef {
907- def_id : tcx. lang_items ( ) . sized_trait ( ) . unwrap ( ) ,
908- substs : tcx. mk_substs_trait ( place_ty, & [ ] ) ,
909- } ;
910- self . prove_trait_ref ( trait_ref, location. interesting ( ) ) ;
906+ if !self . tcx ( ) . features ( ) . unsized_locals {
907+ let trait_ref = ty:: TraitRef {
908+ def_id : tcx. lang_items ( ) . sized_trait ( ) . unwrap ( ) ,
909+ substs : tcx. mk_substs_trait ( place_ty, & [ ] ) ,
910+ } ;
911+ self . prove_trait_ref ( trait_ref, location. interesting ( ) ) ;
912+ }
911913 }
912914 StatementKind :: SetDiscriminant {
913915 ref place,
@@ -962,6 +964,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
962964 mir : & Mir < ' tcx > ,
963965 term : & Terminator < ' tcx > ,
964966 term_location : Location ,
967+ errors_buffer : & mut Option < & mut Vec < Diagnostic > > ,
965968 ) {
966969 debug ! ( "check_terminator: {:?}" , term) ;
967970 let tcx = self . tcx ( ) ;
@@ -1041,7 +1044,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
10411044 & sig,
10421045 ) ;
10431046 let sig = self . normalize ( sig, term_location) ;
1044- self . check_call_dest ( mir, term, & sig, destination, term_location) ;
1047+ self . check_call_dest ( mir, term, & sig, destination, term_location, errors_buffer ) ;
10451048
10461049 self . prove_predicates (
10471050 sig. inputs ( ) . iter ( ) . map ( |ty| ty:: Predicate :: WellFormed ( ty) ) ,
@@ -1115,6 +1118,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
11151118 sig : & ty:: FnSig < ' tcx > ,
11161119 destination : & Option < ( Place < ' tcx > , BasicBlock ) > ,
11171120 term_location : Location ,
1121+ errors_buffer : & mut Option < & mut Vec < Diagnostic > > ,
11181122 ) {
11191123 let tcx = self . tcx ( ) ;
11201124 match * destination {
@@ -1143,6 +1147,13 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
11431147 terr
11441148 ) ;
11451149 }
1150+
1151+ // When `#![feature(unsized_locals)]` is not enabled,
1152+ // this check is done at `check_local`.
1153+ if self . tcx ( ) . features ( ) . unsized_locals {
1154+ let span = term. source_info . span ;
1155+ self . ensure_place_sized ( dest_ty, span, errors_buffer) ;
1156+ }
11461157 }
11471158 None => {
11481159 // FIXME(canndrew): This is_never should probably be an is_uninhabited
@@ -1309,14 +1320,26 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
13091320 LocalKind :: Var | LocalKind :: Temp => { }
13101321 }
13111322
1312- let span = local_decl. source_info . span ;
1313- let ty = local_decl. ty ;
1323+ // When `#![feature(unsized_locals)]` is enabled, only function calls
1324+ // are checked in `check_call_dest`.
1325+ if !self . tcx ( ) . features ( ) . unsized_locals {
1326+ let span = local_decl. source_info . span ;
1327+ let ty = local_decl. ty ;
1328+ self . ensure_place_sized ( ty, span, errors_buffer) ;
1329+ }
1330+ }
1331+
1332+ fn ensure_place_sized ( & mut self ,
1333+ ty : Ty < ' tcx > ,
1334+ span : Span ,
1335+ errors_buffer : & mut Option < & mut Vec < Diagnostic > > ) {
1336+ let tcx = self . tcx ( ) ;
13141337
13151338 // Erase the regions from `ty` to get a global type. The
13161339 // `Sized` bound in no way depends on precise regions, so this
13171340 // shouldn't affect `is_sized`.
1318- let gcx = self . tcx ( ) . global_tcx ( ) ;
1319- let erased_ty = gcx. lift ( & self . tcx ( ) . erase_regions ( & ty) ) . unwrap ( ) ;
1341+ let gcx = tcx. global_tcx ( ) ;
1342+ let erased_ty = gcx. lift ( & tcx. erase_regions ( & ty) ) . unwrap ( ) ;
13201343 if !erased_ty. is_sized ( gcx. at ( span) , self . param_env ) {
13211344 // in current MIR construction, all non-control-flow rvalue
13221345 // expressions evaluate through `as_temp` or `into` a return
@@ -1838,7 +1861,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
18381861 location. statement_index += 1 ;
18391862 }
18401863
1841- self . check_terminator ( mir, block_data. terminator ( ) , location) ;
1864+ self . check_terminator ( mir, block_data. terminator ( ) , location, & mut errors_buffer ) ;
18421865 self . check_iscleanup ( mir, block_data) ;
18431866 }
18441867 }
0 commit comments