Skip to content

rustdoc panics while documenting panicking associated constant #131625

Open
@joshlf

Description

@joshlf

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

A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.T-rustdocRelevant to the rustdoc 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

Issue actions