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

rustdoc panics while documenting panicking associated constant #131625

Open
joshlf opened this issue Oct 12, 2024 · 1 comment
Open

rustdoc panics while documenting panicking associated constant #131625

joshlf opened this issue Oct 12, 2024 · 1 comment
Assignees
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@joshlf
Copy link
Contributor

joshlf commented Oct 12, 2024

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)
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 12, 2024
@jieyouxu jieyouxu added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Oct 12, 2024
@lolbinarycat lolbinarycat added C-discussion Category: Discussion or questions that doesn't represent real issues. C-bug Category: This is a bug. A-monomorphization Area: Monomorphization and removed C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. C-discussion Category: Discussion or questions that doesn't represent real issues. labels Oct 14, 2024
@fmease fmease removed the A-monomorphization Area: Monomorphization label Oct 15, 2024
@fmease fmease self-assigned this Oct 15, 2024
@fmease fmease added the A-const-eval Area: Constant evaluation (MIR interpretation) label Oct 15, 2024
@fmease
Copy link
Member

fmease commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants