Skip to content

Mismatched types error when using ptr::null with *mut #16262

Closed
@SSheldon

Description

@SSheldon

The following code won't compile:

fn main() {
    let foo: *mut uint = std::ptr::null();
}

Instead, it fails with error: mismatched types: expected *mut uintbut found*const <generic #1> (values differ in mutability)

But it gets better, this also won't compile:

fn main() {
    let foo: *mut uint = std::ptr::null() as *mut uint;
}

That fails with error: cannot determine a type for this expression: unconstrained type [E0101].

To get it to compile, you need to do:

fn main() {
    let foo: *mut uint = std::ptr::null::<uint>() as *mut uint;
}

This wasn't previously necessary (at least as of 0.11.0).

I'm using rustc 0.12.0-pre-nightly (4d4eb1023 2014-08-02 23:36:09 +0000)

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