Skip to content

example for --explain E0018 claims to demo it, but does not #25326

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
pnkfelix opened this issue May 12, 2015 · 2 comments · Fixed by #25834
Closed

example for --explain E0018 claims to demo it, but does not #25326

pnkfelix opened this issue May 12, 2015 · 2 comments · Fixed by #25834

Comments

@pnkfelix
Copy link
Member

example for --explain E0018 claims to demo it, but does not

I was reading over

http://doc.rust-lang.org/error-index.html#E0018

And I thought: "this should compile fine. If that yields an error, it's a bug."

So I checked. It does not yield the error.

Here is the text in question:

The value of static and const variables must be known at compile time. You can't cast a pointer as an integer because we can't know what value the address will take.

However, pointers to other constants' addresses are allowed in constants, example:

const X: u32 = 50;
const Y: *const u32 = &X;

Therefore, casting one of these non-constant pointers to an integer results in a non-constant integer which lead to this error. Example:

const X: u32 = 50;
const Y: *const u32 = &X;
println!("{:?}", Y);
@daboross
Copy link
Contributor

For reference, here's some code which (I believe) does fail with this: https://github.com/rust-lang/rust/blob/master/src/test/compile-fail/issue-18294.rs

@pnkfelix
Copy link
Member Author

Yes, it seems like the example in the explanation have lost the *const T as usize step that you can see in that compile-fail test.

steveklabnik added a commit to steveklabnik/rust that referenced this issue May 27, 2015
XMPPwocky pushed a commit to XMPPwocky/rust that referenced this issue May 29, 2015
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

Successfully merging a pull request may close this issue.

3 participants