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

Bug: incorrect generics when implemented method has more specific signature #513

Open
Nadrieril opened this issue Jan 2, 2025 · 1 comment
Assignees
Labels
C-bug A bug in charon

Comments

@Nadrieril
Copy link
Member

While working on #512, I discovered that there are two ways that an implemented method may have a different signature than expected from the trait:

  • the implemented method fn<..> A -> B type (including late-bound vars) may be a subtype of that of the declared method;
  • the implemented method may have less strict trait bounds.
trait Trait: Sized {
    fn method1(self, other: &'static u32);
    fn method2<T: Copy>(self, other: T); 
}

impl Trait for () {
    // This implementation is more general because it works for non-static refs.
    fn method1(self, _other: &u32) {}
    // This implementation is more general because it works for non-`Copy` `T`s.
    fn method2<T>(self, _other: T) {}
}

fn main() {
    let _ = ().method1(&1u32);
    // Error: we pass incorrect predicates
    // let _ = ().method2(false);
}

In both cases our translation is incorrect. Once #512 lands we'll be able to fix this by using the method binders to convert between the trait-declared method generics and the actually-implemented method generics.

@Nadrieril Nadrieril added the C-bug A bug in charon label Jan 2, 2025
@Nadrieril
Copy link
Member Author

cryspen/hax#1215 fixes some of the first kind of error but not yet all. I left a hack that we'll be able to remove after #127.

@Nadrieril Nadrieril self-assigned this Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug A bug in charon
Projects
None yet
Development

No branches or pull requests

1 participant