Skip to content

Commit 85118c8

Browse files
Add clippy suggestions (#6203)
* add clippy suggestions * revert &/ref change * Update cranelift/isle/isle/src/parser.rs Co-authored-by: Jamey Sharp <[email protected]> --------- Co-authored-by: Jamey Sharp <[email protected]>
1 parent 91de5de commit 85118c8

File tree

22 files changed

+140
-172
lines changed

22 files changed

+140
-172
lines changed

cranelift/codegen/meta/src/cdsl/instructions.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ impl InstructionBuilder {
228228
}
229229

230230
fn build(self) -> Instruction {
231-
let operands_in = self.operands_in.unwrap_or_else(Vec::new);
232-
let operands_out = self.operands_out.unwrap_or_else(Vec::new);
231+
let operands_in = self.operands_in.unwrap_or_default();
232+
let operands_out = self.operands_out.unwrap_or_default();
233233

234234
let mut value_opnums = Vec::new();
235235
let mut imm_opnums = Vec::new();
@@ -375,7 +375,7 @@ fn verify_polymorphic(
375375
if (free_typevar.is_some() && tv == &free_typevar.unwrap())
376376
|| tv.singleton_type().is_some()
377377
{
378-
match is_ctrl_typevar_candidate(tv, &operands_in, &operands_out) {
378+
match is_ctrl_typevar_candidate(tv, operands_in, operands_out) {
379379
Ok(_other_typevars) => {
380380
return Some(PolymorphicInfo {
381381
use_typevar_operand: true,
@@ -410,7 +410,7 @@ fn verify_polymorphic(
410410

411411
// At this point, if the next unwrap() fails, it means the output type couldn't be used as a
412412
// controlling type variable either; panicking is the right behavior.
413-
is_ctrl_typevar_candidate(tv, &operands_in, &operands_out).unwrap();
413+
is_ctrl_typevar_candidate(tv, operands_in, operands_out).unwrap();
414414

415415
Some(PolymorphicInfo {
416416
use_typevar_operand: false,

cranelift/codegen/meta/src/cdsl/operands.rs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ impl Operand {
5050
}
5151

5252
pub fn is_value(&self) -> bool {
53-
match self.kind.fields {
54-
OperandKindFields::TypeVar(_) => true,
55-
_ => false,
56-
}
53+
matches!(self.kind.fields, OperandKindFields::TypeVar(_))
5754
}
5855

5956
pub fn type_var(&self) -> Option<&TypeVar> {
@@ -64,28 +61,25 @@ impl Operand {
6461
}
6562

6663
pub fn is_varargs(&self) -> bool {
67-
match self.kind.fields {
68-
OperandKindFields::VariableArgs => true,
69-
_ => false,
70-
}
64+
matches!(self.kind.fields, OperandKindFields::VariableArgs)
7165
}
7266

7367
/// Returns true if the operand has an immediate kind or is an EntityRef.
7468
pub fn is_immediate_or_entityref(&self) -> bool {
75-
match self.kind.fields {
69+
matches!(
70+
self.kind.fields,
7671
OperandKindFields::ImmEnum(_)
77-
| OperandKindFields::ImmValue
78-
| OperandKindFields::EntityRef => true,
79-
_ => false,
80-
}
72+
| OperandKindFields::ImmValue
73+
| OperandKindFields::EntityRef
74+
)
8175
}
8276

8377
/// Returns true if the operand has an immediate kind.
8478
pub fn is_immediate(&self) -> bool {
85-
match self.kind.fields {
86-
OperandKindFields::ImmEnum(_) | OperandKindFields::ImmValue => true,
87-
_ => false,
88-
}
79+
matches!(
80+
self.kind.fields,
81+
OperandKindFields::ImmEnum(_) | OperandKindFields::ImmValue
82+
)
8983
}
9084
}
9185

@@ -158,18 +152,18 @@ impl OperandKind {
158152
}
159153
}
160154

161-
impl Into<OperandKind> for &TypeVar {
162-
fn into(self) -> OperandKind {
155+
impl From<&TypeVar> for OperandKind {
156+
fn from(type_var: &TypeVar) -> Self {
163157
OperandKind {
164158
rust_field_name: "value",
165159
rust_type: "ir::Value",
166-
fields: OperandKindFields::TypeVar(self.into()),
160+
fields: OperandKindFields::TypeVar(type_var.into()),
167161
doc: None,
168162
}
169163
}
170164
}
171-
impl Into<OperandKind> for &OperandKind {
172-
fn into(self) -> OperandKind {
173-
self.clone()
165+
impl From<&OperandKind> for OperandKind {
166+
fn from(kind: &OperandKind) -> Self {
167+
kind.clone()
174168
}
175169
}

cranelift/codegen/meta/src/cdsl/settings.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ pub(crate) enum PresetType {
7575
OtherPreset(PresetIndex),
7676
}
7777

78-
impl Into<PresetType> for BoolSettingIndex {
79-
fn into(self) -> PresetType {
80-
PresetType::BoolSetting(self)
78+
impl From<BoolSettingIndex> for PresetType {
79+
fn from(bool_setting_index: BoolSettingIndex) -> Self {
80+
PresetType::BoolSetting(bool_setting_index)
8181
}
8282
}
83-
impl Into<PresetType> for PresetIndex {
84-
fn into(self) -> PresetType {
85-
PresetType::OtherPreset(self)
83+
impl From<PresetIndex> for PresetType {
84+
fn from(value: PresetIndex) -> Self {
85+
PresetType::OtherPreset(value)
8686
}
8787
}
8888

@@ -134,13 +134,7 @@ impl SettingGroup {
134134
fn num_bool_settings(&self) -> u8 {
135135
self.settings
136136
.iter()
137-
.filter(|s| {
138-
if let SpecificSetting::Bool(_) = s.specific {
139-
true
140-
} else {
141-
false
142-
}
143-
})
137+
.filter(|s| matches!(s.specific, SpecificSetting::Bool(_)))
144138
.count() as u8
145139
}
146140

@@ -184,14 +178,15 @@ pub(crate) enum PredicateNode {
184178
And(Box<PredicateNode>, Box<PredicateNode>),
185179
}
186180

187-
impl Into<PredicateNode> for BoolSettingIndex {
188-
fn into(self) -> PredicateNode {
189-
PredicateNode::OwnedBool(self)
181+
impl From<BoolSettingIndex> for PredicateNode {
182+
fn from(bool_setting_index: BoolSettingIndex) -> Self {
183+
PredicateNode::OwnedBool(bool_setting_index)
190184
}
191185
}
192-
impl<'a> Into<PredicateNode> for (BoolSettingIndex, &'a SettingGroup) {
193-
fn into(self) -> PredicateNode {
194-
let (index, group) = (self.0, self.1);
186+
187+
impl<'a> From<(BoolSettingIndex, &'a SettingGroup)> for PredicateNode {
188+
fn from(val: (BoolSettingIndex, &'a SettingGroup)) -> Self {
189+
let (index, group) = (val.0, val.1);
195190
let setting = &group.settings[index.0];
196191
PredicateNode::SharedBool(group.name, setting.name)
197192
}

cranelift/codegen/meta/src/cdsl/types.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -491,10 +491,6 @@ impl ReferenceTypeIterator {
491491
impl Iterator for ReferenceTypeIterator {
492492
type Item = ReferenceType;
493493
fn next(&mut self) -> Option<Self::Item> {
494-
if let Some(r) = self.reference_iter.next() {
495-
Some(ReferenceType::from(r))
496-
} else {
497-
None
498-
}
494+
self.reference_iter.next().map(ReferenceType::from)
499495
}
500496
}

cranelift/codegen/meta/src/cdsl/typevar.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -279,14 +279,14 @@ impl TypeVar {
279279
}
280280
}
281281

282-
impl Into<TypeVar> for &TypeVar {
283-
fn into(self) -> TypeVar {
284-
self.clone()
282+
impl From<&TypeVar> for TypeVar {
283+
fn from(type_var: &TypeVar) -> Self {
284+
type_var.clone()
285285
}
286286
}
287-
impl Into<TypeVar> for ValueType {
288-
fn into(self) -> TypeVar {
289-
TypeVar::new_singleton(self)
287+
impl From<ValueType> for TypeVar {
288+
fn from(value_type: ValueType) -> Self {
289+
TypeVar::new_singleton(value_type)
290290
}
291291
}
292292

@@ -507,7 +507,7 @@ impl TypeSet {
507507
self.dynamic_lanes
508508
.iter()
509509
.filter(|&&x| x < MAX_LANES)
510-
.map(|&x| x),
510+
.copied(),
511511
);
512512
copy.dynamic_lanes = NumSet::new();
513513
copy
@@ -660,13 +660,7 @@ pub(crate) enum Interval {
660660
impl Interval {
661661
fn to_range(&self, full_range: Range, default: Option<RangeBound>) -> Option<Range> {
662662
match self {
663-
Interval::None => {
664-
if let Some(default_val) = default {
665-
Some(default_val..default_val)
666-
} else {
667-
None
668-
}
669-
}
663+
Interval::None => default.map(|default_val| default_val..default_val),
670664

671665
Interval::All => Some(full_range),
672666

@@ -683,9 +677,9 @@ impl Interval {
683677
}
684678
}
685679

686-
impl Into<Interval> for Range {
687-
fn into(self) -> Interval {
688-
Interval::Range(self)
680+
impl From<Range> for Interval {
681+
fn from(range: Range) -> Self {
682+
Interval::Range(range)
689683
}
690684
}
691685

cranelift/codegen/meta/src/constant_hash.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub fn generate_table<'cont, T, I: iter::Iterator<Item = &'cont T>, H: Fn(&T) ->
3030
let mut table = vec![None; size];
3131

3232
for i in items {
33-
let mut h = hash_function(&i) % size;
33+
let mut h = hash_function(i) % size;
3434
let mut s = 0;
3535
while table[h].is_some() {
3636
s += 1;

cranelift/codegen/meta/src/gen_inst.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ fn get_constraint<'entries, 'table>(
700700
if let Some(free_typevar) = type_var.free_typevar() {
701701
if ctrl_typevar.is_some() && free_typevar != *ctrl_typevar.unwrap() {
702702
assert!(type_var.base.is_none());
703-
return format!("Free({})", type_sets.add(&type_var.get_raw_typeset()));
703+
return format!("Free({})", type_sets.add(type_var.get_raw_typeset()));
704704
}
705705
}
706706

@@ -809,7 +809,7 @@ fn gen_type_constraints(all_inst: &AllInstructions, fmt: &mut Formatter) {
809809
fmt.indent(|fmt| {
810810
for inst in all_inst.iter() {
811811
let (ctrl_typevar, ctrl_typeset) = if let Some(poly) = &inst.polymorphic_info {
812-
let index = type_sets.add(&*poly.ctrl_typevar.get_raw_typeset());
812+
let index = type_sets.add(poly.ctrl_typevar.get_raw_typeset());
813813
(Some(&poly.ctrl_typevar), index)
814814
} else {
815815
(None, TYPESET_LIMIT)
@@ -857,7 +857,7 @@ fn gen_type_constraints(all_inst: &AllInstructions, fmt: &mut Formatter) {
857857
.collect::<Vec<_>>()
858858
.join(", ")));
859859
if let Some(poly) = &inst.polymorphic_info {
860-
fmt.comment(format!("Polymorphic over {}", typeset_to_string(&poly.ctrl_typevar.get_raw_typeset())));
860+
fmt.comment(format!("Polymorphic over {}", typeset_to_string(poly.ctrl_typevar.get_raw_typeset())));
861861
}
862862

863863
// Compute the bit field encoding, c.f. instructions.rs.
@@ -1730,7 +1730,7 @@ fn gen_builder(
17301730
fmt.line("pub trait InstBuilder<'f>: InstBuilderBase<'f> {");
17311731
fmt.indent(|fmt| {
17321732
for inst in instructions.iter() {
1733-
gen_inst_builder(inst, &*inst.format, fmt);
1733+
gen_inst_builder(inst, &inst.format, fmt);
17341734
fmt.empty_line();
17351735
}
17361736
for (i, format) in formats.iter().enumerate() {

cranelift/codegen/meta/src/gen_settings.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,10 @@ fn gen_getters(group: &SettingGroup, fmt: &mut Formatter) {
267267
}
268268

269269
for setting in &group.settings {
270-
gen_getter(&setting, fmt);
270+
gen_getter(setting, fmt);
271271
}
272272
for predicate in &group.predicates {
273-
gen_pred_getter(&predicate, &group, fmt);
273+
gen_pred_getter(predicate, group, fmt);
274274
}
275275
});
276276
fmtln!(fmt, "}");
@@ -364,8 +364,8 @@ fn gen_descriptors(group: &SettingGroup, fmt: &mut Formatter) {
364364

365365
// Generate hash table.
366366
let mut hash_entries: Vec<SettingOrPreset> = Vec::new();
367-
hash_entries.extend(group.settings.iter().map(|x| SettingOrPreset::Setting(x)));
368-
hash_entries.extend(group.presets.iter().map(|x| SettingOrPreset::Preset(x)));
367+
hash_entries.extend(group.settings.iter().map(SettingOrPreset::Setting));
368+
hash_entries.extend(group.presets.iter().map(SettingOrPreset::Preset));
369369

370370
let hash_table = generate_table(hash_entries.iter(), hash_entries.len(), |entry| {
371371
simple_hash(entry.name())
@@ -399,9 +399,9 @@ fn gen_descriptors(group: &SettingGroup, fmt: &mut Formatter) {
399399
fmt.comment(format!(
400400
"{}: {}",
401401
preset.name,
402-
preset.setting_names(&group).collect::<Vec<_>>().join(", ")
402+
preset.setting_names(group).collect::<Vec<_>>().join(", ")
403403
));
404-
for (mask, value) in preset.layout(&group) {
404+
for (mask, value) in preset.layout(group) {
405405
fmtln!(fmt, "(0b{:08b}, 0b{:08b}),", mask, value);
406406
}
407407
}
@@ -502,7 +502,7 @@ pub(crate) fn generate(
502502
out_dir: &str,
503503
) -> Result<(), error::Error> {
504504
let mut fmt = Formatter::new();
505-
gen_group(&settings, parent_group, &mut fmt);
505+
gen_group(settings, parent_group, &mut fmt);
506506
fmt.update_file(filename, out_dir)?;
507507
Ok(())
508508
}

cranelift/codegen/meta/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ pub fn generate(isas: &[isa::Isa], out_dir: &str, isle_dir: &str) -> Result<(),
3131
&shared_defs.settings,
3232
gen_settings::ParentGroup::None,
3333
"settings.rs",
34-
&out_dir,
34+
out_dir,
3535
)?;
36-
gen_types::generate("types.rs", &out_dir)?;
36+
gen_types::generate("types.rs", out_dir)?;
3737

3838
// - per ISA definitions.
3939
let target_isas = isa::define(isas, &mut shared_defs);
@@ -49,7 +49,7 @@ pub fn generate(isas: &[isa::Isa], out_dir: &str, isle_dir: &str) -> Result<(),
4949
"inst_builder.rs",
5050
"clif_opt.isle",
5151
"clif_lower.isle",
52-
&out_dir,
52+
out_dir,
5353
isle_dir,
5454
)?;
5555

@@ -58,7 +58,7 @@ pub fn generate(isas: &[isa::Isa], out_dir: &str, isle_dir: &str) -> Result<(),
5858
&isa.settings,
5959
gen_settings::ParentGroup::Shared,
6060
&format!("settings-{}.rs", isa.name),
61-
&out_dir,
61+
out_dir,
6262
)?;
6363
}
6464

cranelift/codegen/meta/src/shared/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl Definitions {
5858
// Check name.
5959
if let Some(existing_format) = format_names.get(&inst.format.name) {
6060
assert!(
61-
Rc::ptr_eq(&existing_format, &inst.format),
61+
Rc::ptr_eq(existing_format, &inst.format),
6262
"formats must uniquely named; there's a\
6363
conflict on the name '{}', please make sure it is used only once.",
6464
existing_format.name
@@ -80,7 +80,7 @@ impl Definitions {
8080
}
8181
}
8282

83-
let mut result = Vec::from_iter(format_structures.into_iter().map(|(_, v)| v));
83+
let mut result = Vec::from_iter(format_structures.into_values());
8484
result.sort_by_key(|format| format.name);
8585
result
8686
}

cranelift/codegen/meta/src/srcgen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ fn _indent(s: &str) -> Option<usize> {
189189
fn parse_multiline(s: &str) -> Vec<String> {
190190
// Convert tabs into spaces.
191191
let expanded_tab = format!("{:-1$}", " ", SHIFTWIDTH);
192-
let lines: Vec<String> = s.lines().map(|l| l.replace("\t", &expanded_tab)).collect();
192+
let lines: Vec<String> = s.lines().map(|l| l.replace('\t', &expanded_tab)).collect();
193193

194194
// Determine minimum indentation, ignoring the first line and empty lines.
195195
let indent = lines

cranelift/control/src/zero_sized.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub struct ControlPlane {
1313
/// disabled. It doesn't consume any bytes and always returns a default
1414
/// control plane.
1515
impl arbitrary::Arbitrary<'_> for ControlPlane {
16-
fn arbitrary<'a>(_u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
16+
fn arbitrary(_u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result<Self> {
1717
Ok(Self::default())
1818
}
1919
}

0 commit comments

Comments
 (0)