From: Ralf Jung Date: Fri, 18 Oct 2019 09:33:12 +0000 (+0200) Subject: cleanup now that borrow checker knows memory is a field X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=5481afbaf64c05d5647533df0ec58492af5ef455;p=rust.git cleanup now that borrow checker knows memory is a field --- diff --git a/src/eval.rs b/src/eval.rs index 77bc096e319..bb0bad0ea03 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -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 = 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)?; } } diff --git a/src/helpers.rs b/src/helpers.rs index 08e28e909ab..c09d5c823e1 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -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; } diff --git a/src/shims/env.rs b/src/shims/env.rs index bd9263d8bf2..6078ca26e26 100644 --- a/src/shims/env.rs +++ b/src/shims/env.rs @@ -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> { diff --git a/src/shims/foreign_items.rs b/src/shims/foreign_items.rs index 563acde00e1..cfbb02f6081 100644 --- a/src/shims/foreign_items.rs +++ b/src/shims/foreign_items.rs @@ -42,7 +42,6 @@ fn prev_power_of_two(x: u64) -> u64 { fn malloc(&mut self, size: u64, zero_init: bool, kind: MiriMemoryKind) -> Scalar { 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) -> 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) -> InterpResult<'tcx> { fn get_last_error(&mut self) -> InterpResult<'tcx, Scalar> { 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() } diff --git a/src/shims/fs.rs b/src/shims/fs.rs index 3a16e286895..891474bc3bd 100644 --- a/src/shims/fs.rs +++ b/src/shims/fs.rs @@ -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); diff --git a/src/shims/intrinsics.rs b/src/shims/intrinsics.rs index 1fa2b5a0d01..4666557e200 100644 --- a/src/shims/intrinsics.rs +++ b/src/shims/intrinsics.rs @@ -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)?;