Skip to content

rustdoc panics while documenting panicking associated constant #131625

Open
@joshlf

Description

@joshlf
Contributor

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)

Activity

added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Oct 12, 2024
added
T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
C-bugCategory: This is a bug.
on Oct 12, 2024
added
C-discussionCategory: Discussion or questions that doesn't represent real issues.
C-bugCategory: This is a bug.
and removed
C-bugCategory: This is a bug.
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
C-discussionCategory: Discussion or questions that doesn't represent real issues.
on Oct 14, 2024
self-assigned this
on Oct 15, 2024
added
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)
on Oct 15, 2024
fmease

fmease commented on Oct 15, 2024

@fmease
Member

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.

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

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

      Participants

      @joshlf@fmease@lolbinarycat@jieyouxu@rustbot

      Issue actions

        rustdoc panics while documenting panicking associated constant · Issue #131625 · rust-lang/rust