Skip to content

Commit 9d3c0e9

Browse files
cgswordsbmwill
andauthored
Enable clippy for external-crates/move in CI, with clippy changes in the code. (#13529)
## Description Enables clippy for `external-crates/move`, including fixes that clippy flagged (with a few ignores). Hopefully this will avoid issues in the codebase in the future that clippy will flag automatically. **Most of these changes were made automatically with `cargo clippy --fix` so special care should be taken in reviewing this diff.** ## Test Plan CI should work as expected, and now report signals for `move-clippy`, as I've called it. (I'm happy to bikeshed the name.) --- If your changes are not user-facing and not a breaking change, you can skip the following section. Otherwise, please indicate what changed, and then add to the Release Notes section as highlighted during the release process. ### Type of Change (Check all that apply) - [ ] protocol change - [ ] user-visible impact - [ ] breaking change for a client SDKs - [ ] breaking change for FNs (FN binary must upgrade) - [ ] breaking change for validators or node operators (must upgrade binaries) - [ ] breaking change for on-chain data layout - [ ] necessitate either a data wipe or data migration ### Release notes --------- Co-authored-by: Brandon Williams <[email protected]>
1 parent 5440804 commit 9d3c0e9

File tree

44 files changed

+125
-134
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+125
-134
lines changed

move-binary-format/src/file_format.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,10 @@ pub struct FieldDefinition {
416416
#[cfg_attr(any(test, feature = "fuzzing"), proptest(no_params))]
417417
#[cfg_attr(feature = "fuzzing", derive(arbitrary::Arbitrary))]
418418
#[repr(u8)]
419+
#[derive(Default)]
419420
pub enum Visibility {
420421
/// Accessible within its defining module only.
422+
#[default]
421423
Private = 0x0,
422424
/// Accessible by any module or script outside of its declaring module.
423425
Public = 0x1,
@@ -432,12 +434,6 @@ impl Visibility {
432434
pub const DEPRECATED_SCRIPT: u8 = 0x2;
433435
}
434436

435-
impl Default for Visibility {
436-
fn default() -> Self {
437-
Visibility::Private
438-
}
439-
}
440-
441437
impl std::convert::TryFrom<u8> for Visibility {
442438
type Error = ();
443439

move-binary-format/src/views.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ impl<'a, T: ModuleAccess> LocalsSignatureView<'a, T> {
441441
let parameters = self.parameters();
442442
SignatureTokenView::new(
443443
self.function_def_view.module,
444-
if (index as usize) < parameters.len() {
444+
if index < parameters.len() {
445445
&parameters[index]
446446
} else {
447447
&self.additional_locals()[index - parameters.len()]

move-bytecode-verifier/src/struct_defs.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl<'a> StructDefGraphBuilder<'a> {
104104
token: &SignatureToken,
105105
) -> PartialVMResult<()> {
106106
use SignatureToken as T;
107-
Ok(match token {
107+
match token {
108108
T::Bool
109109
| T::U8
110110
| T::U16
@@ -141,6 +141,7 @@ impl<'a> StructDefGraphBuilder<'a> {
141141
self.add_signature_token(neighbors, cur_idx, t)?
142142
}
143143
}
144-
})
144+
};
145+
Ok(())
145146
}
146147
}

move-command-line-common/src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub enum ParsedType {
4747
}
4848

4949
impl Display for TypeToken {
50-
fn fmt<'f>(&self, formatter: &mut fmt::Formatter<'f>) -> Result<(), fmt::Error> {
50+
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
5151
let s = match *self {
5252
TypeToken::Whitespace => "[whitespace]",
5353
TypeToken::Ident => "[identifier]",

move-command-line-common/src/values.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl ParsableValue for () {
117117
}
118118

119119
impl Display for ValueToken {
120-
fn fmt<'f>(&self, formatter: &mut fmt::Formatter<'f>) -> Result<(), fmt::Error> {
120+
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
121121
let s = match self {
122122
ValueToken::Number => "[num]",
123123
ValueToken::NumberTyped => "[num typed]",

move-compiler/src/cfgir/translate.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ impl<'env> Context<'env> {
9090
assert!(self.blocks.insert(lbl, basic_block).is_none());
9191
let block_info = match self.loop_bounds.get(&lbl) {
9292
None => BlockInfo::Other,
93-
Some(info) => BlockInfo::LoopHead(info.clone()),
93+
Some(info) => BlockInfo::LoopHead(*info),
9494
};
9595
self.block_info.push((lbl, block_info));
9696
}
9797

9898
// Returns the blocks inserted in insertion ordering
9999
pub fn finish_blocks(&mut self) -> (Label, BasicBlocks, Vec<(Label, BlockInfo)>) {
100100
self.next_label = None;
101-
let start = mem::replace(&mut self.start, None);
101+
let start = self.start.take();
102102
let blocks = mem::take(&mut self.blocks);
103103
let block_ordering = mem::take(&mut self.block_ordering);
104104
let block_info = mem::take(&mut self.block_info);
@@ -765,13 +765,13 @@ fn visit_function(
765765
struct_declared_abilities: &context.struct_declared_abilities,
766766
signature,
767767
acquires,
768-
locals: &locals,
768+
locals,
769769
infinite_loop_starts: &infinite_loop_starts,
770770
};
771771
let mut ds = Diagnostics::new();
772772
for visitor in &context.env.visitors().abs_int {
773773
let mut v = visitor.borrow_mut();
774-
ds.extend(v.verify(&context.env, prog, &function_context, &cfg));
774+
ds.extend(v.verify(context.env, prog, &function_context, &cfg));
775775
}
776776
context.env.add_diags(ds);
777777
context.env.pop_warning_filter_scope();

move-compiler/src/cfgir/visitor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl<V: SimpleDomain> AbstractDomain for V {
110110
);
111111
let mut result = JoinResult::Unchanged;
112112
for (local, other_state) in other_locals {
113-
match (self.locals().get(&local).unwrap(), other_state) {
113+
match (self.locals().get(local).unwrap(), other_state) {
114114
// both available, join the value
115115
(L::Available(loc, v1), L::Available(_, v2)) => {
116116
let loc = *loc;
@@ -390,7 +390,7 @@ pub trait SimpleAbsInt: Sized {
390390
E::ModuleCall(mcall) => {
391391
let evalues = self.exp(context, state, &mcall.arguments);
392392
if let Some(vs) =
393-
self.call_custom(context, state, eloc, &parent_e.ty, &mcall, evalues)
393+
self.call_custom(context, state, eloc, &parent_e.ty, mcall, evalues)
394394
{
395395
return vs;
396396
}

move-compiler/src/diagnostics/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ impl WarningFilters {
391391
pub fn union(&mut self, other: &Self) {
392392
for (prefix, filters) in &other.0 {
393393
self.0
394-
.entry(prefix.clone())
394+
.entry(*prefix)
395395
.or_insert_with(UnprefixedWarningFilters::new)
396396
.union(filters);
397397
}
@@ -468,7 +468,7 @@ impl UnprefixedWarningFilters {
468468
codes.extend(
469469
other_codes
470470
.iter()
471-
.filter(|((category, _), _)| !categories.contains_key(&category)),
471+
.filter(|((category, _), _)| !categories.contains_key(category)),
472472
);
473473
}
474474
}
@@ -489,7 +489,7 @@ impl UnprefixedWarningFilters {
489489
categories: BTreeMap::new(),
490490
codes: BTreeMap::new(),
491491
};
492-
return self.add(filter_category, filter_code, filter_name);
492+
self.add(filter_category, filter_code, filter_name)
493493
}
494494
Self::Specified { categories, .. } if categories.contains_key(&filter_category) => (),
495495
Self::Specified { categories, codes } => {
@@ -509,16 +509,16 @@ impl UnprefixedWarningFilters {
509509
let unused_fn_tparam_info = UnusedItem::FunTypeParam.into_info();
510510
let filtered_codes = BTreeMap::from([
511511
(
512-
(unused_fun_info.category() as u8, unused_fun_info.code()),
512+
(unused_fun_info.category(), unused_fun_info.code()),
513513
Some(FILTER_UNUSED_FUNCTION),
514514
),
515515
(
516-
(unused_field_info.category() as u8, unused_field_info.code()),
516+
(unused_field_info.category(), unused_field_info.code()),
517517
Some(FILTER_UNUSED_STRUCT_FIELD),
518518
),
519519
(
520520
(
521-
unused_fn_tparam_info.category() as u8,
521+
unused_fn_tparam_info.category(),
522522
unused_fn_tparam_info.code(),
523523
),
524524
Some(FILTER_UNUSED_TYPE_PARAMETER),

move-compiler/src/editions/mod.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ pub struct Edition {
2828
#[derive(PartialEq, Eq, Clone, Copy, Debug, PartialOrd, Ord)]
2929
pub enum FeatureGate {}
3030

31-
#[derive(PartialEq, Eq, Clone, Copy, Debug, PartialOrd, Ord)]
31+
#[derive(PartialEq, Eq, Clone, Copy, Debug, PartialOrd, Ord, Default)]
3232
pub enum Flavor {
33+
#[default]
3334
GlobalStorage,
3435
Sui,
3536
}
@@ -74,19 +75,19 @@ impl Edition {
7475

7576
// Intended only for implementing the lazy static (supported feature map) above
7677
fn prev(&self) -> Option<Self> {
77-
match self {
78-
&Self::LEGACY => None,
79-
&Self::E2024_ALPHA => Some(Self::LEGACY),
78+
match *self {
79+
Self::LEGACY => None,
80+
Self::E2024_ALPHA => Some(Self::LEGACY),
8081
_ => self.unknown_edition_panic(),
8182
}
8283
}
8384

8485
// Inefficient and should be called only to implement the lazy static
8586
// (supported feature map) above
8687
fn features(&self) -> BTreeSet<FeatureGate> {
87-
match self {
88-
&Self::LEGACY => BTreeSet::new(),
89-
&Self::E2024_ALPHA => self.prev().unwrap().features(),
88+
match *self {
89+
Self::LEGACY => BTreeSet::new(),
90+
Self::E2024_ALPHA => self.prev().unwrap().features(),
9091
_ => self.unknown_edition_panic(),
9192
}
9293
}
@@ -232,9 +233,3 @@ impl Default for Edition {
232233
Edition::LEGACY
233234
}
234235
}
235-
236-
impl Default for Flavor {
237-
fn default() -> Self {
238-
Flavor::GlobalStorage
239-
}
240-
}

move-compiler/src/expansion/translate.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl<'env, 'map> Context<'env, 'map> {
5252
) -> Self {
5353
let mut all_filter_alls = WarningFilters::new();
5454
for allow in compilation_env.filter_attributes() {
55-
for f in compilation_env.filter_from_str(FILTER_ALL, allow.clone()) {
55+
for f in compilation_env.filter_from_str(FILTER_ALL, *allow) {
5656
all_filter_alls.add(f);
5757
}
5858
}
@@ -804,7 +804,7 @@ fn warning_filter(
804804
n
805805
}
806806
};
807-
let filters = context.env.filter_from_str(name_, allow.clone());
807+
let filters = context.env.filter_from_str(name_, allow);
808808
if filters.is_empty() {
809809
let msg = format!("Unknown warning filter '{name_}'");
810810
context
@@ -2662,7 +2662,7 @@ fn check_valid_address_name_(
26622662

26632663
fn check_valid_local_name(context: &mut Context, v: &Var) {
26642664
fn is_valid(s: Symbol) -> bool {
2665-
s.starts_with('_') || s.starts_with(|c| matches!(c, 'a'..='z'))
2665+
s.starts_with('_') || s.starts_with(|c: char| c.is_ascii_lowercase())
26662666
}
26672667
if !is_valid(v.value()) {
26682668
let msg = format!(
@@ -2822,7 +2822,7 @@ fn check_valid_module_member_name_impl(
28222822
}
28232823

28242824
pub fn is_valid_struct_constant_or_schema_name(s: &str) -> bool {
2825-
s.starts_with(|c| matches!(c, 'A'..='Z'))
2825+
s.starts_with(|c: char| c.is_ascii_uppercase())
28262826
}
28272827

28282828
// Checks for a restricted name in any decl case

0 commit comments

Comments
 (0)