Skip to content

Pointer type inference fails with 'unconstrained type' error #14861

Closed
@bnoordhuis

Description

@bnoordhuis
$ cat t.rs 
struct A<T> { inner: *T }
struct B;

fn main() {
    // works
    let _: A<B> = A::<B> { inner: std::ptr::null() };
    // works
    let _ = A::<B> { inner: std::ptr::null::<B>() };
    // cannot determine a type for this local variable: unconstrained type
    let _ = A::<B> { inner: std::ptr::null() };
}

$ rustc -v
rustc 0.11.0-pre (3a9228b 2014-06-12 19:36:53 +0000)
host: x86_64-unknown-linux-gnu

$ rustc t.rs 
t.rs:10:9: 10:47 error: cannot determine a type for this local variable: unconstrained type
t.rs:10     let _ = A::<B> { inner: std::ptr::null() };
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error

The third assignment seems unambiguous but the compiler won't accept it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions