@@ -604,6 +604,40 @@ impl<'a, 'tcx> MirUsedCollector<'a, 'tcx> {
604604 ty:: EarlyBinder :: bind ( value) ,
605605 )
606606 }
607+
608+ fn check_move_size ( & mut self , limit : usize , operand : & mir:: Operand < ' tcx > , location : Location ) {
609+ let limit = Size :: from_bytes ( limit) ;
610+ let ty = operand. ty ( self . body , self . tcx ) ;
611+ let ty = self . monomorphize ( ty) ;
612+ let layout = self . tcx . layout_of ( ty:: ParamEnv :: reveal_all ( ) . and ( ty) ) ;
613+ if let Ok ( layout) = layout {
614+ if layout. size > limit {
615+ debug ! ( ?layout) ;
616+ let source_info = self . body . source_info ( location) ;
617+ debug ! ( ?source_info) ;
618+ let lint_root = source_info. scope . lint_root ( & self . body . source_scopes ) ;
619+ debug ! ( ?lint_root) ;
620+ let Some ( lint_root) = lint_root else {
621+ // This happens when the issue is in a function from a foreign crate that
622+ // we monomorphized in the current crate. We can't get a `HirId` for things
623+ // in other crates.
624+ // FIXME: Find out where to report the lint on. Maybe simply crate-level lint root
625+ // but correct span? This would make the lint at least accept crate-level lint attributes.
626+ return ;
627+ } ;
628+ self . tcx . emit_spanned_lint (
629+ LARGE_ASSIGNMENTS ,
630+ lint_root,
631+ source_info. span ,
632+ LargeAssignmentsLint {
633+ span : source_info. span ,
634+ size : layout. size . bytes ( ) ,
635+ limit : limit. bytes ( ) ,
636+ } ,
637+ )
638+ }
639+ }
640+ }
607641}
608642
609643impl < ' a , ' tcx > MirVisitor < ' tcx > for MirUsedCollector < ' a , ' tcx > {
@@ -811,40 +845,9 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
811845
812846 fn visit_operand ( & mut self , operand : & mir:: Operand < ' tcx > , location : Location ) {
813847 self . super_operand ( operand, location) ;
814- let limit = self . tcx . move_size_limit ( ) . 0 ;
815- if limit == 0 {
816- return ;
817- }
818- let limit = Size :: from_bytes ( limit) ;
819- let ty = operand. ty ( self . body , self . tcx ) ;
820- let ty = self . monomorphize ( ty) ;
821- let layout = self . tcx . layout_of ( ty:: ParamEnv :: reveal_all ( ) . and ( ty) ) ;
822- if let Ok ( layout) = layout {
823- if layout. size > limit {
824- debug ! ( ?layout) ;
825- let source_info = self . body . source_info ( location) ;
826- debug ! ( ?source_info) ;
827- let lint_root = source_info. scope . lint_root ( & self . body . source_scopes ) ;
828- debug ! ( ?lint_root) ;
829- let Some ( lint_root) = lint_root else {
830- // This happens when the issue is in a function from a foreign crate that
831- // we monomorphized in the current crate. We can't get a `HirId` for things
832- // in other crates.
833- // FIXME: Find out where to report the lint on. Maybe simply crate-level lint root
834- // but correct span? This would make the lint at least accept crate-level lint attributes.
835- return ;
836- } ;
837- self . tcx . emit_spanned_lint (
838- LARGE_ASSIGNMENTS ,
839- lint_root,
840- source_info. span ,
841- LargeAssignmentsLint {
842- span : source_info. span ,
843- size : layout. size . bytes ( ) ,
844- limit : limit. bytes ( ) ,
845- } ,
846- )
847- }
848+ let move_size_limit = self . tcx . move_size_limit ( ) . 0 ;
849+ if move_size_limit > 0 {
850+ self . check_move_size ( move_size_limit, operand, location) ;
848851 }
849852 }
850853
0 commit comments