Skip to content

Type parameter confusingly inferred to bogus type #2310

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
brson opened this issue Apr 27, 2012 · 3 comments
Closed

Type parameter confusingly inferred to bogus type #2310

brson opened this issue Apr 27, 2012 · 3 comments
Assignees
Labels
A-type-system Area: Type system

Comments

@brson
Copy link
Contributor

brson commented Apr 27, 2012

I wrote the equivalent of this earlier and it baffled me for several minutes.

fn size_of<T>() -> uint {
    // Expecting (though unreasonably) the type parameter to be
    // inferred to T, it is actually inferred to something byte-sized (nil?)
    sys::size_of()
}

fn main() {
    // Why does size_of::<u32>() return 1?
    assert size_of::<u32>() == 4u;
}

It works correctly when you write sys::size_of::<T>(). I don't think this should typecheck.

@marijnh
Copy link
Contributor

marijnh commented Apr 27, 2012

I think this is related to a change @nikomatsakis made, where unrestricted type variables, rather than raising an error, are silently converted to _|_. I've had similar problems with it, where I got strange errors when casting things to iface types. I think we should probably make this an error again.

@nikomatsakis
Copy link
Contributor

That is the problem. I'd be happy to make it an error again. I don't like that change.

@ghost ghost assigned nikomatsakis Apr 29, 2012
@nikomatsakis
Copy link
Contributor

Fixed in 2db4259.

jieyouxu added a commit to jieyouxu/rust that referenced this issue Apr 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system
Projects
None yet
Development

No branches or pull requests

3 participants