Skip to content

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

Closed
@pnkfelix

Description

@pnkfelix

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions