@@ -8,9 +8,11 @@ use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceC
88use rustc_middle:: mir:: { self , DefLocation , Location , TerminatorKind , traversal} ;
99use rustc_middle:: ty:: layout:: { HasTyCtxt , LayoutOf } ;
1010use rustc_middle:: { bug, span_bug} ;
11+ use rustc_span:: Symbol ;
1112use tracing:: debug;
1213
1314use super :: FunctionCx ;
15+ use crate :: errors:: TypeDependsOnTargetFeature ;
1416use crate :: traits:: * ;
1517
1618pub ( crate ) fn non_ssa_locals < ' a , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > (
@@ -157,6 +159,30 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'b, 'tcx>> LocalAnalyzer<'a, 'b, 'tcx, Bx>
157159 self . visit_local ( place_ref. local , context, location) ;
158160 }
159161 }
162+
163+ fn check_type_abi_concerns ( & self , local : mir:: Local ) {
164+ static IGNORED_CRATES : [ & str ; 3 ] = [ "memchr" , "core" , "hashbrown" ] ;
165+
166+ let ty = self . fx . mir . local_decls [ local] . ty ;
167+ let ty = self . fx . monomorphize ( ty) ;
168+ let ty = ty. peel_refs ( ) ;
169+
170+ if let Some ( abi_feature) = ty. abi_target_feature ( ) {
171+ let tcx = self . fx . cx . tcx ( ) ;
172+ let krate = tcx. crate_name ( self . fx . instance . def_id ( ) . krate ) ;
173+ if !IGNORED_CRATES . contains ( & krate. as_str ( ) ) {
174+ if !self . fx . target_features . contains ( & Symbol :: intern ( & abi_feature) ) {
175+ let span = self . fx . mir . local_decls [ local] . source_info . span ;
176+
177+ tcx. sess . dcx ( ) . emit_err ( TypeDependsOnTargetFeature {
178+ span,
179+ ty,
180+ target_feature : abi_feature,
181+ } ) ;
182+ }
183+ }
184+ }
185+ }
160186}
161187
162188impl < ' a , ' b , ' tcx , Bx : BuilderMethods < ' b , ' tcx > > Visitor < ' tcx > for LocalAnalyzer < ' a , ' b , ' tcx , Bx > {
@@ -189,6 +215,8 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'b, 'tcx>> Visitor<'tcx> for LocalAnalyzer
189215 }
190216
191217 fn visit_local ( & mut self , local : mir:: Local , context : PlaceContext , location : Location ) {
218+ self . check_type_abi_concerns ( local) ;
219+
192220 match context {
193221 PlaceContext :: MutatingUse ( MutatingUseContext :: Call ) => {
194222 let call = location. block ;
0 commit comments