Skip to content
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

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

Open
repnop opened this issue Jan 8, 2025 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@repnop
Copy link
Contributor

repnop commented Jan 8, 2025

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

@repnop repnop added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 8, 2025
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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

1 participant