@@ -669,28 +669,43 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
669669 let place_ty: Ty < ' tcx > = place
670670 . ty ( & self . local_decls , self . tcx )
671671 . ty ;
672- if let Ok ( place_layout) = self . tcx . layout_of ( self . param_env . and ( place_ty) ) {
673- if let Some ( value) = self . const_prop ( rval, place_layout, statement. source_info ) {
674- if let Place {
675- base : PlaceBase :: Local ( local) ,
676- projection : box [ ] ,
677- } = * place {
678- trace ! ( "checking whether {:?} can be stored to {:?}" , value, local) ;
679- if self . can_const_prop [ local] {
680- trace ! ( "storing {:?} to {:?}" , value, local) ;
681- assert ! ( self . get_const( local) . is_none( ) ) ;
682- self . set_const ( local, value) ;
683-
684- if self . should_const_prop ( ) {
685- self . replace_with_const (
686- rval,
687- value,
688- statement. source_info ,
689- ) ;
672+
673+ match self . tcx . layout_of ( self . param_env . and ( place_ty) ) {
674+ Ok ( place_layout) => {
675+ if let Some ( value) = self . const_prop (
676+ rval,
677+ place_layout,
678+ statement. source_info ,
679+ ) {
680+ if let Place {
681+ base : PlaceBase :: Local ( local) ,
682+ projection : box [ ] ,
683+ } = * place {
684+ trace ! ( "checking whether {:?} can be stored to {:?}" , value, local) ;
685+ if self . can_const_prop [ local] {
686+ trace ! ( "storing {:?} to {:?}" , value, local) ;
687+ assert ! ( self . get_const( local) . is_none( ) ) ;
688+ self . set_const ( local, value) ;
689+
690+ if self . should_const_prop ( ) {
691+ self . replace_with_const (
692+ rval,
693+ value,
694+ statement. source_info ,
695+ ) ;
690696 }
691697 }
692698 }
693699 }
700+ Err ( LayoutError :: Unsized ( _ty) ) => {
701+ let sp = statement. source_info . span ; // async fn block
702+ self . tcx . sess . struct_span_err (
703+ sp,
704+ "unsized values can't be used in `async` functions" ,
705+ ) . span_label ( sp, "contains unsized values" )
706+ . emit ( ) ;
707+ }
708+ Err ( _) => { }
694709 }
695710 }
696711 self . super_statement( statement, location) ;
0 commit comments