-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes error while using From trait that returns a tuple.
Instead of `Trait "MyFrom<u256>" is not implemented for type "U".` We now get `Trait "MyFrom<u256>" is not implemented for type "(_, _, _, _)".` The error is followed by: `Cannot infer type for type parameter "_". Insufficient type information provided. Try annotating its type.` While Rust compiler is able to inference the type in this situation it is non trivial to do it properly hence we should probably keep asking for the type to be annotated.
- Loading branch information
Showing
5 changed files
with
82 additions
and
30 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
13 changes: 13 additions & 0 deletions
13
..._vm_tests/test_programs/should_fail/generic_trait_tuple_without_type_ascription/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-B089E2A459F9A9B9" | ||
|
||
[[package]] | ||
name = "generic_trait_tuple_without_type_ascription" | ||
source = "member" | ||
dependencies = ["std"] | ||
|
||
[[package]] | ||
name = "std" | ||
source = "path+from-root-B089E2A459F9A9B9" | ||
dependencies = ["core"] |
8 changes: 8 additions & 0 deletions
8
..._vm_tests/test_programs/should_fail/generic_trait_tuple_without_type_ascription/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 = "generic_trait_tuple_without_type_ascription" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../../sway-lib-std" } |
32 changes: 32 additions & 0 deletions
32
...m_tests/test_programs/should_fail/generic_trait_tuple_without_type_ascription/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,32 @@ | ||
script; | ||
|
||
pub trait MyFrom<T> { | ||
fn from(b: T) -> Self; | ||
} | ||
|
||
|
||
pub trait MyInto<T> { | ||
fn into(self) -> T; | ||
} | ||
|
||
|
||
impl<T, U> MyInto<U> for T | ||
where | ||
U: MyFrom<T>, | ||
{ | ||
fn into(self) -> U { | ||
U::from(self) | ||
} | ||
} | ||
|
||
impl MyFrom<u256> for (u64, u64, u64, u64) { | ||
fn from(_val: u256) -> (u64, u64, u64, u64) { | ||
(42, 0, 0, 0) | ||
} | ||
} | ||
|
||
fn main() -> bool { | ||
let (_a, _b, _c, _d) = u256::min().into(); | ||
|
||
true | ||
} |
7 changes: 7 additions & 0 deletions
7
..._vm_tests/test_programs/should_fail/generic_trait_tuple_without_type_ascription/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 = "fail" | ||
|
||
# check: $()let (_a, _b, _c, _d) = u256::min().into(); | ||
# nextln: $()Trait "MyFrom<u256>" is not implemented for type "(_, _, _, _)". | ||
|
||
# check: $()let (_a, _b, _c, _d) = u256::min().into(); | ||
# nextln: $()Cannot infer type for type parameter "_". Insufficient type information provided. Try annotating its type. |