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

Fix panic when compiling Rocket. #121427

Merged
merged 2 commits into from
Feb 22, 2024
Merged

Fix panic when compiling Rocket. #121427

merged 2 commits into from
Feb 22, 2024

Conversation

nnethercote
Copy link
Contributor

This panic was reported here.

r? @oli-obk

`Rustc::emit_diagnostic` reconstructs a diagnostic passed in from the
macro machinery. Currently it uses the type `DiagnosticBuilder<'_,
ErrorGuaranteed>`, which is incorrect, because the diagnostic might be a
warning. And if it is a warning, because of the `ErrorGuaranteed` we end
up calling into `emit_producing_error_guaranteed` and the assertion
within that function (correctly) fails because the level is not an error
level.

The fix is simple: change the type to `DiagnosticBuilder<'_, ()>`. Using
`()` works no matter what the diagnostic level is, and we don't need an
`ErrorGuaranteed` here.

The panic was reported in rust-lang#120576.
PR rust-lang#119097 made the decision to make all `IntoDiagnostic` impls generic,
because this allowed a bunch of nice cleanups. But four hand-written
impls were unintentionally overlooked. This commit makes them generic.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 22, 2024
@nnethercote
Copy link
Contributor Author

I was able to reproduce the panic when building Rocket like so:

git clone https://github.com/rwf2/Rocket
cd Rocket
sudo apt install
libmysqlclient-dev
rustup default nightly
scripts/test.sh

Unfortunately, I wasn't able to test the fix. I tried using rustup toolchain link stage2 ~/dev/rust3/build/host/stage2 and rustup default stage2 to make my local build the default compiler, but I couldn't reproduce the panic with that configuration. There must be some difference between that configuration and using nightly as the default.

I also haven't written a test, because I don't understand the proc macro machinery enough to do so.

So I have only tested this fix in my head :) But I have high confidence that it will work, because the panic message and the stack trace make it very clear what the problem is, conceptually.

@@ -510,7 +510,7 @@ impl server::FreeFunctions for Rustc<'_, '_> {

fn emit_diagnostic(&mut self, diagnostic: Diagnostic<Self::Span>) {
let message = rustc_errors::DiagnosticMessage::from(diagnostic.message);
let mut diag: DiagnosticBuilder<'_, rustc_errors::ErrorGuaranteed> =
let mut diag: DiagnosticBuilder<'_, ()> =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see why this fixed the issue, but why are the other changes necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean in the second commit? While I was looking at this I did an audit of all the DiagnosticBuilder::new calls to make sure there weren't any other problems. That's when I noticed the non-generic IntoDiagnostic impls, and since they are kind of related I decided to do them in the same PR (albeit in a different commit).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of them are explicitly setting error codes. It doesn't really make sense to allow them to be anything but an error. I guess that's a limitation of the IntoDiagnostic API

I don't think they should be made generic if they are always meant to be errors

Copy link
Contributor Author

@nnethercote nnethercote Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#119097 had a lot of stuff about this, see this comment for a summary. In short, all derived IntoDiagnostic impls have to be generic. For consistency, we decided that all hand-written ones should be too (plus it allowed some important related simplifications). That way, for all diagnostics, its the emission site that dictates the level. But four of them were overlooked.

Copy link
Contributor

@oli-obk oli-obk Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, we should probably create a rustc lint for that then

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the IntoDiagnostic doc comment should explain that impls should always be generic, and why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added that to my todo list, I'll get to it next week.

@oli-obk
Copy link
Contributor

oli-obk commented Feb 22, 2024

@bora r+

@nnethercote
Copy link
Contributor Author

@bora r+

@bors r=oli-obk

@bors
Copy link
Contributor

bors commented Feb 22, 2024

📌 Commit 02423a5 has been approved by oli-obk

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 22, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 22, 2024
Fix panic when compiling `Rocket`.

This panic was reported [here](rust-lang#120576 (comment)).

r? `@oli-obk`
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 22, 2024
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#120598 (No need to `validate_alias_bound_self_from_param_env` in `assemble_alias_bound_candidates`)
 - rust-lang#121386 (test that we do not support higher-ranked regions in opaque type inference)
 - rust-lang#121393 (match lowering: Introduce a `TestCase` enum to replace most matching on `PatKind`)
 - rust-lang#121401 (Fix typo in serialized.rs)
 - rust-lang#121427 (Fix panic when compiling `Rocket`.)
 - rust-lang#121439 (Fix typo in metadata.rs doc comment)
 - rust-lang#121441 (`DefId`  to `LocalDefId`)
 - rust-lang#121452 (Add new maintainers to nto-qnx.md)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 01ec4eb into rust-lang:master Feb 22, 2024
11 checks passed
@rustbot rustbot added this to the 1.78.0 milestone Feb 22, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Feb 22, 2024
Rollup merge of rust-lang#121427 - nnethercote:fix-Rocket, r=oli-obk

Fix panic when compiling `Rocket`.

This panic was reported [here](rust-lang#120576 (comment)).

r? ``@oli-obk``
@nnethercote nnethercote deleted the fix-Rocket branch February 22, 2024 21:09
@nnethercote
Copy link
Contributor Author

@SergioBenitez: Hopefully this fixes the problem and Rocket's build with Nightly will start working again some time in the next 24-48 hours, once this PR gets integrated! Please let us know if it works or doesn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants