Open
Description
I have the following code:
pub trait Foo {
const BAR: ();
}
impl Foo for () {
const BAR: () = panic!("intentional PME");
}
While this is contrived, this pattern is used in real codebases to take advantage of post-monomorphization errors (PME's), for example here.
When running cargo doc
, rustdoc seems to try to evaluate the constant, and crashes:
$ cargo doc
Documenting tmp v0.1.0 (.../tmp)
error[E0080]: evaluation of constant value failed
--> src/lib.rs:6:21
|
6 | const BAR: () = panic!("intentional PME");
| ^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'intentional PME', src/lib.rs:6:21
|
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
Miscellaneous
$ cargo version
cargo 1.78.0 (54d8815d0 2024-03-26)
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
fmease commentedon Oct 15, 2024
Right, I didn't think about this when working on #95316 (which I presume to be the culprit) in 2022. Since that PR, rustdoc tries to evaluate public associated constants (via
const_eval_poly
) and display the result.