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: Fix panics on GATs involving const generics #13021

Merged
merged 2 commits into from
Aug 22, 2022

Conversation

N3xed
Copy link
Contributor

@N3xed N3xed commented Aug 14, 2022

This workaround avoids constant crashing of rust analyzer when using GATs with const generics,
even when the const generics are only on the impl block.

The workaround treats GATs as non-existing if either itself or the parent has const generics and
removes relevant panicking code-paths.

Fixes #11989, fixes #12193

crates/hir-ty/src/consteval.rs Outdated Show resolved Hide resolved
crates/hir-ty/src/utils.rs Outdated Show resolved Hide resolved
let idx = generics.param_idx(param_id.into()).expect("matching generics");
let idx = match generics.param_idx(param_id.into()) {
// FIXME: never crash if this involves const generic associated types
None if generics.is_gat => {
Copy link
Member

Choose a reason for hiding this comment

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

let's just do a never!() check here instead of checking is_gat

Copy link
Contributor Author

@N3xed N3xed Aug 16, 2022

Choose a reason for hiding this comment

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

This will make the test fail though, is that okay?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I would be fine with that. It's a bit unfortunate that we can't test that it doesn't crash, but I'd rather have the crashing test as a reminder that it's still broken.

Copy link
Contributor Author

@N3xed N3xed Aug 16, 2022

Choose a reason for hiding this comment

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

So to prevent the test from failing I used tracing::error! and added a FIXME explaining why it doesn't use never!.
Oops, didn't see your comment in time.
I guess running cargo test --release -- -q would make the test succeed.

This workaround avoids constant crashing of rust analyzer when using GATs with const generics,
even when the const generics are only on the `impl` block.

The workaround treats GATs as non-existing if either itself or the parent has const generics and
removes relevant panicking code-paths.
@flodiebold
Copy link
Member

flodiebold commented Aug 21, 2022

LGTM, but the test of course fails 😅 I'd mark it as ignored or should_panic, but we lint against both of those 😒

@bors delegate+

@bors
Copy link
Contributor

bors commented Aug 21, 2022

✌️ @N3xed can now approve this pull request

@N3xed
Copy link
Contributor Author

N3xed commented Aug 21, 2022

Hopefully, the CI failing isn't a big issue. Unfortunately, I'm not familiar enough to tackle the underlying problem since I'm very new to the rust analyzer code base, and just implementing this workaround took me quite a while.

Nonetheless thanks for the review.
@bors r+

@bors
Copy link
Contributor

bors commented Aug 21, 2022

📌 Commit ad7a1ed has been approved by N3xed

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Aug 21, 2022

⌛ Testing commit ad7a1ed with merge 1b8e1c6...

bors added a commit that referenced this pull request Aug 21, 2022
fix: Fix panics on GATs involving const generics

This workaround avoids constant crashing of rust analyzer when using GATs with const generics,
even when the const generics are only on the `impl` block.

The workaround treats GATs as non-existing if either itself or the parent has const generics and
removes relevant panicking code-paths.
~~Additionally, I've added the `is_gat` field to `utils::Generics` that determines whether missing
generics params crashes rust analyzer. Another solution would have been to remove all panics
from the relevant code path regardless of whether the generics are on a GAT, but this could
change behavior outside of GATs.~~

Fixes #11989, fixes #12193
@bors
Copy link
Contributor

bors commented Aug 21, 2022

💔 Test failed - checks-actions

// in debug mode, we catch the unwind and expect that it panicked. See the
// [`crate::utils::generics`] function for more information.
cov_mark::check!(ignore_gats);
std::panic::catch_unwind(|| {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@flodiebold So, to make the test succeed I just catch the unwind here right now, which is pretty much the same as #[shoud_panic]. Or can we merge without passing tests?

@flodiebold
Copy link
Member

TBH I think we should probably just get rid of the should_panic lint. Having tests for cases that currently panic can be genuinely useful, like here. But for now let's merge this.

@bors r+

@bors
Copy link
Contributor

bors commented Aug 22, 2022

📌 Commit ac8cb8c has been approved by flodiebold

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Aug 22, 2022

⌛ Testing commit ac8cb8c with merge fdc28b4...

@bors
Copy link
Contributor

bors commented Aug 22, 2022

☀️ Test successful - checks-actions
Approved by: flodiebold
Pushing fdc28b4 to master...

@bors bors merged commit fdc28b4 into rust-lang:master Aug 22, 2022
@N3xed N3xed deleted the fix-gat-panics branch August 22, 2022 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GAT + const generics crash v2 textDocument/semanticTokens/etc. GAT failure on latest pre-release
3 participants