Skip to content

CTFE error shown thrice #52922

Closed
Closed
@RalfJung

Description

@RalfJung

This program

#![allow(const_err)]

union Foo {
    a: &'static u8,
    b: usize,
}

const BAD: usize = unsafe { Foo { a: &1 }.b * 2};
fn main() {
    let f = BAD;
}

leads to the following errors:

error[E0080]: referenced constant has errors
  --> src/main.rs:10:13
   |
8  | const BAD: usize = unsafe { Foo { a: &1 }.b * 2};
   |                             ------------------- "pointer arithmetic or comparison" needs an rfc before being allowed inside constants
9  | fn main() {
10 |     let f = BAD;
   |             ^^^

error[E0080]: could not evaluate constant
  --> src/main.rs:10:13
   |
10 |     let f = BAD;
   |             ^^^ referenced constant has errors

error[E0080]: constant evaluation error
 --> src/main.rs:8:1
  |
8 | const BAD: usize = unsafe { Foo { a: &1 }.b * 2};
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------------------^^
  |                             |
  |                             "pointer arithmetic or comparison" needs an rfc before being allowed inside constants

error: aborting due to 3 previous errors

Seems like overkill to say three times that the constant has errors. ;)

Cc @oli-obk

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions