Skip to content

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

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
SSheldon opened this issue Aug 5, 2014 · 1 comment
Closed

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

SSheldon opened this issue Aug 5, 2014 · 1 comment

Comments

@SSheldon
Copy link
Contributor

SSheldon commented Aug 5, 2014

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)

@SSheldon
Copy link
Contributor Author

SSheldon commented Aug 5, 2014

Huh I'm sorry, this seems related to the switch to *mut. I thought I was calling RawPtr::null but wasn't. Looks like I should be using mut_null instead. My bad!

@SSheldon SSheldon closed this as completed Aug 5, 2014
bors added a commit to rust-lang-ci/rust that referenced this issue Jan 8, 2024
…, r=lnicola

Further tuning of the Gentoo installation instructions.

Based on feedback from the Gentoo repository maintainer, addition of the possibility to install rust-analyzer via rustup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant