Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion external-crates/move/crates/move-compiler/tests/.prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,15 @@
"autoGroupImports": "module",
"printWidth": 100,
"useModuleLabel": false,
"tabWidth": 4
"tabWidth": 4,
"overrides": [
{
"files": "linter/move_2024/*.move",
"options": {
"parser": "move",
"tabWidth": 4,
"useModuleLabel": true
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,26 @@ fun t0(): u64 { return 5 }
#[allow(lint(unneeded_return))]
fun t1(): u64 { return t0() }

public struct S { }
public struct S {}

#[allow(lint(unneeded_return))]
fun t2(): S { return S { } }
fun t2(): S { return S {} }

public enum E { V }
public enum E {
V,
}

#[allow(lint(unneeded_return))]
fun t3(): E { return E::V }

#[allow(lint(unneeded_return))]
fun t4(): vector<u64> { return vector[1,2,3] }
fun t4(): vector<u64> { return vector[1, 2, 3] }

#[allow(lint(unneeded_return))]
fun t5() { return () }

#[allow(lint(unneeded_return))]
fun t6(): u64 { let x = 0; return move x
}
fun t6(): u64 { let x = 0; return move x }

#[allow(lint(unneeded_return))]
fun t7(): u64 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// this should warn, but it does not at the current state of optimizations in the compiler

module a::m;

fun test_equal_operand() {
let x = 0;
&x == &0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ public struct S has copy, drop {
// Non-Local but Simple Borrow Cases

public fun literal_case() {
let _ref = &*&0; // Redundant borrow-dereference on literal
let _ref = &*&0; // Redundant borrow-dereference on literal
}

public fun literal_case_valid() { let _ref = &0; }

public fun get_resource(): S { S { a: 20 } }

public fun function_call_case() {
let _ref = &*&get_resource(); // Redundant borrow-dereference on function call result
let _ref = &*&get_resource(); // Redundant borrow-dereference on function call result
}

public fun function_call_case_valid() { let _ref = &get_resource(); }
Expand All @@ -24,30 +24,30 @@ public fun function_call_case_valid() { let _ref = &get_resource(); }

public fun field_borrows() {
let resource = S { a: 10 };
let _ref = &*(&*&resource.a); // Multiple redundant borrows on field
let _ref = &*(&*&resource.a); // Multiple redundant borrows on field
}

public fun field_borrows_valid() {
let resource = S { a: 10 };
let _ref = &(copy resource.a); // Multiple redundant borrows on field
let _ref = &(copy resource.a); // Multiple redundant borrows on field
}

public fun mixed_borrow_types() {
let resource = S { a: 10 };
let _ref = &*&mut *&resource; // Mixed mutable and immutable redundant borrows
let _ref = &*&mut *&resource; // Mixed mutable and immutable redundant borrows
}

public fun mixed_borrow_types_valid() {
let resource = S { a: 10 };
let _ref = &(copy resource); // Mixed mutable and immutable redundant borrows
let _ref = &(copy resource); // Mixed mutable and immutable redundant borrows
}

public fun complex_expression() {
let resource = S { a: 10 };
let _a = *&(*&resource.a + 1); // Redundant borrows in complex expression
let _a = *&(*&resource.a + 1); // Redundant borrows in complex expression
}

public fun complex_expression_valid() {
let resource = S { a: 10 };
let _a = (copy resource.a) + 1; // Redundant borrows in complex expression
let _a = (copy resource.a) + 1; // Redundant borrows in complex expression
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,71 +8,71 @@ info:
warning[Lint W01009]: redundant reference/dereference
┌─ tests/linter/move_2024/ref_deref_complex.move:10:17
10 │ let _ref = &*&0; // Redundant borrow-dereference on literal
10 │ let _ref = &*&0; // Redundant borrow-dereference on literal
│ ^^^ Redundant borrow-dereference detected. Remove this borrow-deref and use the expression directly.
= This warning can be suppressed with '#[allow(lint(redundant_ref_deref))]' applied to the 'module' or module member ('const', 'fun', or 'struct')

warning[Lint W01009]: redundant reference/dereference
┌─ tests/linter/move_2024/ref_deref_complex.move:18:17
18 │ let _ref = &*&get_resource(); // Redundant borrow-dereference on function call result
18 │ let _ref = &*&get_resource(); // Redundant borrow-dereference on function call result
│ ^^^^^^^^^^^^^^^^ Redundant borrow-dereference detected. Remove this borrow-deref and use the expression directly.
= This warning can be suppressed with '#[allow(lint(redundant_ref_deref))]' applied to the 'module' or module member ('const', 'fun', or 'struct')

warning[Lint W01009]: redundant reference/dereference
┌─ tests/linter/move_2024/ref_deref_complex.move:27:17
27 │ let _ref = &*(&*&resource.a); // Multiple redundant borrows on field
27 │ let _ref = &*(&*&resource.a); // Multiple redundant borrows on field
│ ^^^^^^^^^^^^^^^^ Redundant borrow-dereference detected. Use the inner expression directly.
= This warning can be suppressed with '#[allow(lint(redundant_ref_deref))]' applied to the 'module' or module member ('const', 'fun', or 'struct')

warning[Lint W01009]: redundant reference/dereference
┌─ tests/linter/move_2024/ref_deref_complex.move:27:20
27 │ let _ref = &*(&*&resource.a); // Multiple redundant borrows on field
27 │ let _ref = &*(&*&resource.a); // Multiple redundant borrows on field
│ ^^^^^^^^^^^^ Redundant borrow-dereference detected. Use the field access directly.
= This warning can be suppressed with '#[allow(lint(redundant_ref_deref))]' applied to the 'module' or module member ('const', 'fun', or 'struct')

warning[Lint W01009]: redundant reference/dereference
┌─ tests/linter/move_2024/ref_deref_complex.move:32:18
32 │ let _ref = &(copy resource.a); // Multiple redundant borrows on field
32 │ let _ref = &(copy resource.a); // Multiple redundant borrows on field
│ ^^^^^^^^^^^^^^^ Redundant borrow-dereference detected. Use the field access directly.
= This warning can be suppressed with '#[allow(lint(redundant_ref_deref))]' applied to the 'module' or module member ('const', 'fun', or 'struct')

warning[Lint W01009]: redundant reference/dereference
┌─ tests/linter/move_2024/ref_deref_complex.move:37:17
37 │ let _ref = &*&mut *&resource; // Mixed mutable and immutable redundant borrows
37 │ let _ref = &*&mut *&resource; // Mixed mutable and immutable redundant borrows
│ ^^^^^^^^^^^^^^^^ Redundant borrow-dereference detected. Use the inner expression directly.
= This warning can be suppressed with '#[allow(lint(redundant_ref_deref))]' applied to the 'module' or module member ('const', 'fun', or 'struct')

warning[Lint W01009]: redundant reference/dereference
┌─ tests/linter/move_2024/ref_deref_complex.move:37:23
37 │ let _ref = &*&mut *&resource; // Mixed mutable and immutable redundant borrows
37 │ let _ref = &*&mut *&resource; // Mixed mutable and immutable redundant borrows
│ ^^^^^^^^^^ Redundant borrow-dereference detected. Replace this borrow-deref with 'copy'.
= This warning can be suppressed with '#[allow(lint(redundant_ref_deref))]' applied to the 'module' or module member ('const', 'fun', or 'struct')

warning[Lint W01009]: redundant reference/dereference
┌─ tests/linter/move_2024/ref_deref_complex.move:47:17
47 │ let _a = *&(*&resource.a + 1); // Redundant borrows in complex expression
47 │ let _a = *&(*&resource.a + 1); // Redundant borrows in complex expression
│ ^^^^^^^^^^^^ Redundant borrow-dereference detected. Use the field access directly.
= This warning can be suppressed with '#[allow(lint(redundant_ref_deref))]' applied to the 'module' or module member ('const', 'fun', or 'struct')

warning[Lint W01009]: redundant reference/dereference
┌─ tests/linter/move_2024/ref_deref_complex.move:52:15
52 │ let _a = (copy resource.a) + 1; // Redundant borrows in complex expression
52 │ let _a = (copy resource.a) + 1; // Redundant borrows in complex expression
│ ^^^^^^^^^^^^^^^ Redundant borrow-dereference detected. Use the field access directly.
= This warning can be suppressed with '#[allow(lint(redundant_ref_deref))]' applied to the 'module' or module member ('const', 'fun', or 'struct')
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,47 @@ struct MyResource has copy, drop {
// Case 1: Should be flagged - simple &*& pattern
public fun should_flag_simple() {
let resource = MyResource { value: 10 };
let _ref = &*&resource; // Should be flagged
let _ref = &*&resource; // Should be flagged
}

// Case 2: Should be flagged - &mut *& pattern
public fun should_flag_mut() {
let resource = MyResource { value: 10 };
let _ref = &mut *&resource; // Should be flagged
let _ref = &mut *&resource; // Should be flagged
}

// Case 3: Should be flagged - &*& pattern with field access
public fun should_flag_field() {
let mut resource = MyResource { value: 10 };
let _ref = &*&resource.value; // Should be flagged
let _ref = &*&resource.value; // Should be flagged
resource.value = 10;
}

// Case 3: Should not be flagged - &* pattern without extra &
public fun should_not_flag_modified() {
let resource = MyResource { value: 10 };
let ref1 = &resource;
resource.value = 20; // Modifying the resource
let _ref2 = &*ref1; // No flag -- ref was made elsewhere
resource.value = 20; // Modifying the resource
let _ref2 = &*ref1; // No flag -- ref was made elsewhere
}

// Case 5: Should be flagged - nested &*& pattern
public fun should_flag_nested() {
let resource = MyResource { value: 10 };
let _ref = &*(&*&resource); // Should be flagged
let _ref = &*(&*&resource); // Should be flagged
}

// Case 6: Should not be flagged - &* pattern without extra &
public fun should_not_flag_deref_only() {
let resource = MyResource { value: 10 };
let ref1 = &resource;
let _ref2 = &*ref1; // Should not be flagged
let _ref2 = &*ref1; // Should not be flagged
}

// Case 7: Should be flagged - *& pattern without leading &
public fun should_flag_copy() {
let resource = MyResource { value: 10 };
let _copy = *&resource; // Should be flagged, making a copy
let _copy = *&resource; // Should be flagged, making a copy
}

// Case 8: Should be flagged for removal - &*& pattern with function call
Expand All @@ -56,20 +56,20 @@ public fun get_resource(): MyResource {
}

public fun should_flag_function_call() {
let _ref = &*&get_resource(); // Should be flagged
let _ref = &*&get_resource(); // Should be flagged
}

// Case 9: Should be flagged for removal - &*& pattern with constant value
public fun should_flag_value() {
let _ref = &*&0; // Should be flagged
let _ref = &*&0; // Should be flagged
}

// Case 10: Should be flagged - &*& pattern but path is mutated in a loop
public fun should_flag_loop_mutation() {
let mut resource = MyResource { value: 10 };
let mut i = 0;
while (i < 5) {
let _ref = &*&resource; // Should be flagged regardless
let _ref = &*&resource; // Should be flagged regardless
resource.value = resource.value + 1;
i = i + 1;
}
Expand All @@ -80,10 +80,10 @@ const E: u64 = 0;
// Case 11: Should be flagged -- constant
#[allow(implicit_const_copy)]
public fun should_flag_constant() {
let _ref = &*&E; // Should be flagged
let _ref = &*&E; // Should be flagged
}

// Case 12: Should be flagged -- vector
public fun should_flag_vector() {
let _ref = &*&vector[1,2,3]; // Should be flagged
let _ref = &*&vector[1, 2, 3]; // Should be flagged
}
Loading
Loading