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

Implicit trait implementation do not work #5883

Open
SwayStar123 opened this issue Apr 19, 2024 · 0 comments
Open

Implicit trait implementation do not work #5883

SwayStar123 opened this issue Apr 19, 2024 · 0 comments

Comments

@SwayStar123
Copy link
Member

Minimum reproduction:

contract;

use std::convert::*;
use std::primitive_conversions::u64::*;

abi MyContract {
    fn test_function() -> bool;
}

impl MyContract for Contract {
    fn test_function() -> bool {
        true
    }
}

pub struct MyStruct {
    inner_val: u64,
}

impl MyStruct {
    pub fn new<T>(val: T) -> Self
    where T: Into<u64> {
        MyStruct { inner_val: val.into() }
    }
}

#[test]
fn test_method() {
    let s1 = MyStruct::new(1u8);

    assert(s1.inner_val == 1);
}

Despite impl From<u8> for u64 existing, and

impl<T, U> Into<U> for T
where
    U: From<T>,
{

existing, the compiler errors with
^^^^^^^^^^^^ Trait "Into<u64>" is not implemented for type "u8".

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

No branches or pull requests

1 participant