Update to rustfmt-preview (#348)

* Update to rustfmt-preview.

* Run "cargo fmt --all" with rustfmt 0.4.1.

rustfmt 0.4.1 is the latest release of rustfmt-preview available on the
stable channel.

* Fix a long line that rustfmt 0.4.1 can't handle.

* Remove unneeded commas left behind by rustfmt.
This commit is contained in:
Dan Gohman
2018-05-25 11:38:38 -07:00
committed by GitHub
parent 99f6055c55
commit 6b88cd44a8
137 changed files with 1914 additions and 2380 deletions

View File

@@ -1,17 +1,17 @@
//! Defines `SimpleJITBackend`.
use cretonne_codegen::binemit::{Addend, CodeOffset, Reloc, RelocSink, NullTrapSink};
use cretonne_codegen::binemit::{Addend, CodeOffset, NullTrapSink, Reloc, RelocSink};
use cretonne_codegen::isa::TargetIsa;
use cretonne_codegen::{self, ir, settings};
use cretonne_module::{Backend, DataContext, Linkage, ModuleNamespace, Writability,
DataDescription, Init, ModuleError};
use cretonne_module::{Backend, DataContext, DataDescription, Init, Linkage, ModuleError,
ModuleNamespace, Writability};
use cretonne_native;
use libc;
use memory::Memory;
use std::ffi::CString;
use std::ptr;
use libc;
#[cfg(windows)]
use winapi;
use memory::Memory;
/// A builder for `SimpleJITBackend`.
pub struct SimpleJITBuilder {
@@ -119,9 +119,9 @@ impl<'simple_jit_backend> Backend for SimpleJITBackend {
code_size: u32,
) -> Result<Self::CompiledFunction, ModuleError> {
let size = code_size as usize;
let ptr = self.code_memory.allocate(size).expect(
"TODO: handle OOM etc.",
);
let ptr = self.code_memory
.allocate(size)
.expect("TODO: handle OOM etc.");
let mut reloc_sink = SimpleJITRelocSink::new();
// Ignore traps for now. For now, frontends should just avoid generating code
// that traps.
@@ -152,16 +152,12 @@ impl<'simple_jit_backend> Backend for SimpleJITBackend {
let size = init.size();
let storage = match writable {
Writability::Readonly => {
self.writable_memory.allocate(size).expect(
"TODO: handle OOM etc.",
)
}
Writability::Writable => {
self.writable_memory.allocate(size).expect(
"TODO: handle OOM etc.",
)
}
Writability::Readonly => self.writable_memory
.allocate(size)
.expect("TODO: handle OOM etc."),
Writability::Writable => self.writable_memory
.allocate(size)
.expect("TODO: handle OOM etc."),
};
match *init {
@@ -262,20 +258,25 @@ impl<'simple_jit_backend> Backend for SimpleJITBackend {
Reloc::Abs4 => {
// TODO: Handle overflow.
#[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
unsafe { write_unaligned(at as *mut u32, what as u32) };
unsafe {
write_unaligned(at as *mut u32, what as u32)
};
}
Reloc::Abs8 => {
#[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
unsafe { write_unaligned(at as *mut u64, what as u64) };
unsafe {
write_unaligned(at as *mut u64, what as u64)
};
}
Reloc::X86PCRel4 => {
// TODO: Handle overflow.
let pcrel = ((what as isize) - (at as isize)) as i32;
#[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
unsafe { write_unaligned(at as *mut i32, pcrel) };
unsafe {
write_unaligned(at as *mut i32, pcrel)
};
}
Reloc::X86GOTPCRel4 |
Reloc::X86PLTRel4 => panic!("unexpected PIC relocation"),
Reloc::X86GOTPCRel4 | Reloc::X86PLTRel4 => panic!("unexpected PIC relocation"),
_ => unimplemented!(),
}
}
@@ -322,15 +323,19 @@ impl<'simple_jit_backend> Backend for SimpleJITBackend {
Reloc::Abs4 => {
// TODO: Handle overflow.
#[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
unsafe { write_unaligned(at as *mut u32, what as u32) };
unsafe {
write_unaligned(at as *mut u32, what as u32)
};
}
Reloc::Abs8 => {
#[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
unsafe { write_unaligned(at as *mut u64, what as u64) };
unsafe {
write_unaligned(at as *mut u64, what as u64)
};
}
Reloc::X86PCRel4 | Reloc::X86GOTPCRel4 | Reloc::X86PLTRel4 => {
panic!("unexpected text relocation in data")
}
Reloc::X86PCRel4 |
Reloc::X86GOTPCRel4 |
Reloc::X86PLTRel4 => panic!("unexpected text relocation in data"),
_ => unimplemented!(),
}
}

View File

@@ -3,25 +3,17 @@
#![deny(missing_docs, trivial_numeric_casts, unused_extern_crates)]
#![warn(unused_import_braces, unstable_features)]
#![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))]
#![cfg_attr(feature = "cargo-clippy", allow(new_without_default, new_without_default_derive))]
#![cfg_attr(feature = "cargo-clippy",
allow(new_without_default, new_without_default_derive))]
#![cfg_attr(feature="cargo-clippy", warn(
float_arithmetic,
mut_mut,
nonminimal_bool,
option_map_unwrap_or,
option_map_unwrap_or_else,
print_stdout,
unicode_not_nfc,
use_self,
))]
warn(float_arithmetic, mut_mut, nonminimal_bool, option_map_unwrap_or,
option_map_unwrap_or_else, print_stdout, unicode_not_nfc, use_self))]
extern crate cretonne_codegen;
extern crate cretonne_module;
extern crate cretonne_native;
extern crate errno;
extern crate region;
extern crate libc;
extern crate region;
#[cfg(target_os = "windows")]
extern crate winapi;
@@ -29,4 +21,4 @@ extern crate winapi;
mod backend;
mod memory;
pub use backend::{SimpleJITBuilder, SimpleJITBackend};
pub use backend::{SimpleJITBackend, SimpleJITBuilder};

View File

@@ -1,8 +1,8 @@
use std::mem;
use std::ptr;
use errno;
use libc;
use region;
use std::mem;
use std::ptr;
/// Round `size` up to the nearest multiple of `page_size`.
fn round_up_to_page_size(size: usize, page_size: usize) -> usize {
@@ -91,10 +91,8 @@ impl Memory {
}
fn finish_current(&mut self) {
self.allocations.push(mem::replace(
&mut self.current,
PtrLen::new(),
));
self.allocations
.push(mem::replace(&mut self.current, PtrLen::new()));
self.position = 0;
}
@@ -136,9 +134,8 @@ impl Memory {
for &PtrLen { ptr, len } in &self.allocations[self.executable..] {
if len != 0 {
unsafe {
region::protect(ptr, len, region::Protection::Read).expect(
"unable to make memory readonly",
);
region::protect(ptr, len, region::Protection::Read)
.expect("unable to make memory readonly");
}
}
}