Skip to content

poor error message when casting from fat raw pointer to usize #27450

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
durka opened this issue Aug 1, 2015 · 5 comments
Closed

poor error message when casting from fat raw pointer to usize #27450

durka opened this issue Aug 1, 2015 · 5 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@durka
Copy link
Contributor

durka commented Aug 1, 2015

playpen

trait Num {}
impl Num for i32 {}

fn main() {
    &0i32 as *const Num as usize;
}

This compiles on stable, but beta and nightly require an extra as *const () in the middle to cast away the fat. The error message says to use a "raw pointer" which is misleading as *const Num is already a raw pointer, it's just a fat one.

Since this code compiles on stable, I'm not sure if it's also a regression or if I missed an RFC (to be fair, I miss a lot of RFCs).

@bluss
Copy link
Member

bluss commented Aug 1, 2015

I'm sure it went in as a bug fix. cc @arielb1

@arielb1
Copy link
Contributor

arielb1 commented Aug 1, 2015

This is indeed intentional: the spec at https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md has this relevant part: e has type *T and U is a numeric type, while T: Sized; ptr-addr-cast. IIRC @nrc made that decision.

@arielb1
Copy link
Contributor

arielb1 commented Aug 1, 2015

The old (1.1) cast code was a badly specified mess of if-s. It is rather badly behaved.

@durka
Copy link
Contributor Author

durka commented Aug 1, 2015

Noted. Is this still a (minor) diagnostics issue, or I just don't
understand the terminology? The compiler's advice is to cast through a "raw
pointer", but the actual fix is to cast through a thin pointer.
On Aug 1, 2015 12:28 PM, "arielb1" [email protected] wrote:

The old (1.1) cast code was a badly specified mess of if-s. Do not report
bugs.


Reply to this email directly or view it on GitHub
#27450 (comment).

@arielb1
Copy link
Contributor

arielb1 commented Aug 1, 2015

This may be a diagnostic issue. cc @steveklabnik

@nrc nrc added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. A-diagnostics Area: Messages for errors, warnings, and lints labels Aug 3, 2015
@nrc nrc changed the title bad error and/or stable regression when casting from fat raw pointer to usize poor error message when casting from fat raw pointer to usize Aug 3, 2015
bors added a commit that referenced this issue Aug 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

4 participants