Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use specialization feature for AnyTryInto trait #7

Closed
3 tasks
cowboy-bebug opened this issue Oct 17, 2019 · 1 comment · Fixed by #9
Closed
3 tasks

Use specialization feature for AnyTryInto trait #7

cowboy-bebug opened this issue Oct 17, 2019 · 1 comment · Fixed by #9
Assignees

Comments

@cowboy-bebug
Copy link
Contributor

Refactor src/interpreter/type_cast.rs to

  • use specialization
  • have default impl (with default return)
  • refactor Any -> TryInto
@cowboy-bebug cowboy-bebug self-assigned this Oct 17, 2019
@cowboy-bebug
Copy link
Contributor Author

cowboy-bebug commented Oct 20, 2019

What we expected from specialization was something like:

// Parent (default) impl
impl<'a, T, U> PactTryInto<'a, T> for U { ... }
// Child (specialised) impl
impl<T: TryInto<u64>> PactTryInto<'a, T> for PactType<'a> { ... }
impl<T: AsRef<[u8]>>  PactTryInto<'a, T> for PactType<'a> { ... }

But the above impl blocks are non-overlapping to raise conflicting trait implementations error as the compiler doesn't know which of the children impl blocks to choose.

To make the above compile, the following can be observed:

// Parent (default) impl
impl<T: TryInto<u64>> PactTryInto<'a, T> for PactType<'a> { ... }
// Child (specialised) impl
impl<T: TryInto<u64> + AsRef<[u8]>>  PactTryInto<'a, T> for PactType<'a> { ... }

However, this is not what we want.

The issue could be revisited once specialization overlap rules are enhanced (see rust-lang/rust#42721 (comment) and rust-lang/rust#49624)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant