forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[move-compiler] Added a warning for unused function type params (Myst…
…enLabs#13112) ## Description Added a warning for unused function type params. Kept the same suppression annotation as for struct type params which required a small change to how known warning filters are stored. ## Test Plan Added new tests --- 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 - [x] 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 When building Move code new compiler warnings may appear pointing towards unused function type parameters
- Loading branch information
Showing
16 changed files
with
202 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
external-crates/move/move-compiler/tests/move_check/naming/unused_fun_tparam.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module 0x42::unused_fun_tparam { | ||
|
||
public fun unused<T>(): u64 { | ||
42 | ||
} | ||
|
||
public fun one_unused<T1, T2>(v: T1): T1 { | ||
v | ||
} | ||
|
||
public fun all_unused<T1, T2>(): u64 { | ||
42 | ||
} | ||
|
||
} |
Empty file.
32 changes: 32 additions & 0 deletions
32
external-crates/move/move-compiler/tests/move_check/naming/unused_fun_tparam.unused.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
warning[W09010]: unused function type parameter | ||
┌─ tests/move_check/naming/unused_fun_tparam.move:3:23 | ||
│ | ||
3 │ public fun unused<T>(): u64 { | ||
│ ^ Unused type parameter 'T'. | ||
│ | ||
= This warning can be suppressed with '#[allow(unused_type_parameter)]' applied to the 'module' or module member ('const', 'fun', or 'struct') | ||
|
||
warning[W09010]: unused function type parameter | ||
┌─ tests/move_check/naming/unused_fun_tparam.move:7:31 | ||
│ | ||
7 │ public fun one_unused<T1, T2>(v: T1): T1 { | ||
│ ^^ Unused type parameter 'T2'. | ||
│ | ||
= This warning can be suppressed with '#[allow(unused_type_parameter)]' applied to the 'module' or module member ('const', 'fun', or 'struct') | ||
|
||
warning[W09010]: unused function type parameter | ||
┌─ tests/move_check/naming/unused_fun_tparam.move:11:27 | ||
│ | ||
11 │ public fun all_unused<T1, T2>(): u64 { | ||
│ ^^ Unused type parameter 'T1'. | ||
│ | ||
= This warning can be suppressed with '#[allow(unused_type_parameter)]' applied to the 'module' or module member ('const', 'fun', or 'struct') | ||
|
||
warning[W09010]: unused function type parameter | ||
┌─ tests/move_check/naming/unused_fun_tparam.move:11:31 | ||
│ | ||
11 │ public fun all_unused<T1, T2>(): u64 { | ||
│ ^^ Unused type parameter 'T2'. | ||
│ | ||
= This warning can be suppressed with '#[allow(unused_type_parameter)]' applied to the 'module' or module member ('const', 'fun', or 'struct') | ||
|
51 changes: 51 additions & 0 deletions
51
external-crates/move/move-compiler/tests/move_check/naming/used_fun_tparam.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module 0x42::used_fun_tparam { | ||
// no warnings related to unused function type params should be generated for functions in this | ||
// module | ||
|
||
|
||
struct S<phantom T: key + drop> has key, drop { | ||
} | ||
|
||
public fun foo<T>(): T { | ||
abort 0 | ||
} | ||
|
||
public fun bar<T>(_: T) { | ||
abort 0 | ||
} | ||
|
||
|
||
public fun no_warn_sig_direct<T>(v: T): T { | ||
v | ||
} | ||
|
||
public fun no_warn_sig_indirect<T: key + drop>(v: S<T>): S<T> { | ||
v | ||
} | ||
|
||
public fun no_warn_pack<T: key + drop>() { | ||
let _ = S<T> {}; | ||
} | ||
|
||
public fun no_warn_pack_unpack<T: key + drop>() { | ||
let x = S {}; | ||
let S<T> {} = x; | ||
} | ||
|
||
public fun no_warn_bind<T: key + drop>() { | ||
let _: T = foo(); | ||
} | ||
|
||
public fun no_warn_call<T: key + drop>() { | ||
let _ = foo<T>(); | ||
} | ||
|
||
public fun no_warn_annotation<T: key + drop>() { | ||
let x = foo(); | ||
bar((x: T)); | ||
} | ||
|
||
|
||
|
||
|
||
} |
Empty file.
1 change: 1 addition & 0 deletions
1
external-crates/move/move-prover/move-abigen/tests/sources/some_script.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.