Skip to content

Type parameter confusingly inferred to bogus type #2310

Closed
@brson

Description

@brson

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions