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

[missing_fields_in_debug]: don't ICE when self type is a generic param #10897

Merged
merged 1 commit into from
Jun 7, 2023

Conversation

y21
Copy link
Member

@y21 y21 commented Jun 5, 2023

Fixes #10887

This PR fixes an ICE that happens when the implementor (self type) of a Debug impl is a generic parameter.
The lint calls TyCtxt::type_of with that self type, which ICEs when called with generic parameters, so this just adds a quick check before getting there to ignore them.

That can only happen inside of core itself (afaik) because the orphan rules forbid defining an impl such as impl<T> Debug for T outside of core, so I'm not sure how to add a test for this.
It seems like this impl in particular caused this: https://doc.rust-lang.org/stable/std/fmt/trait.Debug.html#impl-Debug-for-F

changelog: [missing_fields_in_debug]: don't ICE on blanket Debug impl in core

@rustbot
Copy link
Collaborator

rustbot commented Jun 5, 2023

r? @dswij

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jun 5, 2023
@y21 y21 changed the title don't call type_of on generic params [missing_fields_in_debug]: don't ICE when self type is a generic param Jun 5, 2023
@y21
Copy link
Member Author

y21 commented Jun 5, 2023

r? @Alexendoo
assigning you because you reviewed my PR that added this lint, that might help for reviewing this 😅

@rustbot rustbot assigned Alexendoo and unassigned dswij Jun 5, 2023
@Alexendoo
Copy link
Member

Thanks! Interesting case

@bors r+

@bors
Copy link
Contributor

bors commented Jun 7, 2023

📌 Commit 1cf95a9 has been approved by Alexendoo

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Jun 7, 2023

⌛ Testing commit 1cf95a9 with merge 2360f80...

@bors
Copy link
Contributor

bors commented Jun 7, 2023

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: Alexendoo
Pushing 2360f80 to master...

@bors bors merged commit 2360f80 into rust-lang:master Jun 7, 2023
bors added a commit that referenced this pull request Jul 2, 2023
[`missing_fields_in_debug`]: make sure self type is an adt

Fixes #11063, another ICE that can only happen in core.

This lint needs the `DefId` of the implementor to get its fields, but that ICEs if the implementor does not have a `DefId` (as is the case with primitive types, e.g. `impl Debug for bool`), which is where this ICE comes from.

This PR changes the check I added in #10897 to be more... robust against `Debug` implementations we don't want to lint.
Instead of just checking if the self type is a type parameter and "special casing" one specific case we don't want to lint, we should probably rather just check that the self type is either a struct, an enum or a union and only then continue.
That prevents weird edge cases like this one that can only happen in core.

Again, I don't know if it's even possible to add a test case for this since one cannot implement `Debug` for primitive types outside of the crate that defined `Debug` (core).
I did make sure that this PR no longer ICEs on `impl<T> Debug for T` and `impl Debug for bool`.
Maybe writing such a test is possible with `#![no_core]` and then re-defining the `Debug` trait or something like that...?

changelog: [`missing_fields_in_debug`]: make sure self type is an adt (fixes an ICE in core)

r? `@Alexendoo` (reviewed the last PRs for this lint)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
5 participants