@@ -13,6 +13,7 @@ use rustc_middle::mir::interpret::{alloc_range, Scalar};
1313use rustc_middle:: mir:: ConstValue ;
1414use rustc_middle:: ty:: { self , EarlyBinder , FloatTy , GenericArgsRef , IntTy , List , ScalarInt , Ty , TyCtxt , UintTy } ;
1515use rustc_middle:: { bug, mir, span_bug} ;
16+ use rustc_span:: def_id:: DefId ;
1617use rustc_span:: symbol:: { Ident , Symbol } ;
1718use rustc_span:: SyntaxContext ;
1819use rustc_target:: abi:: Size ;
@@ -482,11 +483,21 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
482483 }
483484
484485 /// Simple constant folding to determine if an expression is an empty slice, str, array, …
486+ /// `None` will be returned if the constness cannot be determined, or if the resolution
487+ /// leaves the local crate.
485488 pub fn expr_is_empty ( & mut self , e : & Expr < ' _ > ) -> Option < bool > {
486489 match e. kind {
487490 ExprKind :: ConstBlock ( ConstBlock { body, .. } ) => self . expr_is_empty ( self . lcx . tcx . hir ( ) . body ( body) . value ) ,
488491 ExprKind :: DropTemps ( e) => self . expr_is_empty ( e) ,
489492 ExprKind :: Path ( ref qpath) => {
493+ if !self
494+ . typeck_results
495+ . qpath_res ( qpath, e. hir_id )
496+ . opt_def_id ( )
497+ . is_some_and ( DefId :: is_local)
498+ {
499+ return None ;
500+ }
490501 self . fetch_path_and_apply ( qpath, e. hir_id , self . typeck_results . expr_ty ( e) , |this, result| {
491502 mir_is_empty ( this. lcx , result)
492503 } )
0 commit comments