Skip to content

consts that depend on other constants which fail to evaluate create difficult to read error messages due to notes: output #135259

Open
@repnop

Description

@repnop
Contributor

Code

macro_rules! blarg {
    () => {
        const A: u32 = const {
            panic!()
        };
        
        const B: u32 = A + 1;
        const C: u32 = B + 1;
        const D: u32 = C + 1;
    }
}

blarg!();

Current output

Compiling playground v0.0.1 (/playground)
error[E0080]: evaluation of `A::{constant#0}` failed
  --> src/lib.rs:13:1
   |
13 | blarg!();
   | ^^^^^^^^ the evaluated program panicked at 'explicit panic', src/lib.rs:13:1
   |
   = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `blarg` (in Nightly builds, run with -Z macro-backtrace for more info)

note: erroneous constant encountered
  --> src/lib.rs:3:24
   |
3  |           const A: u32 = const {
   |  ________________________^
4  | |             panic!()
5  | |         };
   | |_________^
...
13 |   blarg!();
   |   -------- in this macro invocation
   |
   = note: this note originates in the macro `blarg` (in Nightly builds, run with -Z macro-backtrace for more info)

note: erroneous constant encountered
  --> src/lib.rs:7:24
   |
7  |         const B: u32 = A + 1;
   |                        ^
...
13 | blarg!();
   | -------- in this macro invocation
   |
   = note: this note originates in the macro `blarg` (in Nightly builds, run with -Z macro-backtrace for more info)

note: erroneous constant encountered
  --> src/lib.rs:8:24
   |
8  |         const C: u32 = B + 1;
   |                        ^
...
13 | blarg!();
   | -------- in this macro invocation
   |
   = note: this note originates in the macro `blarg` (in Nightly builds, run with -Z macro-backtrace for more info)

note: erroneous constant encountered
  --> src/lib.rs:9:24
   |
9  |         const D: u32 = C + 1;
   |                        ^
...
13 | blarg!();
   | -------- in this macro invocation
   |
   = note: this note originates in the macro `blarg` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0080`.
error: could not compile `playground` (lib) due to 1 previous error

Desired output

Compiling playground v0.0.1 (/playground)
error[E0080]: evaluation of `A::{constant#0}` failed
  --> src/lib.rs:13:1
   |
13 | blarg!();
   | ^^^^^^^^ the evaluated program panicked at 'explicit panic', src/lib.rs:13:1
   |
   = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `blarg` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0080`.
error: could not compile `playground` (lib) due to 1 previous error

Rationale and extra context

playground link to repro: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=f8bd0c35877ea97f896174c4543618cc

seems like a regression of this previous issue & fix: #110891

while working on a macro for rasn, I tested the panic conditions for failure to parse the input literal, which I noticed produces a wall of note:s that are utterly useless (especially given the fact that the macro is not expanded in the doctest so the error spans are just the same macro invocation over and over + a couple others, which makes finding the error very difficult:

error[E0080]: evaluation of `main::_doctest_main_src_macros_rs_193_0::SYS_DESCR::OID::{constant#0}::COMPONENTS::{constant#0}` failed
 --> src/macros.rs:195:46
  |
5 | const SYS_DESCR: &'static rasn::types::Oid = rasn::oid!(".3.3.6.1.2.1.2.2.1.3");
  |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'the first OID arc must be <= 2', src/macros.rs:5:46
  |
  = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `rasn::oid` (in Nightly builds, run with -Z macro-backtrace for more info)

note: erroneous constant encountered
 --> src/macros.rs:195:46
  |
5 | const SYS_DESCR: &'static rasn::types::Oid = rasn::oid!(".3.3.6.1.2.1.2.2.1.3");
  |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this note originates in the macro `rasn::oid` (in Nightly builds, run with -Z macro-backtrace for more info)

note: erroneous constant encountered
 --> src/macros.rs:195:46
  |
5 | const SYS_DESCR: &'static rasn::types::Oid = rasn::oid!(".3.3.6.1.2.1.2.2.1.3");
  |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this note originates in the macro `rasn::oid` (in Nightly builds, run with -Z macro-backtrace for more info)

note: erroneous constant encountered
 --> src/macros.rs:195:46
  |
5 | const SYS_DESCR: &'static rasn::types::Oid = rasn::oid!(".3.3.6.1.2.1.2.2.1.3");
  |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this note originates in the macro `rasn::oid` (in Nightly builds, run with -Z macro-backtrace for more info)

note: erroneous constant encountered
 --> src/macros.rs:195:46
  |
5 | const SYS_DESCR: &'static rasn::types::Oid = rasn::oid!(".3.3.6.1.2.1.2.2.1.3");
  |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this note originates in the macro `rasn::oid` (in Nightly builds, run with -Z macro-backtrace for more info)

note: erroneous constant encountered
 --> src/macros.rs:196:12
  |
6 | assert_eq!(SYS_DESCR, rasn::types::Oid::new(&[1, 3, 6, 1, 2, 1, 2, 2, 1, 3]).unwrap());
  |            ^^^^^^^^^

note: erroneous constant encountered
 --> src/macros.rs:196:1
  |
6 | assert_eq!(SYS_DESCR, rasn::types::Oid::new(&[1, 3, 6, 1, 2, 1, 2, 2, 1, 3]).unwrap());
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)

Other cases

Rust Version

rustc 1.85.0-beta.1 (e30eefff4 2025-01-08)
binary: rustc
commit-hash: e30eefff41038ceea427009023627d6d66b36715
commit-date: 2025-01-08
host: x86_64-unknown-linux-gnu
release: 1.85.0-beta.1
LLVM version: 19.1.6

Anything else?

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @repnop

        Issue actions

          `const`s that depend on other constants which fail to evaluate create difficult to read error messages due to `notes:` output · Issue #135259 · rust-lang/rust