@@ -52,6 +52,7 @@ fn type_is_unsafe_function(ty: Ty) -> bool {
5252struct EffectCheckVisitor < ' a , ' tcx : ' a > {
5353 tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
5454 tables : & ' a ty:: TypeckTables < ' tcx > ,
55+ body_id : hir:: BodyId ,
5556
5657 /// Whether we're in an unsafe context.
5758 unsafe_context : UnsafeContext ,
@@ -99,10 +100,13 @@ impl<'a, 'tcx> Visitor<'tcx> for EffectCheckVisitor<'a, 'tcx> {
99100
100101 fn visit_nested_body ( & mut self , body : hir:: BodyId ) {
101102 let old_tables = self . tables ;
103+ let old_body_id = self . body_id ;
102104 self . tables = self . tcx . body_tables ( body) ;
105+ self . body_id = body;
103106 let body = self . tcx . hir . body ( body) ;
104107 self . visit_body ( body) ;
105108 self . tables = old_tables;
109+ self . body_id = old_body_id;
106110 }
107111
108112 fn visit_fn ( & mut self , fn_kind : FnKind < ' tcx > , fn_decl : & ' tcx hir:: FnDecl ,
@@ -223,8 +227,9 @@ impl<'a, 'tcx> Visitor<'tcx> for EffectCheckVisitor<'a, 'tcx> {
223227 if let ty:: TyAdt ( adt, ..) = self . tables . expr_ty_adjusted ( base_expr) . sty {
224228 if adt. is_union ( ) {
225229 let field_ty = self . tables . expr_ty_adjusted ( lhs) ;
226- let param_env = self . tcx . parameter_environment ( adt. did ) ;
227- if field_ty. moves_by_default ( self . tcx , & param_env, field. span ) {
230+ let owner_def_id = self . tcx . hir . body_owner_def_id ( self . body_id ) ;
231+ let param_env = self . tcx . param_env ( owner_def_id) ;
232+ if field_ty. moves_by_default ( self . tcx , param_env, field. span ) {
228233 self . require_unsafe ( field. span ,
229234 "assignment to non-`Copy` union field" ) ;
230235 }
@@ -261,6 +266,7 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
261266 let mut visitor = EffectCheckVisitor {
262267 tcx : tcx,
263268 tables : & ty:: TypeckTables :: empty ( ) ,
269+ body_id : hir:: BodyId { node_id : ast:: CRATE_NODE_ID } ,
264270 unsafe_context : UnsafeContext :: new ( SafeContext ) ,
265271 } ;
266272
0 commit comments