]> git.lizzy.rs Git - rust.git/commitdiff
cleanup now that borrow checker knows memory is a field
authorRalf Jung <post@ralfj.de>
Fri, 18 Oct 2019 09:33:12 +0000 (11:33 +0200)
committerRalf Jung <post@ralfj.de>
Fri, 18 Oct 2019 09:33:12 +0000 (11:33 +0200)
src/eval.rs
src/helpers.rs
src/shims/env.rs
src/shims/foreign_items.rs
src/shims/fs.rs
src/shims/intrinsics.rs

index 77bc096e31983c8a4d8035bf6ba4b0bcfe653fba..bb0bad0ea03d729053ca4b063b5072a43a781e05 100644 (file)
@@ -155,7 +155,6 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
     }
     // Store command line as UTF-16 for Windows `GetCommandLineW`.
     {
-        let tcx = &{ ecx.tcx.tcx };
         let cmd_utf16: Vec<u16> = cmd.encode_utf16().collect();
         let cmd_ptr = ecx.memory.allocate(
             Size::from_bytes(cmd_utf16.len() as u64 * 2),
@@ -169,12 +168,12 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
         let mut cur_ptr = cmd_ptr;
         for &c in cmd_utf16.iter() {
             cmd_alloc.write_scalar(
-                tcx,
+                &*ecx.tcx,
                 cur_ptr,
                 Scalar::from_uint(c, char_size).into(),
                 char_size,
             )?;
-            cur_ptr = cur_ptr.offset(char_size, tcx)?;
+            cur_ptr = cur_ptr.offset(char_size, &*ecx.tcx)?;
         }
     }
 
index 08e28e909ab28e760d43cd2509ca17db3f83e283..c09d5c823e1bb214f306223ea9dfb7978a65c02a 100644 (file)
@@ -112,8 +112,7 @@ fn gen_random(
             rng.fill_bytes(&mut data);
         }
 
-        let tcx = &{this.tcx.tcx};
-        this.memory.get_mut(ptr.alloc_id)?.write_bytes(tcx, ptr, &data)
+        this.memory.get_mut(ptr.alloc_id)?.write_bytes(&*this.tcx, ptr, &data)
     }
 
     /// Visits the memory covered by `place`, sensitive to freezing: the 3rd parameter
@@ -311,8 +310,7 @@ fn eval_libc_i32(&mut self, name: &str) -> InterpResult<'tcx, i32> {
     /// Helper function to get the `TyLayout` of a `libc` type
     fn libc_ty_layout(&mut self, name: &str) -> InterpResult<'tcx, TyLayout<'tcx>> {
         let this = self.eval_context_mut();
-        let tcx = &{ this.tcx.tcx };
-        let ty = this.resolve_path(&["libc", name])?.ty(*tcx);
+        let ty = this.resolve_path(&["libc", name])?.ty(*this.tcx);
         this.layout_of(ty)
     }
 
@@ -325,14 +323,12 @@ fn write_packed_immediates(
     ) -> InterpResult<'tcx> {
         let this = self.eval_context_mut();
 
-        let tcx = &{ this.tcx.tcx };
-
         let mut offset = Size::from_bytes(0);
 
         for &imm in imms {
             this.write_immediate_to_mplace(
                 *imm,
-                place.offset(offset, None, imm.layout, tcx)?,
+                place.offset(offset, None, imm.layout, &*this.tcx)?,
             )?;
             offset += imm.layout.size;
         }
index bd9263d8bf2b7953655f22cbd520b3ff26d6e7f8..6078ca26e269a17e11ec2432d43094991fc13330 100644 (file)
@@ -122,10 +122,8 @@ fn getcwd(
 
         this.check_no_isolation("getcwd")?;
 
-        let tcx = &{ this.tcx.tcx };
-
         let buf = this.force_ptr(this.read_scalar(buf_op)?.not_undef()?)?;
-        let size = this.read_scalar(size_op)?.to_usize(&*tcx)?;
+        let size = this.read_scalar(size_op)?.to_usize(&*this.tcx)?;
         // If we cannot get the current directory, we return null
         match env::current_dir() {
             Ok(cwd) => {
@@ -142,7 +140,7 @@ fn getcwd(
                     // `bytes.len()`, meaning that `bytes` actually fit inside tbe buffer.
                     this.memory
                         .get_mut(buf.alloc_id)?
-                        .write_bytes(tcx, buf, &bytes)?;
+                        .write_bytes(&*this.tcx, buf, &bytes)?;
                     return Ok(Scalar::Ptr(buf));
                 }
                 let erange = this.eval_libc("ERANGE")?;
@@ -150,7 +148,7 @@ fn getcwd(
             }
             Err(e) => this.consume_io_error(e)?,
         }
-        Ok(Scalar::ptr_null(&*tcx))
+        Ok(Scalar::ptr_null(&*this.tcx))
     }
 
     fn chdir(&mut self, path_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
index 563acde00e1e13466713caacaf590aca6f579504..cfbb02f608130deda2e6ecc30c078bc8ddc8f9ff 100644 (file)
@@ -42,7 +42,6 @@ fn prev_power_of_two(x: u64) -> u64 {
 
     fn malloc(&mut self, size: u64, zero_init: bool, kind: MiriMemoryKind) -> Scalar<Tag> {
         let this = self.eval_context_mut();
-        let tcx = &{ this.tcx.tcx };
         if size == 0 {
             Scalar::from_int(0, this.pointer_size())
         } else {
@@ -55,7 +54,7 @@ fn malloc(&mut self, size: u64, zero_init: bool, kind: MiriMemoryKind) -> Scalar
                 this.memory
                     .get_mut(ptr.alloc_id)
                     .unwrap()
-                    .write_repeat(tcx, ptr, 0, Size::from_bytes(size))
+                    .write_repeat(&*this.tcx, ptr, 0, Size::from_bytes(size))
                     .unwrap();
             }
             Scalar::Ptr(ptr)
@@ -90,12 +89,11 @@ fn realloc(
             }
         } else {
             let old_ptr = this.force_ptr(old_ptr)?;
-            let memory = &mut this.memory;
             if new_size == 0 {
-                memory.deallocate(old_ptr, None, kind.into())?;
+                this.memory.deallocate(old_ptr, None, kind.into())?;
                 Ok(Scalar::from_int(0, this.pointer_size()))
             } else {
-                let new_ptr = memory.reallocate(
+                let new_ptr = this.memory.reallocate(
                     old_ptr,
                     None,
                     Size::from_bytes(new_size),
@@ -334,7 +332,7 @@ fn emulate_foreign_item(
                 // for the TLS destructors, and of course `eval_main`.
                 let mir = this.load_mir(f_instance.def, None)?;
                 let ret_place =
-                    MPlaceTy::dangling(this.layout_of(this.tcx.mk_unit())?, this).into();
+                    MPlaceTy::dangling(this.layout_of(tcx.mk_unit())?, this).into();
                 this.push_stack_frame(
                     f_instance,
                     mir.span,
@@ -471,7 +469,7 @@ fn emulate_foreign_item(
             "write" => {
                 let fd = this.read_scalar(args[0])?.to_i32()?;
                 let buf = this.read_scalar(args[1])?.not_undef()?;
-                let n = this.read_scalar(args[2])?.to_usize(&*this.tcx)?;
+                let n = this.read_scalar(args[2])?.to_usize(tcx)?;
                 trace!("Called write({:?}, {:?}, {:?})", fd, buf, n);
                 let result = if fd == 1 || fd == 2 {
                     // stdout/stderr
@@ -993,10 +991,9 @@ fn eval_path_scalar(
 
     fn set_last_error(&mut self, scalar: Scalar<Tag>) -> InterpResult<'tcx> {
         let this = self.eval_context_mut();
-        let tcx = &{ this.tcx.tcx };
         let errno_ptr = this.machine.last_error.unwrap();
         this.memory.get_mut(errno_ptr.alloc_id)?.write_scalar(
-            tcx,
+            &*this.tcx,
             errno_ptr,
             scalar.into(),
             Size::from_bits(32),
@@ -1005,11 +1002,10 @@ fn set_last_error(&mut self, scalar: Scalar<Tag>) -> InterpResult<'tcx> {
 
     fn get_last_error(&mut self) -> InterpResult<'tcx, Scalar<Tag>> {
         let this = self.eval_context_mut();
-        let tcx = &{ this.tcx.tcx };
         let errno_ptr = this.machine.last_error.unwrap();
         this.memory
             .get(errno_ptr.alloc_id)?
-            .read_scalar(tcx, errno_ptr, Size::from_bits(32))?
+            .read_scalar(&*this.tcx, errno_ptr, Size::from_bits(32))?
             .not_undef()
     }
 
index 3a16e2868958d379a343dc0fd49e7de15ac3533f..891474bc3bdb6bd90e8214daa9596896530a716d 100644 (file)
@@ -157,8 +157,6 @@ fn read(
 
         this.check_no_isolation("read")?;
 
-        let tcx = &{ this.tcx.tcx };
-
         let count = this.read_scalar(count_op)?.to_usize(&*this.tcx)?;
         // Reading zero bytes should not change `buf`
         if count == 0 {
@@ -173,7 +171,7 @@ fn read(
             let bytes = this.force_ptr(buf_scalar).and_then(|buf| {
                 this.memory
                     .get_mut(buf.alloc_id)?
-                    .get_bytes_mut(tcx, buf, Size::from_bytes(count))
+                    .get_bytes_mut(&*this.tcx, buf, Size::from_bytes(count))
                     .map(|buffer| handle.file.read(buffer))
             });
             // Reinsert the file handle
@@ -192,8 +190,6 @@ fn write(
 
         this.check_no_isolation("write")?;
 
-        let tcx = &{ this.tcx.tcx };
-
         let count = this.read_scalar(count_op)?.to_usize(&*this.tcx)?;
         // Writing zero bytes should not change `buf`
         if count == 0 {
@@ -205,7 +201,7 @@ fn write(
         this.remove_handle_and(fd, |mut handle, this| {
             let bytes = this.memory.get(buf.alloc_id).and_then(|alloc| {
                 alloc
-                    .get_bytes(tcx, buf, Size::from_bytes(count))
+                    .get_bytes(&*this.tcx, buf, Size::from_bytes(count))
                     .map(|bytes| handle.file.write(bytes).map(|bytes| bytes as i64))
             });
             this.machine.file_handler.handles.insert(fd, handle);
index 1fa2b5a0d01fc298df31c21de9d2b160c3d4a035..4666557e200c01c97ef44aeb6626a067bd751f7c 100644 (file)
@@ -28,7 +28,7 @@ fn call_intrinsic(
         // (as opposed to through a place), we have to remember to erase any tag
         // that might still hang around!
 
-        let intrinsic_name = &*this.tcx.item_name(instance.def_id()).as_str();
+        let intrinsic_name = &*tcx.item_name(instance.def_id()).as_str();
         match intrinsic_name {
             "arith_offset" => {
                 let offset = this.read_scalar(args[1])?.to_isize(this)?;