Skip to content
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

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

Closed
chris-morgan opened this issue Mar 25, 2015 · 4 comments · Fixed by #37851
Closed
Labels
A-typesystem Area: The type system E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@chris-morgan
Copy link
Member

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
@Ms2ger
Copy link
Contributor

Ms2ger commented Mar 25, 2015

#23630?

@Marwes
Copy link
Contributor

Marwes commented Mar 27, 2015

Smaller test case of what I believe to be the same bug.

fn test<T>(t: T) { }

fn main() {
    let t = test as fn (i32);
    t(0i32);
}

I don't have any knowledge of the inner workings of rustc but it seems that as doesn't unify the expression to the type at all. leading to the expr to still have an unknown type (fn (T) rather than fn (i32)).

@brson brson added E-help-wanted Call for participation: Help is requested to fix this issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. labels Nov 17, 2016
@brson
Copy link
Contributor

brson commented Nov 17, 2016

Both examples seem to work. Just add them to the test suite.

@brson brson added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Nov 17, 2016
@jneem
Copy link
Contributor

jneem commented Nov 17, 2016

I can do that

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Nov 23, 2016
Add a regression test for issue 23699.

This should close rust-lang#23699
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-typesystem Area: The type system E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants