@@ -13,6 +13,7 @@ use rustc_middle::mir::interpret::{alloc_range, Scalar};
13
13
use rustc_middle:: mir:: ConstValue ;
14
14
use rustc_middle:: ty:: { self , EarlyBinder , FloatTy , GenericArgsRef , IntTy , List , ScalarInt , Ty , TyCtxt , UintTy } ;
15
15
use rustc_middle:: { bug, mir, span_bug} ;
16
+ use rustc_span:: def_id:: DefId ;
16
17
use rustc_span:: symbol:: { Ident , Symbol } ;
17
18
use rustc_span:: SyntaxContext ;
18
19
use rustc_target:: abi:: Size ;
@@ -482,11 +483,21 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
482
483
}
483
484
484
485
/// 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.
485
488
pub fn expr_is_empty ( & mut self , e : & Expr < ' _ > ) -> Option < bool > {
486
489
match e. kind {
487
490
ExprKind :: ConstBlock ( ConstBlock { body, .. } ) => self . expr_is_empty ( self . lcx . tcx . hir ( ) . body ( body) . value ) ,
488
491
ExprKind :: DropTemps ( e) => self . expr_is_empty ( e) ,
489
492
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
+ }
490
501
self . fetch_path_and_apply ( qpath, e. hir_id , self . typeck_results . expr_ty ( e) , |this, result| {
491
502
mir_is_empty ( this. lcx , result)
492
503
} )
0 commit comments