@@ -52,6 +52,7 @@ fn type_is_unsafe_function(ty: Ty) -> bool {
52
52
struct EffectCheckVisitor < ' a , ' tcx : ' a > {
53
53
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
54
54
tables : & ' a ty:: TypeckTables < ' tcx > ,
55
+ body_id : hir:: BodyId ,
55
56
56
57
/// Whether we're in an unsafe context.
57
58
unsafe_context : UnsafeContext ,
@@ -99,10 +100,13 @@ impl<'a, 'tcx> Visitor<'tcx> for EffectCheckVisitor<'a, 'tcx> {
99
100
100
101
fn visit_nested_body ( & mut self , body : hir:: BodyId ) {
101
102
let old_tables = self . tables ;
103
+ let old_body_id = self . body_id ;
102
104
self . tables = self . tcx . body_tables ( body) ;
105
+ self . body_id = body;
103
106
let body = self . tcx . hir . body ( body) ;
104
107
self . visit_body ( body) ;
105
108
self . tables = old_tables;
109
+ self . body_id = old_body_id;
106
110
}
107
111
108
112
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> {
223
227
if let ty:: TyAdt ( adt, ..) = self . tables . expr_ty_adjusted ( base_expr) . sty {
224
228
if adt. is_union ( ) {
225
229
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 ) {
228
233
self . require_unsafe ( field. span ,
229
234
"assignment to non-`Copy` union field" ) ;
230
235
}
@@ -261,6 +266,7 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
261
266
let mut visitor = EffectCheckVisitor {
262
267
tcx : tcx,
263
268
tables : & ty:: TypeckTables :: empty ( ) ,
269
+ body_id : hir:: BodyId { node_id : ast:: CRATE_NODE_ID } ,
264
270
unsafe_context : UnsafeContext :: new ( SafeContext ) ,
265
271
} ;
266
272
0 commit comments