Skip to content

Type hint on structs is ignored #9620

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

Closed
huonw opened this issue Sep 30, 2013 · 2 comments
Closed

Type hint on structs is ignored #9620

huonw opened this issue Sep 30, 2013 · 2 comments
Labels
P-low Low priority

Comments

@huonw
Copy link
Member

huonw commented Sep 30, 2013

This compiles fine:

struct Point <T> { x: T, y: T }

fn main() {
    let _b: Point<u64> = Point::<u8> { x: 1, y: 2 };
}
@luqmana
Copy link
Member

luqmana commented Dec 12, 2013

This makes using phantom types a bit annoying:

enum Open {}
enum Closed {}

struct Door<State> {
    name: ~str
}

fn open(Door { name }: Door<Closed>) -> Door<Open> {
    Door { name: name }
}

fn main() {
    let d: Door<Open> = Door { name: ~"front" };
    open(d); // Fails (as it should)

    let d = Door::<Open> { name: ~"front" };
    open(d); // Should fail but doesn't
}

@pnkfelix
Copy link
Member

P-low, not 1.0 blocker.

pcwalton added a commit to pcwalton/rust that referenced this issue Jul 24, 2014
This breaks code like:

    struct Point<T> {
        x: T,
        y: T,
    }

    let pt = Point::<bool> {
        x: 1,
        y: 2,
    };

Change this code to not contain a type error. For example:

    let pt = Point::<int> {
        x: 1,
        y: 2,
    };

Closes rust-lang#9620.
Closes rust-lang#15875.

[breaking-change]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P-low Low priority
Projects
None yet
Development

No branches or pull requests

3 participants