Enable and fix several more clippy lints.

This commit is contained in:
Dan Gohman
2018-04-02 08:48:06 -07:00
parent 5c6cb202d8
commit bf597b7abf
71 changed files with 360 additions and 219 deletions

View File

@@ -1,3 +1,15 @@
#![deny(trivial_numeric_casts, unused_extern_crates)]
#![warn(unused_import_braces, unstable_features)]
#![cfg_attr(feature="cargo-clippy", warn(
float_arithmetic,
mut_mut,
nonminimal_bool,
option_map_unwrap_or,
option_map_unwrap_or_else,
unicode_not_nfc,
use_self,
))]
extern crate cretonne_codegen;
extern crate cretonne_filetests;
extern crate cretonne_reader;

View File

@@ -47,7 +47,7 @@ def gen_formats(fmt):
with fmt.indented(
"impl<'a> From<&'a InstructionData> for InstructionFormat {", '}'):
with fmt.indented(
"fn from(inst: &'a InstructionData) -> InstructionFormat {",
"fn from(inst: &'a InstructionData) -> Self {",
'}'):
m = srcgen.Match('*inst')
for f in InstructionFormat.all_formats:

View File

@@ -29,7 +29,7 @@ def gen_enum_types(sgrp, fmt):
continue
ty = camel_case(setting.name)
fmt.doc_comment('Values for `{}`.'.format(setting))
fmt.line('#[derive(Debug, PartialEq, Eq)]')
fmt.line('#[derive(Debug, Copy, Clone, PartialEq, Eq)]')
with fmt.indented('pub enum {} {{'.format(ty), '}'):
for v in setting.values:
fmt.doc_comment('`{}`.'.format(v))
@@ -223,7 +223,7 @@ def gen_display(sgrp, fmt):
fmt.line(
'TEMPLATE.format_toml_value(d.detail,' +
'self.bytes[d.offset as usize], f)?;')
fmt.line('writeln!(f, "")?;')
fmt.line('writeln!(f)?;')
fmt.line('Ok(())')
@@ -241,7 +241,7 @@ def gen_constructor(sgrp, parent, fmt):
fmt.doc_comment('Create flags {} settings group.'.format(sgrp.name))
fmt.line('#[allow(unused_variables)]')
with fmt.indented(
'pub fn new({}) -> Flags {{'.format(args), '}'):
'pub fn new({}) -> Self {{'.format(args), '}'):
fmt.line('let bvec = builder.state_for("{}");'.format(sgrp.name))
fmt.line('let mut bytes = [0; {}];'.format(sgrp.byte_size()))
fmt.line(
@@ -252,12 +252,12 @@ def gen_constructor(sgrp, parent, fmt):
# Stop here without predicates.
if len(sgrp.predicate_number) == sgrp.boolean_settings:
fmt.line('Flags { bytes: bytes }')
fmt.line('Self { bytes }')
return
# Now compute the predicates.
fmt.line(
'let mut {} = Flags {{ bytes: bytes }};'
'let mut {} = Self {{ bytes }};'
.format(sgrp.name))
for pred, number in sgrp.predicate_number.items():

View File

@@ -530,7 +530,7 @@ puid_bool = TailRecipe(
// The destination register is encoded in the low bits of the opcode.
// No ModR/M.
PUT_OP(bits | (out_reg0 & 7), rex1(out_reg0), sink);
let imm: u32 = if imm.into() { 1 } else { 0 };
let imm: u32 = if imm { 1 } else { 0 };
sink.put4(imm);
''')

View File

@@ -25,13 +25,13 @@ pub enum ArgAction {
}
impl From<ArgumentLoc> for ArgAction {
fn from(x: ArgumentLoc) -> ArgAction {
fn from(x: ArgumentLoc) -> Self {
ArgAction::Assign(x)
}
}
impl From<ValueConversion> for ArgAction {
fn from(x: ValueConversion) -> ArgAction {
fn from(x: ValueConversion) -> Self {
ArgAction::Convert(x)
}
}

View File

@@ -45,8 +45,8 @@ where
C: Comparator<K>,
{
/// Create a new empty forest.
pub fn new() -> MapForest<K, V, C> {
MapForest { nodes: NodePool::new() }
pub fn new() -> Self {
Self { nodes: NodePool::new() }
}
/// Clear all maps in the forest.
@@ -83,8 +83,8 @@ where
C: Comparator<K>,
{
/// Make an empty map.
pub fn new() -> Map<K, V, C> {
Map {
pub fn new() -> Self {
Self {
root: None.into(),
unused: PhantomData,
}

View File

@@ -73,7 +73,7 @@ impl<F: Forest> NodeData<F> {
}
/// Create an inner node with a single key and two sub-trees.
pub fn inner(left: Node, key: F::Key, right: Node) -> NodeData<F> {
pub fn inner(left: Node, key: F::Key, right: Node) -> Self {
// Splat the key and right node to the whole array.
// Saves us from inventing a default/reserved value.
let mut tree = [right; INNER_SIZE];
@@ -86,7 +86,7 @@ impl<F: Forest> NodeData<F> {
}
/// Create a leaf node with a single key-value pair.
pub fn leaf(key: F::Key, value: F::Value) -> NodeData<F> {
pub fn leaf(key: F::Key, value: F::Value) -> Self {
NodeData::Leaf {
size: 1,
keys: F::splat_key(key),
@@ -360,7 +360,7 @@ impl<F: Forest> NodeData<F> {
///
/// In the first case, `None` is returned. In the second case, the new critical key for the
/// right sibling node is returned.
pub fn balance(&mut self, crit_key: F::Key, rhs: &mut NodeData<F>) -> Option<F::Key> {
pub fn balance(&mut self, crit_key: F::Key, rhs: &mut Self) -> Option<F::Key> {
match (self, rhs) {
(&mut NodeData::Inner {
size: ref mut l_size,
@@ -514,7 +514,7 @@ pub(super) enum Removed {
impl Removed {
/// Create a `Removed` status from a size and capacity.
fn new(removed: usize, new_size: usize, capacity: usize) -> Removed {
fn new(removed: usize, new_size: usize, capacity: usize) -> Self {
if 2 * new_size >= capacity {
if removed == new_size {
Removed::Rightmost

View File

@@ -22,8 +22,8 @@ pub(super) struct Path<F: Forest> {
}
impl<F: Forest> Default for Path<F> {
fn default() -> Path<F> {
Path {
fn default() -> Self {
Self {
size: 0,
node: [Node(0); MAX_PATH],
entry: [0; MAX_PATH],

View File

@@ -12,8 +12,8 @@ pub(super) struct NodePool<F: Forest> {
impl<F: Forest> NodePool<F> {
/// Allocate a new empty pool of nodes.
pub fn new() -> NodePool<F> {
NodePool {
pub fn new() -> Self {
Self {
nodes: PrimaryMap::new(),
freelist: None,
}

View File

@@ -42,8 +42,8 @@ where
C: Comparator<K>,
{
/// Create a new empty forest.
pub fn new() -> SetForest<K, C> {
SetForest { nodes: NodePool::new() }
pub fn new() -> Self {
Self { nodes: NodePool::new() }
}
/// Clear all sets in the forest.
@@ -78,8 +78,8 @@ where
C: Comparator<K>,
{
/// Make an empty set.
pub fn new() -> Set<K, C> {
Set {
pub fn new() -> Self {
Self {
root: None.into(),
unused: PhantomData,
}

View File

@@ -48,12 +48,12 @@ impl fmt::Display for Reloc {
/// already unambigious, e.g. cton syntax with isa specified. In other contexts, use Debug.
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Reloc::Abs4 => write!(f, "{}", "Abs4"),
Reloc::Abs8 => write!(f, "{}", "Abs8"),
Reloc::X86PCRel4 => write!(f, "{}", "PCRel4"),
Reloc::X86GOTPCRel4 => write!(f, "{}", "GOTPCRel4"),
Reloc::X86PLTRel4 => write!(f, "{}", "PLTRel4"),
Reloc::Arm32Call | Reloc::Arm64Call | Reloc::RiscvCall => write!(f, "{}", "Call"),
Reloc::Abs4 => write!(f, "Abs4"),
Reloc::Abs8 => write!(f, "Abs8"),
Reloc::X86PCRel4 => write!(f, "PCRel4"),
Reloc::X86GOTPCRel4 => write!(f, "GOTPCRel4"),
Reloc::X86PLTRel4 => write!(f, "PLTRel4"),
Reloc::Arm32Call | Reloc::Arm64Call | Reloc::RiscvCall => write!(f, "Call"),
}
}
}

View File

@@ -52,7 +52,7 @@ impl Context {
/// The returned instance should be reused for compiling multiple functions in order to avoid
/// needless allocator thrashing.
pub fn new() -> Self {
Context::for_function(Function::new())
Self::for_function(Function::new())
}
/// Allocate a new compilation context with an existing Function.
@@ -61,7 +61,7 @@ impl Context {
/// needless allocator thrashing.
pub fn for_function(func: Function) -> Self {
Self {
func: func,
func,
cfg: ControlFlowGraph::new(),
domtree: DominatorTree::new(),
regalloc: regalloc::Context::new(),

View File

@@ -528,8 +528,8 @@ struct ExtraNode {
/// Creating and computing the dominator tree pre-order.
impl DominatorTreePreorder {
/// Create a new blank `DominatorTreePreorder`.
pub fn new() -> DominatorTreePreorder {
DominatorTreePreorder {
pub fn new() -> Self {
Self {
nodes: EntityMap::new(),
stack: Vec::new(),
}

View File

@@ -31,7 +31,7 @@ impl Ebb {
/// Create a new EBB reference from its number. This corresponds to the `ebbNN` representation.
///
/// This method is for use by the parser.
pub fn with_number(n: u32) -> Option<Ebb> {
pub fn with_number(n: u32) -> Option<Self> {
if n < u32::MAX { Some(Ebb(n)) } else { None }
}
}
@@ -46,7 +46,7 @@ impl Value {
/// This is the number in the `vNN` notation.
///
/// This method is for use by the parser.
pub fn with_number(n: u32) -> Option<Value> {
pub fn with_number(n: u32) -> Option<Self> {
if n < u32::MAX / 2 {
Some(Value(n))
} else {
@@ -69,7 +69,7 @@ impl StackSlot {
/// Create a new stack slot reference from its number.
///
/// This method is for use by the parser.
pub fn with_number(n: u32) -> Option<StackSlot> {
pub fn with_number(n: u32) -> Option<Self> {
if n < u32::MAX {
Some(StackSlot(n))
} else {
@@ -87,7 +87,7 @@ impl GlobalVar {
/// Create a new global variable reference from its number.
///
/// This method is for use by the parser.
pub fn with_number(n: u32) -> Option<GlobalVar> {
pub fn with_number(n: u32) -> Option<Self> {
if n < u32::MAX {
Some(GlobalVar(n))
} else {
@@ -105,7 +105,7 @@ impl JumpTable {
/// Create a new jump table reference from its number.
///
/// This method is for use by the parser.
pub fn with_number(n: u32) -> Option<JumpTable> {
pub fn with_number(n: u32) -> Option<Self> {
if n < u32::MAX {
Some(JumpTable(n))
} else {
@@ -123,7 +123,7 @@ impl FuncRef {
/// Create a new external function reference from its number.
///
/// This method is for use by the parser.
pub fn with_number(n: u32) -> Option<FuncRef> {
pub fn with_number(n: u32) -> Option<Self> {
if n < u32::MAX { Some(FuncRef(n)) } else { None }
}
}
@@ -137,7 +137,7 @@ impl SigRef {
/// Create a new function signature reference from its number.
///
/// This method is for use by the parser.
pub fn with_number(n: u32) -> Option<SigRef> {
pub fn with_number(n: u32) -> Option<Self> {
if n < u32::MAX { Some(SigRef(n)) } else { None }
}
}
@@ -151,7 +151,7 @@ impl Heap {
/// Create a new heap reference from its number.
///
/// This method is for use by the parser.
pub fn with_number(n: u32) -> Option<Heap> {
pub fn with_number(n: u32) -> Option<Self> {
if n < u32::MAX { Some(Heap(n)) } else { None }
}
}
@@ -205,55 +205,55 @@ impl fmt::Debug for AnyEntity {
}
impl From<Ebb> for AnyEntity {
fn from(r: Ebb) -> AnyEntity {
fn from(r: Ebb) -> Self {
AnyEntity::Ebb(r)
}
}
impl From<Inst> for AnyEntity {
fn from(r: Inst) -> AnyEntity {
fn from(r: Inst) -> Self {
AnyEntity::Inst(r)
}
}
impl From<Value> for AnyEntity {
fn from(r: Value) -> AnyEntity {
fn from(r: Value) -> Self {
AnyEntity::Value(r)
}
}
impl From<StackSlot> for AnyEntity {
fn from(r: StackSlot) -> AnyEntity {
fn from(r: StackSlot) -> Self {
AnyEntity::StackSlot(r)
}
}
impl From<GlobalVar> for AnyEntity {
fn from(r: GlobalVar) -> AnyEntity {
fn from(r: GlobalVar) -> Self {
AnyEntity::GlobalVar(r)
}
}
impl From<JumpTable> for AnyEntity {
fn from(r: JumpTable) -> AnyEntity {
fn from(r: JumpTable) -> Self {
AnyEntity::JumpTable(r)
}
}
impl From<FuncRef> for AnyEntity {
fn from(r: FuncRef) -> AnyEntity {
fn from(r: FuncRef) -> Self {
AnyEntity::FuncRef(r)
}
}
impl From<SigRef> for AnyEntity {
fn from(r: SigRef) -> AnyEntity {
fn from(r: SigRef) -> Self {
AnyEntity::SigRef(r)
}
}
impl From<Heap> for AnyEntity {
fn from(r: Heap) -> AnyEntity {
fn from(r: Heap) -> Self {
AnyEntity::Heap(r)
}
}

View File

@@ -304,7 +304,7 @@ impl fmt::Display for ArgumentPurpose {
impl FromStr for ArgumentPurpose {
type Err = ();
fn from_str(s: &str) -> Result<ArgumentPurpose, ()> {
fn from_str(s: &str) -> Result<Self, ()> {
match s {
"normal" => Ok(ArgumentPurpose::Normal),
"sret" => Ok(ArgumentPurpose::StructReturn),

View File

@@ -56,7 +56,7 @@ impl ExternalName {
/// let name = ExternalName::testcase("hello");
/// assert_eq!(name.to_string(), "%hello");
/// ```
pub fn testcase<T: AsRef<[u8]>>(v: T) -> ExternalName {
pub fn testcase<T: AsRef<[u8]>>(v: T) -> Self {
let vec = v.as_ref();
let len = cmp::min(vec.len(), TESTCASE_NAME_LENGTH);
let mut bytes = [0u8; TESTCASE_NAME_LENGTH];
@@ -77,17 +77,14 @@ impl ExternalName {
/// let name = ExternalName::user(123, 456);
/// assert_eq!(name.to_string(), "u123:456");
/// ```
pub fn user(namespace: u32, index: u32) -> ExternalName {
ExternalName::User {
namespace: namespace,
index: index,
}
pub fn user(namespace: u32, index: u32) -> Self {
ExternalName::User { namespace, index }
}
}
impl Default for ExternalName {
fn default() -> ExternalName {
ExternalName::user(0, 0)
fn default() -> Self {
Self::user(0, 0)
}
}

View File

@@ -18,12 +18,12 @@ pub struct Imm64(i64);
impl Imm64 {
/// Create a new `Imm64` representing the signed number `x`.
pub fn new(x: i64) -> Imm64 {
pub fn new(x: i64) -> Self {
Imm64(x)
}
/// Return self negated.
pub fn wrapping_neg(self) -> Imm64 {
pub fn wrapping_neg(self) -> Self {
Imm64(self.0.wrapping_neg())
}
}
@@ -143,8 +143,8 @@ impl FromStr for Imm64 {
type Err = &'static str;
// Parse a decimal or hexadecimal `Imm64`, formatted as above.
fn from_str(s: &str) -> Result<Imm64, &'static str> {
parse_i64(s).map(Imm64::new)
fn from_str(s: &str) -> Result<Self, &'static str> {
parse_i64(s).map(Self::new)
}
}
@@ -191,7 +191,7 @@ impl FromStr for Uimm32 {
type Err = &'static str;
// Parse a decimal or hexadecimal `Uimm32`, formatted as above.
fn from_str(s: &str) -> Result<Uimm32, &'static str> {
fn from_str(s: &str) -> Result<Self, &'static str> {
parse_i64(s).and_then(|x| if 0 <= x && x <= i64::from(u32::MAX) {
Ok(Uimm32(x as u32))
} else {
@@ -209,7 +209,7 @@ pub struct Offset32(i32);
impl Offset32 {
/// Create a new `Offset32` representing the signed number `x`.
pub fn new(x: i32) -> Offset32 {
pub fn new(x: i32) -> Self {
Offset32(x)
}
}
@@ -255,14 +255,14 @@ impl FromStr for Offset32 {
type Err = &'static str;
// Parse a decimal or hexadecimal `Offset32`, formatted as above.
fn from_str(s: &str) -> Result<Offset32, &'static str> {
fn from_str(s: &str) -> Result<Self, &'static str> {
if !(s.starts_with('-') || s.starts_with('+')) {
return Err("Offset must begin with sign");
}
parse_i64(s).and_then(|x| if i64::from(i32::MIN) <= x &&
x <= i64::from(i32::MAX)
{
Ok(Offset32::new(x as i32))
Ok(Self::new(x as i32))
} else {
Err("Offset out of range")
})
@@ -524,12 +524,12 @@ fn parse_float(s: &str, w: u8, t: u8) -> Result<u64, &'static str> {
impl Ieee32 {
/// Create a new `Ieee32` containing the bits of `x`.
pub fn with_bits(x: u32) -> Ieee32 {
pub fn with_bits(x: u32) -> Self {
Ieee32(x)
}
/// Create an `Ieee32` number representing `2.0^n`.
pub fn pow2<I: Into<i32>>(n: I) -> Ieee32 {
pub fn pow2<I: Into<i32>>(n: I) -> Self {
let n = n.into();
let w = 8;
let t = 23;
@@ -542,7 +542,7 @@ impl Ieee32 {
/// Create an `Ieee32` number representing the greatest negative value
/// not convertable from f32 to a signed integer with width n.
pub fn fcvt_to_sint_negative_overflow<I: Into<i32>>(n: I) -> Ieee32 {
pub fn fcvt_to_sint_negative_overflow<I: Into<i32>>(n: I) -> Self {
let n = n.into();
debug_assert!(n < 32);
debug_assert!(23 + 1 - n < 32);
@@ -552,12 +552,12 @@ impl Ieee32 {
}
/// Return self negated.
pub fn neg(self) -> Ieee32 {
pub fn neg(self) -> Self {
Ieee32(self.0 ^ (1 << 31))
}
/// Create a new `Ieee32` representing the number `x`.
pub fn with_float(x: f32) -> Ieee32 {
pub fn with_float(x: f32) -> Self {
Ieee32(unsafe { mem::transmute(x) })
}
@@ -577,7 +577,7 @@ impl Display for Ieee32 {
impl FromStr for Ieee32 {
type Err = &'static str;
fn from_str(s: &str) -> Result<Ieee32, &'static str> {
fn from_str(s: &str) -> Result<Self, &'static str> {
match parse_float(s, 8, 23) {
Ok(b) => Ok(Ieee32(b as u32)),
Err(s) => Err(s),
@@ -587,12 +587,12 @@ impl FromStr for Ieee32 {
impl Ieee64 {
/// Create a new `Ieee64` containing the bits of `x`.
pub fn with_bits(x: u64) -> Ieee64 {
pub fn with_bits(x: u64) -> Self {
Ieee64(x)
}
/// Create an `Ieee64` number representing `2.0^n`.
pub fn pow2<I: Into<i64>>(n: I) -> Ieee64 {
pub fn pow2<I: Into<i64>>(n: I) -> Self {
let n = n.into();
let w = 11;
let t = 52;
@@ -605,7 +605,7 @@ impl Ieee64 {
/// Create an `Ieee64` number representing the greatest negative value
/// not convertable from f64 to a signed integer with width n.
pub fn fcvt_to_sint_negative_overflow<I: Into<i64>>(n: I) -> Ieee64 {
pub fn fcvt_to_sint_negative_overflow<I: Into<i64>>(n: I) -> Self {
let n = n.into();
debug_assert!(n < 64);
debug_assert!(52 + 1 - n < 64);
@@ -615,12 +615,12 @@ impl Ieee64 {
}
/// Return self negated.
pub fn neg(self) -> Ieee64 {
pub fn neg(self) -> Self {
Ieee64(self.0 ^ (1 << 63))
}
/// Create a new `Ieee64` representing the number `x`.
pub fn with_float(x: f64) -> Ieee64 {
pub fn with_float(x: f64) -> Self {
Ieee64(unsafe { mem::transmute(x) })
}
@@ -640,7 +640,7 @@ impl Display for Ieee64 {
impl FromStr for Ieee64 {
type Err = &'static str;
fn from_str(s: &str) -> Result<Ieee64, &'static str> {
fn from_str(s: &str) -> Result<Self, &'static str> {
match parse_float(s, 11, 52) {
Ok(b) => Ok(Ieee64(b)),
Err(s) => Err(s),

View File

@@ -72,7 +72,7 @@ impl FromStr for Opcode {
type Err = &'static str;
/// Parse an Opcode name from a string.
fn from_str(s: &str) -> Result<Opcode, &'static str> {
fn from_str(s: &str) -> Result<Self, &'static str> {
use constant_hash::{probe, simple_hash, Table};
impl<'a> Table<&'a str> for [Option<Opcode>] {
@@ -85,7 +85,7 @@ impl FromStr for Opcode {
}
}
match probe::<&str, [Option<Opcode>]>(&OPCODE_HASH_TABLE, s, simple_hash(s)) {
match probe::<&str, [Option<Self>]>(&OPCODE_HASH_TABLE, s, simple_hash(s)) {
Err(_) => Err("Unknown opcode"),
// We unwrap here because probe() should have ensured that the entry
// at this index is not None.

View File

@@ -72,7 +72,7 @@ impl LibCall {
/// given opcode and controlling type variable.
///
/// Returns `None` if no well-known library routine name exists for that instruction.
pub fn for_inst(opcode: Opcode, ctrl_type: Type) -> Option<LibCall> {
pub fn for_inst(opcode: Opcode, ctrl_type: Type) -> Option<Self> {
Some(match ctrl_type {
types::F32 => {
match opcode {

View File

@@ -17,7 +17,7 @@ use std::u32;
pub struct ProgramPoint(u32);
impl From<Inst> for ProgramPoint {
fn from(inst: Inst) -> ProgramPoint {
fn from(inst: Inst) -> Self {
let idx = inst.index();
debug_assert!(idx < (u32::MAX / 2) as usize);
ProgramPoint((idx * 2) as u32)
@@ -25,7 +25,7 @@ impl From<Inst> for ProgramPoint {
}
impl From<Ebb> for ProgramPoint {
fn from(ebb: Ebb) -> ProgramPoint {
fn from(ebb: Ebb) -> Self {
let idx = ebb.index();
debug_assert!(idx < (u32::MAX / 2) as usize);
ProgramPoint((idx * 2 + 1) as u32)
@@ -33,7 +33,7 @@ impl From<Ebb> for ProgramPoint {
}
impl From<ValueDef> for ProgramPoint {
fn from(def: ValueDef) -> ProgramPoint {
fn from(def: ValueDef) -> Self {
match def {
ValueDef::Result(inst, _) => inst.into(),
ValueDef::Param(ebb, _) => ebb.into(),
@@ -62,19 +62,19 @@ impl ExpandedProgramPoint {
}
impl From<Inst> for ExpandedProgramPoint {
fn from(inst: Inst) -> ExpandedProgramPoint {
fn from(inst: Inst) -> Self {
ExpandedProgramPoint::Inst(inst)
}
}
impl From<Ebb> for ExpandedProgramPoint {
fn from(ebb: Ebb) -> ExpandedProgramPoint {
fn from(ebb: Ebb) -> Self {
ExpandedProgramPoint::Ebb(ebb)
}
}
impl From<ValueDef> for ExpandedProgramPoint {
fn from(def: ValueDef) -> ExpandedProgramPoint {
fn from(def: ValueDef) -> Self {
match def {
ValueDef::Result(inst, _) => inst.into(),
ValueDef::Param(ebb, _) => ebb.into(),
@@ -83,7 +83,7 @@ impl From<ValueDef> for ExpandedProgramPoint {
}
impl From<ProgramPoint> for ExpandedProgramPoint {
fn from(pp: ProgramPoint) -> ExpandedProgramPoint {
fn from(pp: ProgramPoint) -> Self {
if pp.0 & 1 == 0 {
ExpandedProgramPoint::Inst(Inst::new((pp.0 / 2) as usize))
} else {

View File

@@ -17,7 +17,7 @@ pub struct SourceLoc(u32);
impl SourceLoc {
/// Create a new source location with the given bits.
pub fn new(bits: u32) -> SourceLoc {
pub fn new(bits: u32) -> Self {
SourceLoc(bits)
}

View File

@@ -70,7 +70,7 @@ pub enum StackSlotKind {
impl FromStr for StackSlotKind {
type Err = ();
fn from_str(s: &str) -> Result<StackSlotKind, ()> {
fn from_str(s: &str) -> Result<Self, ()> {
use self::StackSlotKind::*;
match s {
"explicit_slot" => Ok(ExplicitSlot),
@@ -117,8 +117,8 @@ pub struct StackSlotData {
impl StackSlotData {
/// Create a stack slot with the specified byte size.
pub fn new(kind: StackSlotKind, size: StackSize) -> StackSlotData {
StackSlotData {
pub fn new(kind: StackSlotKind, size: StackSize) -> Self {
Self {
kind,
size,
offset: None,

View File

@@ -39,7 +39,7 @@ impl Type {
/// Get the lane type of this SIMD vector type.
///
/// A lane type is the same as a SIMD vector type with one lane, so it returns itself.
pub fn lane_type(self) -> Type {
pub fn lane_type(self) -> Self {
if self.0 < VECTOR_BASE {
self
} else {
@@ -72,7 +72,7 @@ impl Type {
}
/// Get an integer type with the requested number of bits.
pub fn int(bits: u16) -> Option<Type> {
pub fn int(bits: u16) -> Option<Self> {
match bits {
8 => Some(I8),
16 => Some(I16),
@@ -83,7 +83,7 @@ impl Type {
}
/// Get a type with the same number of lanes as `self`, but using `lane` as the lane type.
fn replace_lanes(self, lane: Type) -> Type {
fn replace_lanes(self, lane: Self) -> Self {
debug_assert!(lane.is_lane() && !self.is_special());
Type((lane.0 & 0x0f) | (self.0 & 0xf0))
}
@@ -93,7 +93,7 @@ impl Type {
///
/// Scalar types are treated as vectors with one lane, so they are converted to the multi-bit
/// boolean types.
pub fn as_bool_pedantic(self) -> Type {
pub fn as_bool_pedantic(self) -> Self {
// Replace the low 4 bits with the boolean version, preserve the high 4 bits.
self.replace_lanes(match self.lane_type() {
B8 | I8 => B8,
@@ -108,7 +108,7 @@ impl Type {
/// booleans of the same size.
///
/// Scalar types are all converted to `b1` which is usually what you want.
pub fn as_bool(self) -> Type {
pub fn as_bool(self) -> Self {
if !self.is_vector() {
B1
} else {
@@ -118,7 +118,7 @@ impl Type {
/// Get a type with the same number of lanes as this type, but with lanes that are half the
/// number of bits.
pub fn half_width(self) -> Option<Type> {
pub fn half_width(self) -> Option<Self> {
Some(self.replace_lanes(match self.lane_type() {
I16 => I8,
I32 => I16,
@@ -133,7 +133,7 @@ impl Type {
/// Get a type with the same number of lanes as this type, but with lanes that are twice the
/// number of bits.
pub fn double_width(self) -> Option<Type> {
pub fn double_width(self) -> Option<Self> {
Some(self.replace_lanes(match self.lane_type() {
I8 => I16,
I16 => I32,
@@ -235,7 +235,7 @@ impl Type {
///
/// If this is already a SIMD vector type, this produces a SIMD vector type with `n *
/// self.lane_count()` lanes.
pub fn by(self, n: u16) -> Option<Type> {
pub fn by(self, n: u16) -> Option<Self> {
if self.lane_bits() == 0 || !n.is_power_of_two() {
return None;
}
@@ -251,7 +251,7 @@ impl Type {
/// Get a SIMD vector with half the number of lanes.
///
/// There is no `double_vector()` method. Use `t.by(2)` instead.
pub fn half_vector(self) -> Option<Type> {
pub fn half_vector(self) -> Option<Self> {
if self.is_vector() {
Some(Type(self.0 - 0x10))
} else {
@@ -268,7 +268,7 @@ impl Type {
///
/// 1. `self.lane_count() == other.lane_count()` and
/// 2. `self.lane_bits() >= other.lane_bits()`
pub fn wider_or_equal(self, other: Type) -> bool {
pub fn wider_or_equal(self, other: Self) -> bool {
self.lane_count() == other.lane_count() && self.lane_bits() >= other.lane_bits()
}
}

View File

@@ -18,8 +18,8 @@ pub struct Encoding {
impl Encoding {
/// Create a new `Encoding` containing `(recipe, bits)`.
pub fn new(recipe: u16, bits: u16) -> Encoding {
Encoding { recipe, bits }
pub fn new(recipe: u16, bits: u16) -> Self {
Self { recipe, bits }
}
/// Get the recipe number in this encoding.
@@ -122,10 +122,10 @@ impl EncInfo {
///
/// Returns 0 for illegal encodings.
pub fn bytes(&self, enc: Encoding) -> CodeOffset {
self.sizing
.get(enc.recipe())
.map(|s| CodeOffset::from(s.bytes))
.unwrap_or(0)
self.sizing.get(enc.recipe()).map_or(
0,
|s| CodeOffset::from(s.bytes),
)
}
/// Get the branch range that is supported by `enc`, if any.

View File

@@ -24,8 +24,8 @@ struct Args {
}
impl Args {
fn new(bits: u16, enable_e: bool) -> Args {
Args {
fn new(bits: u16, enable_e: bool) -> Self {
Self {
pointer_bits: bits,
pointer_bytes: u32::from(bits) / 8,
pointer_type: Type::int(bits).unwrap(),

View File

@@ -23,10 +23,10 @@ pub struct StackRef {
impl StackRef {
/// Get a reference to the stack slot `ss` using one of the base pointers in `mask`.
pub fn masked(ss: StackSlot, mask: StackBaseMask, frame: &StackSlots) -> Option<StackRef> {
pub fn masked(ss: StackSlot, mask: StackBaseMask, frame: &StackSlots) -> Option<Self> {
// Try an SP-relative reference.
if mask.contains(StackBase::SP) {
return Some(StackRef::sp(ss, frame));
return Some(Self::sp(ss, frame));
}
// No reference possible with this mask.
@@ -34,7 +34,7 @@ impl StackRef {
}
/// Get a reference to `ss` using the stack pointer as a base.
pub fn sp(ss: StackSlot, frame: &StackSlots) -> StackRef {
pub fn sp(ss: StackSlot, frame: &StackSlots) -> Self {
let size = frame.frame_size.expect(
"Stack layout must be computed before referencing stack slots",
);
@@ -48,7 +48,7 @@ impl StackRef {
let sp_offset = -(size as StackOffset);
slot.offset.unwrap() - sp_offset
};
StackRef {
Self {
base: StackBase::SP,
offset,
}

View File

@@ -34,8 +34,8 @@ struct Args {
}
impl Args {
fn new(bits: u16, gpr: &'static [RU], fpr_limit: usize, call_conv: CallConv) -> Args {
Args {
fn new(bits: u16, gpr: &'static [RU], fpr_limit: usize, call_conv: CallConv) -> Self {
Self {
pointer_bytes: u32::from(bits) / 8,
pointer_bits: bits,
pointer_type: ir::Type::int(bits).unwrap(),
@@ -44,7 +44,7 @@ impl Args {
fpr_limit,
fpr_used: 0,
offset: 0,
call_conv: call_conv,
call_conv,
}
}
}
@@ -205,7 +205,7 @@ fn callee_saved_gprs_used(flags: &shared_settings::Flags, func: &ir::Function) -
}
used.intersect(&all_callee_saved);
return used;
used
}
pub fn prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> result::CtonResult {

View File

@@ -1,6 +1,7 @@
//! Cretonne code generation library.
#![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(
// Rustfmt 0.9.0 is at odds with this lint:
@@ -29,6 +30,16 @@
redundant_field_names,
useless_let_if_seq,
len_without_is_empty))]
#![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,
))]
pub use context::Context;
pub use legalizer::legalize_function;

View File

@@ -150,7 +150,7 @@ fn is_loop_invariant(inst: Inst, dfg: &DataFlowGraph, loop_values: &HashSet<Valu
return false;
}
}
return true;
true
}
// Traverses a loop in reverse post-order from a header EBB and identify loop-invariant
@@ -173,7 +173,7 @@ fn remove_loop_invariant_instructions(
}
pos.goto_top(*ebb);
#[cfg_attr(feature = "cargo-clippy", allow(block_in_if_condition_stmt))]
'next_inst: while let Some(inst) = pos.next_inst() {
while let Some(inst) = pos.next_inst() {
if is_loop_invariant(inst, &pos.func.dfg, &loop_values) {
// If all the instruction's argument are defined outside the loop
// then this instruction is loop-invariant

View File

@@ -32,9 +32,9 @@ struct LoopData {
impl LoopData {
/// Creates a `LoopData` object with the loop header and its eventual parent in the loop tree.
pub fn new(header: Ebb, parent: Option<Loop>) -> LoopData {
LoopData {
header: header,
pub fn new(header: Ebb, parent: Option<Loop>) -> Self {
Self {
header,
parent: parent.into(),
}
}

View File

@@ -19,7 +19,7 @@ pub enum Affinity {
///
/// This indicates a value that is not defined or used by any real instructions. It is a ghost
/// value that won't appear in the final program.
None,
Unassigned,
/// This value should be placed in a spill slot on the stack.
Stack,
@@ -30,16 +30,16 @@ pub enum Affinity {
impl Default for Affinity {
fn default() -> Self {
Affinity::None
Affinity::Unassigned
}
}
impl Affinity {
/// Create an affinity that satisfies a single constraint.
///
/// This will never create an `Affinity::None`.
/// This will never create an `Affinity::Unassigned`.
/// Use the `Default` implementation for that.
pub fn new(constraint: &OperandConstraint) -> Affinity {
pub fn new(constraint: &OperandConstraint) -> Self {
if constraint.kind == ConstraintKind::Stack {
Affinity::Stack
} else {
@@ -48,18 +48,18 @@ impl Affinity {
}
/// Create an affinity that matches an ABI argument for `isa`.
pub fn abi(arg: &AbiParam, isa: &TargetIsa) -> Affinity {
pub fn abi(arg: &AbiParam, isa: &TargetIsa) -> Self {
match arg.location {
ArgumentLoc::Unassigned => Affinity::None,
ArgumentLoc::Unassigned => Affinity::Unassigned,
ArgumentLoc::Reg(_) => Affinity::Reg(isa.regclass_for_abi_type(arg.value_type).into()),
ArgumentLoc::Stack(_) => Affinity::Stack,
}
}
/// Is this the `None` affinity?
pub fn is_none(self) -> bool {
/// Is this the `Unassigned` affinity?
pub fn is_unassigned(self) -> bool {
match self {
Affinity::None => true,
Affinity::Unassigned => true,
_ => false,
}
}
@@ -86,15 +86,15 @@ impl Affinity {
/// satisfies the constraint.
pub fn merge(&mut self, constraint: &OperandConstraint, reg_info: &RegInfo) {
match *self {
Affinity::None => *self = Affinity::new(constraint),
Affinity::Unassigned => *self = Self::new(constraint),
Affinity::Reg(rc) => {
// If the preferred register class is a subclass of the constraint, there's no need
// to change anything.
if constraint.kind != ConstraintKind::Stack &&
!constraint.regclass.has_subclass(rc)
{
// If the register classes don't overlap, `intersect` returns `None`, and we
// just keep our previous affinity.
// If the register classes don't overlap, `intersect` returns `Unassigned`, and
// we just keep our previous affinity.
if let Some(subclass) = constraint.regclass.intersect_index(reg_info.rc(rc)) {
// This constraint shrinks our preferred register class.
*self = Affinity::Reg(subclass);
@@ -118,7 +118,7 @@ pub struct DisplayAffinity<'a>(Affinity, Option<&'a RegInfo>);
impl<'a> fmt::Display for DisplayAffinity<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.0 {
Affinity::None => write!(f, "none"),
Affinity::Unassigned => write!(f, "unassigned"),
Affinity::Stack => write!(f, "stack"),
Affinity::Reg(rci) => {
match self.1 {

View File

@@ -704,10 +704,10 @@ struct Node {
impl Node {
/// Create a node representing `value`.
pub fn value(value: Value, set_id: u8, func: &Function) -> Node {
pub fn value(value: Value, set_id: u8, func: &Function) -> Self {
let def = func.dfg.value_def(value).pp();
let ebb = func.layout.pp_ebb(def);
Node {
Self {
def,
ebb,
is_vcopy: false,
@@ -717,10 +717,10 @@ impl Node {
}
/// Create a node representing a virtual copy.
pub fn vcopy(branch: Inst, value: Value, set_id: u8, func: &Function) -> Node {
pub fn vcopy(branch: Inst, value: Value, set_id: u8, func: &Function) -> Self {
let def = branch.into();
let ebb = func.layout.pp_ebb(def);
Node {
Self {
def,
ebb,
is_vcopy: true,
@@ -891,8 +891,8 @@ struct VirtualCopies {
impl VirtualCopies {
/// Create an empty VirtualCopies struct.
pub fn new() -> VirtualCopies {
VirtualCopies {
pub fn new() -> Self {
Self {
params: Vec::new(),
branches: Vec::new(),
filter: Vec::new(),

View File

@@ -272,7 +272,7 @@ impl<'a> Context<'a> {
Affinity::Stack => debug_assert!(abi.location.is_stack()),
// This is a ghost value, unused in the function. Don't assign it to a location
// either.
Affinity::None => {}
Affinity::Unassigned => {}
}
}
@@ -1126,8 +1126,8 @@ struct AvailableRegs {
impl AvailableRegs {
/// Initialize both the input and global sets from `regs`.
pub fn new(regs: &RegisterSet) -> AvailableRegs {
AvailableRegs {
pub fn new(regs: &RegisterSet) -> Self {
Self {
input: regs.clone(),
global: regs.clone(),
}

View File

@@ -32,9 +32,9 @@ pub struct Diversion {
impl Diversion {
/// Make a new diversion.
pub fn new(value: Value, from: ValueLoc, to: ValueLoc) -> Diversion {
pub fn new(value: Value, from: ValueLoc, to: ValueLoc) -> Self {
debug_assert!(from.is_assigned() && to.is_assigned());
Diversion { value, from, to }
Self { value, from, to }
}
}

View File

@@ -179,7 +179,7 @@ use entity::SparseMap;
use flowgraph::ControlFlowGraph;
use ir::dfg::ValueDef;
use ir::{Ebb, Function, Inst, Layout, ProgramPoint, Value};
use isa::{EncInfo, TargetIsa};
use isa::{EncInfo, TargetIsa, OperandConstraint};
use regalloc::affinity::Affinity;
use regalloc::liverange::{LiveRange, LiveRangeContext, LiveRangeForest};
use std::mem;
@@ -413,11 +413,10 @@ impl Liveness {
// Iterator of constraints, one per value operand.
let encoding = func.encodings[inst];
let mut operand_constraints = enc_info
let operand_constraint_slice: &[OperandConstraint] = enc_info
.operand_constraints(encoding)
.map(|c| c.ins)
.unwrap_or(&[])
.iter();
.map_or(&[], |c| c.ins);
let mut operand_constraints = operand_constraint_slice.iter();
for &arg in func.dfg.inst_args(inst) {
// Get the live range, create it as a dead range if necessary.

View File

@@ -217,8 +217,8 @@ impl<PO: ProgramOrder> GenLiveRange<PO> {
/// Create a new live range for `value` defined at `def`.
///
/// The live range will be created as dead, but it can be extended with `extend_in_ebb()`.
pub fn new(value: Value, def: ProgramPoint, affinity: Affinity) -> GenLiveRange<PO> {
GenLiveRange {
pub fn new(value: Value, def: ProgramPoint, affinity: Affinity) -> Self {
Self {
value,
affinity,
def_begin: def,

View File

@@ -81,8 +81,8 @@ pub struct Pressure {
impl Pressure {
/// Create a new register pressure tracker.
pub fn new(reginfo: &RegInfo, usable: &RegisterSet) -> Pressure {
let mut p = Pressure {
pub fn new(reginfo: &RegInfo, usable: &RegisterSet) -> Self {
let mut p = Self {
aliased: 0,
toprc: Default::default(),
};

View File

@@ -103,7 +103,7 @@ impl RegisterSet {
/// of `other`.
///
/// This assumes that unused bits are 1.
pub fn interferes_with(&self, other: &RegisterSet) -> bool {
pub fn interferes_with(&self, other: &Self) -> bool {
self.avail.iter().zip(&other.avail).any(
|(&x, &y)| (x | y) != !0,
)
@@ -111,7 +111,7 @@ impl RegisterSet {
/// Intersect this set of registers with `other`. This has the effect of removing any register
/// units from this set that are not in `other`.
pub fn intersect(&mut self, other: &RegisterSet) {
pub fn intersect(&mut self, other: &Self) {
for (x, &y) in self.avail.iter_mut().zip(&other.avail) {
*x &= y;
}

View File

@@ -219,7 +219,7 @@ impl<'a> Context<'a> {
self.reloads.insert(ReloadedValue {
stack: cand.value,
reg: reg,
reg,
});
cand.value = reg;

View File

@@ -151,8 +151,8 @@ pub struct Variable {
}
impl Variable {
fn new_live(value: Value, constraint: RegClass, from: RegUnit, is_output: bool) -> Variable {
Variable {
fn new_live(value: Value, constraint: RegClass, from: RegUnit, is_output: bool) -> Self {
Self {
value,
constraint,
from: Some(from),
@@ -164,8 +164,8 @@ impl Variable {
}
}
fn new_def(value: Value, constraint: RegClass, is_global: bool) -> Variable {
Variable {
fn new_def(value: Value, constraint: RegClass, is_global: bool) -> Self {
Self {
value,
constraint,
from: None,
@@ -280,7 +280,7 @@ pub enum Move {
impl Move {
/// Create a register move from an assignment, but not for identity assignments.
fn with_assignment(a: &Assignment) -> Option<Move> {
fn with_assignment(a: &Assignment) -> Option<Self> {
if a.from != a.to {
Some(Move::Reg {
value: a.value,

View File

@@ -363,7 +363,7 @@ impl<'a> Context<'a> {
self.cur.isa.regclass_for_abi_type(abi.value_type).into(),
true,
),
Affinity::None => panic!("Missing affinity for {}", arg),
Affinity::Unassigned => panic!("Missing affinity for {}", arg),
};
let mut reguse = RegUse::new(arg, fixed_args + idx, rci);
reguse.fixed = true;
@@ -393,10 +393,9 @@ impl<'a> Context<'a> {
} else if ru.fixed {
// This is a fixed register use which doesn't necessarily require a copy.
// Make a copy only if this is not the first use of the value.
self.reg_uses
.get(i.wrapping_sub(1))
.map(|ru2| ru2.value == ru.value)
.unwrap_or(false)
self.reg_uses.get(i.wrapping_sub(1)).map_or(false, |ru2| {
ru2.value == ru.value
})
} else {
false
};
@@ -567,8 +566,8 @@ struct RegUse {
}
impl RegUse {
fn new(value: Value, idx: usize, rci: RegClassIndex) -> RegUse {
RegUse {
fn new(value: Value, idx: usize, rci: RegClassIndex) -> Self {
Self {
value,
opidx: idx as u16,
rci,

View File

@@ -101,10 +101,9 @@ impl VirtRegs {
where
'a: 'b,
{
self.get(*value).map(|vr| self.values(vr)).unwrap_or_else(
|| {
ref_slice(value)
},
self.get(*value).map_or_else(
|| ref_slice(value),
|vr| self.values(vr),
)
}
@@ -257,7 +256,7 @@ enum UFEntry {
/// A singleton set is the same as a set with rank 0. It contains only the leader value.
impl UFEntry {
/// Decode a table entry.
fn decode(x: i32) -> UFEntry {
fn decode(x: i32) -> Self {
if x < 0 {
UFEntry::Link(Value::new((!x) as usize))
} else {

View File

@@ -70,7 +70,7 @@ impl StdError for CtonError {
}
impl From<verifier::Error> for CtonError {
fn from(e: verifier::Error) -> CtonError {
fn from(e: verifier::Error) -> Self {
CtonError::Verifier(e)
}
}

View File

@@ -50,8 +50,8 @@ pub struct Builder {
impl Builder {
/// Create a new builder with defaults and names from the given template.
pub fn new(tmpl: &'static detail::Template) -> Builder {
Builder {
pub fn new(tmpl: &'static detail::Template) -> Self {
Self {
template: tmpl,
bytes: tmpl.defaults.into(),
}

View File

@@ -102,8 +102,7 @@ impl<'a> FlagsVerifier<'a> {
if self.encinfo
.as_ref()
.and_then(|ei| ei.operand_constraints(self.func.encodings[inst]))
.map(|c| c.clobbers_flags)
.unwrap_or(false) && live_val.is_some()
.map_or(false, |c| c.clobbers_flags) && live_val.is_some()
{
return err!(inst, "encoding clobbers live CPU flags in {}", live);
}

View File

@@ -78,7 +78,7 @@ impl<'a> LivenessVerifier<'a> {
if encoding.is_legal() {
// A legal instruction is not allowed to define ghost values.
if lr.affinity.is_none() {
if lr.affinity.is_unassigned() {
return err!(
inst,
"{} is a ghost value defined by a real [{}] instruction",
@@ -86,7 +86,7 @@ impl<'a> LivenessVerifier<'a> {
self.isa.encoding_info().display(encoding)
);
}
} else if !lr.affinity.is_none() {
} else if !lr.affinity.is_unassigned() {
// A non-encoded instruction can only define ghost values.
return err!(
inst,
@@ -108,7 +108,7 @@ impl<'a> LivenessVerifier<'a> {
}
// A legal instruction is not allowed to depend on ghost values.
if encoding.is_legal() && lr.affinity.is_none() {
if encoding.is_legal() && lr.affinity.is_unassigned() {
return err!(
inst,
"{} is a ghost value used by a real [{}] instruction",

View File

@@ -244,9 +244,9 @@ impl<'a> Verifier<'a> {
let fixed_results = inst_data.opcode().constraints().fixed_results();
// var_results is 0 if we aren't a call instruction
let var_results = dfg.call_signature(inst)
.map(|sig| dfg.signatures[sig].returns.len())
.unwrap_or(0);
let var_results = dfg.call_signature(inst).map_or(0, |sig| {
dfg.signatures[sig].returns.len()
});
let total_results = fixed_results + var_results;
// All result values for multi-valued instructions are created

View File

@@ -22,7 +22,7 @@ pub fn write_function(w: &mut Write, func: &Function, isa: Option<&TargetIsa>) -
let mut any = write_preamble(w, func, regs)?;
for ebb in &func.layout {
if any {
writeln!(w, "")?;
writeln!(w)?;
}
write_ebb(w, func, isa, ebb)?;
any = true;
@@ -258,7 +258,7 @@ fn write_instruction(
}
write_operands(w, &func.dfg, isa, inst)?;
writeln!(w, "")
writeln!(w)
}
/// Write the operands of `inst` to `w` with a prepended space.

View File

@@ -30,9 +30,20 @@
//! `Vec`.
#![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, redundant_field_names))]
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,
))]
// Turns on no_std and alloc features if std is not available.
#![cfg_attr(not(feature = "std"), no_std)]
@@ -91,7 +102,7 @@ macro_rules! entity_impl {
impl $crate::__core::fmt::Display for $entity {
fn fmt(&self, f: &mut $crate::__core::fmt::Formatter) -> $crate::__core::fmt::Result {
write!(f, "{}{}", $display_prefix, self.0)
write!(f, concat!($display_prefix, "{}"), self.0)
}
}

View File

@@ -49,7 +49,7 @@ where
pub fn with_default(default: V) -> Self {
Self {
elems: Vec::new(),
default: default,
default,
unused: PhantomData,
}
}

View File

@@ -28,7 +28,7 @@ impl<T: ReservedValue> PackedOption<T> {
/// Returns `true` if the packed option is a `Some` value.
pub fn is_some(&self) -> bool {
!self.is_none()
self.0 != T::reserved_value()
}
/// Expand the packed option into a normal `Option`.
@@ -62,14 +62,14 @@ impl<T: ReservedValue> PackedOption<T> {
impl<T: ReservedValue> Default for PackedOption<T> {
/// Create a default packed option representing `None`.
fn default() -> PackedOption<T> {
fn default() -> Self {
PackedOption(T::reserved_value())
}
}
impl<T: ReservedValue> From<T> for PackedOption<T> {
/// Convert `t` into a packed `Some(x)`.
fn from(t: T) -> PackedOption<T> {
fn from(t: T) -> Self {
debug_assert!(
t != T::reserved_value(),
"Can't make a PackedOption from the reserved value."
@@ -80,7 +80,7 @@ impl<T: ReservedValue> From<T> for PackedOption<T> {
impl<T: ReservedValue> From<Option<T>> for PackedOption<T> {
/// Convert an option into its packed equivalent.
fn from(opt: Option<T>) -> PackedOption<T> {
fn from(opt: Option<T>) -> Self {
match opt {
None => Self::default(),
Some(t) => t.into(),

View File

@@ -270,7 +270,7 @@ impl<'a> RelocSink for FaerieRelocSink<'a> {
&self.namespace.get_data_decl(name).name
};
let addend_i32 = addend as i32;
debug_assert!(addend_i32 as i64 == addend);
debug_assert!(i64::from(addend_i32) == addend);
let raw_reloc = container::raw_relocation(reloc, self.format);
self.artifact
.link_with(

View File

@@ -3,6 +3,20 @@
//! Users of this module should not have to depend on faerie directly.
#![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", 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;

View File

@@ -3,10 +3,20 @@
//! This crate contains the main test driver as well as implementations of the
//! available filetest commands.
#![deny(missing_docs, trivial_numeric_casts, unused_extern_crates)]
#![warn(unused_import_braces, unstable_features)]
#![cfg_attr(feature="cargo-clippy", allow(
type_complexity,
// Rustfmt 0.9.0 is at odds with this lint:
block_in_if_condition_stmt))]
#![cfg_attr(feature="cargo-clippy", warn(
mut_mut,
nonminimal_bool,
option_map_unwrap_or,
option_map_unwrap_or_else,
unicode_not_nfc,
use_self,
))]
#[macro_use(dbg)]
extern crate cretonne_codegen;

View File

@@ -122,7 +122,7 @@ fn run_one_test<'a>(
) -> Result<()> {
let (test, flags, isa) = tuple;
let name = format!("{}({})", test.name(), func.name);
dbg!("Test: {} {}", name, isa.map(TargetIsa::name).unwrap_or("-"));
dbg!("Test: {} {}", name, isa.map_or("-", TargetIsa::name));
context.flags = flags;
context.isa = isa;

View File

@@ -125,7 +125,7 @@ fn filecheck_text(func: &Function, domtree: &DominatorTree) -> result::Result<St
for &ebb in domtree.cfg_postorder() {
write!(s, " {}", ebb)?;
}
writeln!(s, "")?;
writeln!(s)?;
// Compute and print out a pre-order of the dominator tree.
writeln!(s, "domtree_preorder {{")?;
@@ -140,7 +140,7 @@ fn filecheck_text(func: &Function, domtree: &DominatorTree) -> result::Result<St
write!(s, " {}", ch)?;
stack.push(ch);
}
writeln!(s, "")?;
writeln!(s)?;
// Reverse the children we just pushed so we'll pop them in order.
stack[i..].reverse();
}

View File

@@ -238,9 +238,9 @@ where
) -> FunctionBuilder<'a, Variable> {
debug_assert!(func_ctx.is_empty());
FunctionBuilder {
func: func,
func,
srcloc: Default::default(),
func_ctx: func_ctx,
func_ctx,
position: Position::default(),
}
}

View File

@@ -128,7 +128,18 @@
//! ```
#![deny(missing_docs, trivial_numeric_casts, unused_extern_crates)]
#![cfg_attr(feature = "cargo-clippy", allow(new_without_default, redundant_field_names))]
#![warn(unused_import_braces, unstable_features)]
#![cfg_attr(feature = "cargo-clippy", allow(new_without_default))]
#![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,
))]
extern crate cretonne_codegen;

View File

@@ -361,7 +361,7 @@ where
let block = self.blocks.push(BlockData::EbbHeader(EbbHeaderBlockData {
predecessors: Vec::new(),
sealed: false,
ebb: ebb,
ebb,
undef_variables: Vec::new(),
}));
self.ebb_headers[ebb] = block.into();

View File

@@ -1,6 +1,20 @@
//! Top-level lib.rs for `cretonne_module`.
#![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", 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;
#[macro_use]

View File

@@ -36,7 +36,7 @@ pub enum Linkage {
}
impl Linkage {
fn merge(a: Linkage, b: Linkage) -> Linkage {
fn merge(a: Self, b: Self) -> Self {
match a {
Linkage::Export => Linkage::Export,
Linkage::Preemptible => {

View File

@@ -2,6 +2,20 @@
//! Cretonne to generate code to run on the same machine.
#![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", 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;

View File

@@ -4,6 +4,20 @@
//! testing Cretonne, but is not essential for a JIT compiler.
#![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", 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;

View File

@@ -54,7 +54,7 @@ impl<'a> Display for TestCommand<'a> {
for opt in &self.options {
write!(f, " {}", opt)?;
}
writeln!(f, "")
writeln!(f)
}
}

View File

@@ -1,6 +1,20 @@
//! Top-level lib.rs for `cretonne_simplejit`.
#![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", 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;

View File

@@ -25,7 +25,7 @@ impl PtrLen {
let err = libc::posix_memalign(&mut ptr, page_size, alloc_size);
if err == 0 {
Ok(Self {
ptr: mem::transmute(ptr),
ptr: ptr as *mut u8,
len: alloc_size,
})
} else {

View File

@@ -1,7 +1,20 @@
//! Cretonne umbrella crate, providing a convenient one-line dependency.
#![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", warn(
float_arithmetic,
mut_mut,
nonminimal_bool,
option_map_unwrap_or,
option_map_unwrap_or_else,
print_stdout,
unicode_not_nfc,
use_self,
))]
pub extern crate cretonne_codegen;
pub extern crate cretonne_frontend;

View File

@@ -949,7 +949,7 @@ fn get_heap_addr(
heap: ir::Heap,
addr32: ir::Value,
offset: u32,
addr_ty: ir::Type,
addr_ty: Type,
builder: &mut FunctionBuilder<Variable>,
) -> (ir::Value, i32) {
use std::cmp::min;
@@ -985,7 +985,7 @@ fn get_heap_addr(
fn translate_load<FE: FuncEnvironment + ?Sized>(
offset: u32,
opcode: ir::Opcode,
result_ty: ir::Type,
result_ty: Type,
builder: &mut FunctionBuilder<Variable>,
state: &mut TranslationState,
environ: &mut FE,

View File

@@ -226,7 +226,7 @@ impl<'dummy_environment> FuncEnvironment for DummyFuncEnvironment<'dummy_environ
args.push(vmctx, &mut pos.func.dfg.value_lists);
pos.ins()
.CallIndirect(ir::Opcode::CallIndirect, ir::types::VOID, sig_ref, args)
.CallIndirect(ir::Opcode::CallIndirect, VOID, sig_ref, args)
.0
}
@@ -248,9 +248,7 @@ impl<'dummy_environment> FuncEnvironment for DummyFuncEnvironment<'dummy_environ
args.extend(call_args.iter().cloned(), &mut pos.func.dfg.value_lists);
args.push(vmctx, &mut pos.func.dfg.value_lists);
pos.ins()
.Call(ir::Opcode::Call, ir::types::VOID, callee, args)
.0
pos.ins().Call(ir::Opcode::Call, VOID, callee, args).0
}
fn translate_grow_memory(

View File

@@ -10,8 +10,20 @@
//! The main function of this module is [`translate_module`](fn.translate_module.html).
#![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, redundant_field_names))]
#![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,
))]
#[macro_use(dbg)]
extern crate cretonne_codegen;

View File

@@ -241,8 +241,8 @@ pub fn parse_global_section(
}
let global = Global {
ty: type_to_type(&content_type).unwrap(),
mutability: mutability,
initializer: initializer,
mutability,
initializer,
};
environ.declare_global(global);
match *parser.read() {