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

Type inference issues around generic impls #1447

Closed
bjorn3 opened this issue Aug 8, 2022 · 0 comments · Fixed by #1451
Closed

Type inference issues around generic impls #1447

bjorn3 opened this issue Aug 8, 2022 · 0 comments · Fixed by #1451

Comments

@bjorn3
Copy link

bjorn3 commented Aug 8, 2022

I tried this code:

struct PhantomData<T>;

struct Hasher<S> {
    _marker: PhantomData<S>,
}

struct Sip24Rounds;

struct SipHasher24 {
    hasher: Hasher<Sip24Rounds>,
}

impl SipHasher24 {
    pub fn new_with_keys(key0: u64, key1: u64) -> SipHasher24 {
        SipHasher24 { hasher: Hasher::new_with_keys() }
    }
}

impl<S> Hasher<S> {
    #[inline]
    fn new_with_keys() -> Hasher<S> {
        Hasher {
            _marker: PhantomData,
        }
    }
}

I expected to see this happen: Compiles

Instead, this happened:

<source>:15:31: error: type annotations needed
   15 |         SipHasher24 { hasher: Hasher::new_with_keys() }
      |                               ^
<source>:15:39: error: type annotations needed
   15 |         SipHasher24 { hasher: Hasher::new_with_keys() }
      |                                       ^
<source>:22:9: error: type annotations needed
   22 |         Hasher {
      |         ^
Compiler returned: 1

Meta

  • What version of Rust GCC were you using, git sha if possible.
gccrs (Compiler-Explorer-Build-gcc-8809ee8c6a5621e830f3cfe66c381f986e63c7f2-binutils-2.38) 12.0.1 20220118 (experimental)
@bjorn3 bjorn3 added the bug label Aug 8, 2022
@bjorn3 bjorn3 mentioned this issue Aug 8, 2022
16 tasks
philberty added a commit that referenced this issue Aug 8, 2022
There is some dulication here which will eventually go away with the
coercion site refactor which is still a WIP. Here we update the type rules
so that we allow ADT's and tuples to unify and thus fulfill the type
inference rules.

Addresses #1447
philberty added a commit that referenced this issue Aug 8, 2022
When we have generic unit-structs there are no fields to unify the generic.
This adds a case to ensure we iterate and check these. We might end up
making it always do this for all structs always.

Addresses #1447
@philberty philberty added this to To do in Const generics and missing features sprint via automation Aug 9, 2022
@philberty philberty self-assigned this Aug 9, 2022
bors bot added a commit that referenced this issue Aug 9, 2022
1425: Cleanup frontend entrypoint r=CohenArthur a=CohenArthur

This removes a lot of code that was simply ported from the Go frontend, and forbids the usage of multiple input files.

Addresses #1115

1451: Fix failiure to type inference on unit-structs r=philberty a=philberty

This patch set adds fixes to ensure we can type inference generic unit-structs.

Fixes #1447 

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
@bors bors bot closed this as completed in 92eef6c Aug 9, 2022
Const generics and missing features sprint automation moved this from To do to Done Aug 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants