forked from FuelLabs/sway
-
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.
Fixes trait item method DCA warning. (FuelLabs#4229)
## Description ```rust pub trait MyTrait { fn trait_method(self) -> bool; } { fn item_method(self) -> bool { true } } ``` When a trait implements an item method in a library, the compiler should not throw a warning when the method is not used as it may be used by any Sway program that imports the library. Closes FuelLabs#3674. ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. --------- Co-authored-by: Mohammad Fawaz <[email protected]>
- Loading branch information
1 parent
5f452e5
commit 707bf2e
Showing
15 changed files
with
191 additions
and
14 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
8 changes: 8 additions & 0 deletions
8
test/src/e2e_vm_tests/test_programs/should_pass/dca/trait_method/Forc.lock
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,8 @@ | ||
[[package]] | ||
name = 'trait_method' | ||
source = 'member' | ||
dependencies = ['trait_method_lib'] | ||
|
||
[[package]] | ||
name = 'trait_method_lib' | ||
source = 'path+from-root-BB9C49E98039D004' |
9 changes: 9 additions & 0 deletions
9
test/src/e2e_vm_tests/test_programs/should_pass/dca/trait_method/Forc.toml
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,9 @@ | ||
[project] | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "trait_method" | ||
implicit-std = false | ||
|
||
[dependencies] | ||
trait_method_lib = { path = "../trait_method_lib" } |
29 changes: 29 additions & 0 deletions
29
test/src/e2e_vm_tests/test_programs/should_pass/dca/trait_method/src/main.sw
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,29 @@ | ||
script; | ||
|
||
use trait_method_lib::*; | ||
|
||
pub trait MyTrait2 { | ||
fn trait_method2(self) -> bool; | ||
} { | ||
fn method2(self) -> MyStruct { | ||
MyStruct {} | ||
} | ||
} | ||
|
||
impl MyTrait for MyStruct { | ||
fn trait_method(self) -> bool { | ||
true | ||
} | ||
} | ||
|
||
impl MyTrait2 for MyStruct { | ||
fn trait_method2(self) -> bool { | ||
true | ||
} | ||
} | ||
|
||
fn main() { | ||
let s = MyStruct {}; | ||
let b = s.trait_method(); | ||
let b = s.trait_method2(); | ||
} |
7 changes: 7 additions & 0 deletions
7
test/src/e2e_vm_tests/test_programs/should_pass/dca/trait_method/test.toml
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,7 @@ | ||
category = "compile" | ||
|
||
# check: $()fn method2(self) -> MyStruct { | ||
# check: $()This method is never called. | ||
|
||
expected_warnings = 1 | ||
|
3 changes: 3 additions & 0 deletions
3
test/src/e2e_vm_tests/test_programs/should_pass/dca/trait_method_lib/Forc.lock
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,3 @@ | ||
[[package]] | ||
name = 'trait_method_lib' | ||
source = 'member' |
6 changes: 6 additions & 0 deletions
6
test/src/e2e_vm_tests/test_programs/should_pass/dca/trait_method_lib/Forc.toml
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,6 @@ | ||
[project] | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "trait_method_lib" | ||
implicit-std = false |
13 changes: 13 additions & 0 deletions
13
test/src/e2e_vm_tests/test_programs/should_pass/dca/trait_method_lib/src/main.sw
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,13 @@ | ||
library; | ||
|
||
pub struct MyStruct { | ||
|
||
} | ||
|
||
pub trait MyTrait { | ||
fn trait_method(self) -> bool; | ||
} { | ||
fn method(self) -> MyStruct { | ||
MyStruct {} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
test/src/e2e_vm_tests/test_programs/should_pass/dca/trait_method_lib/test.toml
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,3 @@ | ||
category = "compile" | ||
expected_warnings = 0 | ||
|
13 changes: 13 additions & 0 deletions
13
test/src/e2e_vm_tests/test_programs/should_pass/dca/trait_method_neq/Forc.lock
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,13 @@ | ||
[[package]] | ||
name = 'core' | ||
source = 'path+from-root-A6EAB8F92CD55881' | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'path+from-root-A6EAB8F92CD55881' | ||
dependencies = ['core'] | ||
|
||
[[package]] | ||
name = 'trait_method_neq' | ||
source = 'member' | ||
dependencies = ['std'] |
8 changes: 8 additions & 0 deletions
8
test/src/e2e_vm_tests/test_programs/should_pass/dca/trait_method_neq/Forc.toml
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,8 @@ | ||
[project] | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "trait_method_neq" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../../../sway-lib-std" } |
23 changes: 23 additions & 0 deletions
23
test/src/e2e_vm_tests/test_programs/should_pass/dca/trait_method_neq/src/main.sw
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,23 @@ | ||
script; | ||
fn main() -> u64 { | ||
let a = 255; | ||
|
||
enum X { | ||
Y: bool, | ||
} | ||
|
||
impl core::ops::Eq for X { | ||
fn eq(self, other: Self) -> bool { | ||
asm(r1: self, r2: other, r3) { | ||
eq r3 r2 r1; | ||
r3: bool | ||
} | ||
} | ||
} | ||
|
||
if X::Y(true) == X::Y(true) { | ||
a | ||
} else { | ||
a | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
test/src/e2e_vm_tests/test_programs/should_pass/dca/trait_method_neq/test.toml
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,3 @@ | ||
category = "compile" | ||
expected_warnings = 0 | ||
|