Add clippy suggestions (#6203)

* add clippy suggestions

* revert &/ref change

* Update cranelift/isle/isle/src/parser.rs

Co-authored-by: Jamey Sharp <jamey@minilop.net>

---------

Co-authored-by: Jamey Sharp <jamey@minilop.net>
This commit is contained in:
kevaundray
2023-04-17 16:53:34 +01:00
committed by GitHub
parent 91de5de049
commit 85118c8c26
22 changed files with 140 additions and 172 deletions

View File

@@ -228,8 +228,8 @@ impl InstructionBuilder {
}
fn build(self) -> Instruction {
let operands_in = self.operands_in.unwrap_or_else(Vec::new);
let operands_out = self.operands_out.unwrap_or_else(Vec::new);
let operands_in = self.operands_in.unwrap_or_default();
let operands_out = self.operands_out.unwrap_or_default();
let mut value_opnums = Vec::new();
let mut imm_opnums = Vec::new();
@@ -375,7 +375,7 @@ fn verify_polymorphic(
if (free_typevar.is_some() && tv == &free_typevar.unwrap())
|| tv.singleton_type().is_some()
{
match is_ctrl_typevar_candidate(tv, &operands_in, &operands_out) {
match is_ctrl_typevar_candidate(tv, operands_in, operands_out) {
Ok(_other_typevars) => {
return Some(PolymorphicInfo {
use_typevar_operand: true,
@@ -410,7 +410,7 @@ fn verify_polymorphic(
// At this point, if the next unwrap() fails, it means the output type couldn't be used as a
// controlling type variable either; panicking is the right behavior.
is_ctrl_typevar_candidate(tv, &operands_in, &operands_out).unwrap();
is_ctrl_typevar_candidate(tv, operands_in, operands_out).unwrap();
Some(PolymorphicInfo {
use_typevar_operand: false,

View File

@@ -50,10 +50,7 @@ impl Operand {
}
pub fn is_value(&self) -> bool {
match self.kind.fields {
OperandKindFields::TypeVar(_) => true,
_ => false,
}
matches!(self.kind.fields, OperandKindFields::TypeVar(_))
}
pub fn type_var(&self) -> Option<&TypeVar> {
@@ -64,28 +61,25 @@ impl Operand {
}
pub fn is_varargs(&self) -> bool {
match self.kind.fields {
OperandKindFields::VariableArgs => true,
_ => false,
}
matches!(self.kind.fields, OperandKindFields::VariableArgs)
}
/// Returns true if the operand has an immediate kind or is an EntityRef.
pub fn is_immediate_or_entityref(&self) -> bool {
match self.kind.fields {
matches!(
self.kind.fields,
OperandKindFields::ImmEnum(_)
| OperandKindFields::ImmValue
| OperandKindFields::EntityRef => true,
_ => false,
}
| OperandKindFields::ImmValue
| OperandKindFields::EntityRef
)
}
/// Returns true if the operand has an immediate kind.
pub fn is_immediate(&self) -> bool {
match self.kind.fields {
OperandKindFields::ImmEnum(_) | OperandKindFields::ImmValue => true,
_ => false,
}
matches!(
self.kind.fields,
OperandKindFields::ImmEnum(_) | OperandKindFields::ImmValue
)
}
}
@@ -158,18 +152,18 @@ impl OperandKind {
}
}
impl Into<OperandKind> for &TypeVar {
fn into(self) -> OperandKind {
impl From<&TypeVar> for OperandKind {
fn from(type_var: &TypeVar) -> Self {
OperandKind {
rust_field_name: "value",
rust_type: "ir::Value",
fields: OperandKindFields::TypeVar(self.into()),
fields: OperandKindFields::TypeVar(type_var.into()),
doc: None,
}
}
}
impl Into<OperandKind> for &OperandKind {
fn into(self) -> OperandKind {
self.clone()
impl From<&OperandKind> for OperandKind {
fn from(kind: &OperandKind) -> Self {
kind.clone()
}
}

View File

@@ -75,14 +75,14 @@ pub(crate) enum PresetType {
OtherPreset(PresetIndex),
}
impl Into<PresetType> for BoolSettingIndex {
fn into(self) -> PresetType {
PresetType::BoolSetting(self)
impl From<BoolSettingIndex> for PresetType {
fn from(bool_setting_index: BoolSettingIndex) -> Self {
PresetType::BoolSetting(bool_setting_index)
}
}
impl Into<PresetType> for PresetIndex {
fn into(self) -> PresetType {
PresetType::OtherPreset(self)
impl From<PresetIndex> for PresetType {
fn from(value: PresetIndex) -> Self {
PresetType::OtherPreset(value)
}
}
@@ -134,13 +134,7 @@ impl SettingGroup {
fn num_bool_settings(&self) -> u8 {
self.settings
.iter()
.filter(|s| {
if let SpecificSetting::Bool(_) = s.specific {
true
} else {
false
}
})
.filter(|s| matches!(s.specific, SpecificSetting::Bool(_)))
.count() as u8
}
@@ -184,14 +178,15 @@ pub(crate) enum PredicateNode {
And(Box<PredicateNode>, Box<PredicateNode>),
}
impl Into<PredicateNode> for BoolSettingIndex {
fn into(self) -> PredicateNode {
PredicateNode::OwnedBool(self)
impl From<BoolSettingIndex> for PredicateNode {
fn from(bool_setting_index: BoolSettingIndex) -> Self {
PredicateNode::OwnedBool(bool_setting_index)
}
}
impl<'a> Into<PredicateNode> for (BoolSettingIndex, &'a SettingGroup) {
fn into(self) -> PredicateNode {
let (index, group) = (self.0, self.1);
impl<'a> From<(BoolSettingIndex, &'a SettingGroup)> for PredicateNode {
fn from(val: (BoolSettingIndex, &'a SettingGroup)) -> Self {
let (index, group) = (val.0, val.1);
let setting = &group.settings[index.0];
PredicateNode::SharedBool(group.name, setting.name)
}

View File

@@ -491,10 +491,6 @@ impl ReferenceTypeIterator {
impl Iterator for ReferenceTypeIterator {
type Item = ReferenceType;
fn next(&mut self) -> Option<Self::Item> {
if let Some(r) = self.reference_iter.next() {
Some(ReferenceType::from(r))
} else {
None
}
self.reference_iter.next().map(ReferenceType::from)
}
}

View File

@@ -279,14 +279,14 @@ impl TypeVar {
}
}
impl Into<TypeVar> for &TypeVar {
fn into(self) -> TypeVar {
self.clone()
impl From<&TypeVar> for TypeVar {
fn from(type_var: &TypeVar) -> Self {
type_var.clone()
}
}
impl Into<TypeVar> for ValueType {
fn into(self) -> TypeVar {
TypeVar::new_singleton(self)
impl From<ValueType> for TypeVar {
fn from(value_type: ValueType) -> Self {
TypeVar::new_singleton(value_type)
}
}
@@ -507,7 +507,7 @@ impl TypeSet {
self.dynamic_lanes
.iter()
.filter(|&&x| x < MAX_LANES)
.map(|&x| x),
.copied(),
);
copy.dynamic_lanes = NumSet::new();
copy
@@ -660,13 +660,7 @@ pub(crate) enum Interval {
impl Interval {
fn to_range(&self, full_range: Range, default: Option<RangeBound>) -> Option<Range> {
match self {
Interval::None => {
if let Some(default_val) = default {
Some(default_val..default_val)
} else {
None
}
}
Interval::None => default.map(|default_val| default_val..default_val),
Interval::All => Some(full_range),
@@ -683,9 +677,9 @@ impl Interval {
}
}
impl Into<Interval> for Range {
fn into(self) -> Interval {
Interval::Range(self)
impl From<Range> for Interval {
fn from(range: Range) -> Self {
Interval::Range(range)
}
}