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

Into::into needs From impl or turbofish #6530

Closed
michaeljklein opened this issue Nov 15, 2024 · 1 comment · Fixed by #7089
Closed

Into::into needs From impl or turbofish #6530

michaeljklein opened this issue Nov 15, 2024 · 1 comment · Fixed by #7089
Labels
bug Something isn't working

Comments

@michaeljklein
Copy link
Contributor

Aim

Attempted to compile a program with an Into<Field> that's called like let _: Field = T.into():

struct Foo {
    inner: Field,
}

impl Into<Field> for Foo {
    fn into(self) -> Field {
        self.inner
    }
}

fn main() {
    let foo = Foo {
        inner: 0,
    };

    // This works:
    // let _: Field = Into::<Field>::into(foo);

    // This fails with 'No matching impl':
    //
    // error: No matching impl found for `Field: From<Foo>`
    //     ┌─ main.nr:439:20
    //     │
    // 439 │     let _: Field = foo.into();
    //     │                    -------- No impl for `Field: From<Foo>`
    //     │
    let _: Field = foo.into();
}

Expected Behavior

Expected that, given impl Into<Field> for Foo and the following definition for Into:

pub trait Into<T> {
    fn into(self) -> T;
}

For any foo: Foo, calling foo.into() when the return type is known to be Field would convert Foo -> Field.

Bug

foo.into() fails with the following error:

error: No matching impl found for `Field: From<Foo>`
    ┌─ main.nr:439:20
    │
439 │     let _: Field = foo.into();
    │                    -------- No impl for `Field: From<Foo>`

It appears to be "getting stuck" on the following impl for Into:

impl<T, U> Into<T> for U
where
    T: From<U>,
{
    fn into(self) -> T {
        T::from(self)
    }
}

However, it's unclear why this is happening since the turbofish version works: Into::<Field>::into(foo)

To Reproduce

Workaround

Yes

Workaround Description

Use turbofish

Additional Context

No response

Project Impact

Nice-to-have

Blocker Context

No response

Nargo Version

nargo version = 0.38.0 noirc version = 0.38.0+0fc0c53ec183890370c69aa4148952b3123cb055 (git version hash: 0fc0c53, is dirty: false)

NoirJS Version

No response

Proving Backend Tooling & Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@michaeljklein michaeljklein added the bug Something isn't working label Nov 15, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Nov 15, 2024
@asterite
Copy link
Collaborator

It seems this works in master, probably fixed by #7041

@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Jan 15, 2025
michaeljklein added a commit that referenced this issue Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants