Skip to content

Coercion to an unspecified but easily inferrable raw pointer (as *const _) has regressed #23699

Closed
@chris-morgan

Description

@chris-morgan

A couple of days ago it was all working fine, but in a fresh build (rustc 1.0.0-dev (593db005d 2015-03-25) (built 2015-03-25)) trouble is happening:

#![allow(dead_code)]

// Note that it’s got to be *const T; T compiles fine!
fn gimme_a_raw_pointer<T>(_: *const T) { }
fn gimme_a_raw_pointer_to_unit(_: *const ()) { }
fn gimme_a_raw_pointer_to_a_u8(_: *const u8) { }

fn main() {
    // This builds fine:
    //let pointer: *const _ = &();
    // But add an `as *const _` (the type ascription on `let pointer` is optional and meaningless):
    let pointer = &() as *const _;

    // Clearly `pointer` must be of type `*const ()`.

    // The real failure case was a “simple” `println!("{:?}", pointer)`.
    // I have extracted the essence of the failure here:
    gimme_a_raw_pointer(pointer);
    // Uncomment either of these two and it will suddenly figure out that that _ has got to be ().
    //gimme_a_raw_pointer_to_unit(pointer);
    //gimme_a_raw_pointer_to_a_u8(pointer);
}
<anon>:18:5: 18:24 error: unable to infer enough type information about `_`; type annotations required [E0282]
<anon>:18     gimme_a_raw_pointer(pointer);
              ^~~~~~~~~~~~~~~~~~~
error: aborting due to previous error

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-help-wantedCall for participation: Help is requested to fix this issue.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions