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 ICE in diagnostic_hir_wf_check #87524

Merged
merged 1 commit into from
Jul 28, 2021
Merged

Conversation

FabianWolff
Copy link
Contributor

Fixes #87495. The documentation for ObligationCauseCode::WellFormed says that

it is always correct [...] to specify WellFormed(None)

instead of WellFormed(Some(...)), which seems to have caused the issue here, as diagnostic_hir_wf_check does not expect to be called with an associated constant and will ICE:

hir::Node::TraitItem(item) => match item.kind {
hir::TraitItemKind::Type(_, ty) => ty,
ref item => bug!("Unexpected TraitItem {:?}", item),
},

Therefore, I have changed check_associated_item() to pass a WellFormed(None) for associated constants.

r? @Aaron1011

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 27, 2021
@Aaron1011
Copy link
Member

@FabianWolff: I think a better solution would be to add support for hir::TraitItemKind::Const. We can perform well-formed checking on the type of the const by using the first tuple field of TraitItemKind::Const (the &'hir Ty<'hir> field).

@FabianWolff
Copy link
Contributor Author

@FabianWolff: I think a better solution would be to add support for hir::TraitItemKind::Const. We can perform well-formed checking on the type of the const by using the first tuple field of TraitItemKind::Const (the &'hir Ty<'hir> field).

Fixed. Thanks for the quick review!

@Aaron1011 Aaron1011 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 27, 2021
@Aaron1011
Copy link
Member

Thanks!
@bors r+

@bors
Copy link
Contributor

bors commented Jul 28, 2021

📌 Commit dbd0fd2 has been approved by Aaron1011

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 28, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jul 28, 2021
Fix ICE in `diagnostic_hir_wf_check`

Fixes rust-lang#87495. The [documentation for `ObligationCauseCode::WellFormed`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_infer/traits/enum.ObligationCauseCode.html#variant.WellFormed) says that

> it is always correct [...] to specify `WellFormed(None)`

instead of `WellFormed(Some(...))`, which seems to have caused the issue here, as `diagnostic_hir_wf_check` does not expect to be called with an associated constant and will ICE:

https://github.com/rust-lang/rust/blob/fd853c00e255559255885aadff9e93a1760c8728/compiler/rustc_typeck/src/hir_wf_check.rs#L131-L134

Therefore, I have changed `check_associated_item()` to pass a `WellFormed(None)` for associated constants.

r? `@Aaron1011`
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 28, 2021
Rollup of 10 pull requests

Successful merges:

 - rust-lang#87315 (Add docs for raw-dylib to unstable book)
 - rust-lang#87330 (Use hashbrown's `extend_reserve()` in `HashMap`)
 - rust-lang#87443 (Don't treat git repos as non-existent when `ignore_git` is set)
 - rust-lang#87453 (Suggest removing unnecessary &mut as help message)
 - rust-lang#87500 (Document math behind MIN/MAX consts on integers)
 - rust-lang#87501 (Remove min_type_alias_impl_trait in favor of type_alias_impl_trait)
 - rust-lang#87507 (SGX mutex is *not* moveable)
 - rust-lang#87513 (bootstrap.py: change `git log` option to indicate desired behavior)
 - rust-lang#87523 (Stop creating a reference then immediately dereferencing it.)
 - rust-lang#87524 (Fix ICE in `diagnostic_hir_wf_check`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 7985e4c into rust-lang:master Jul 28, 2021
@rustbot rustbot added this to the 1.56.0 milestone Jul 28, 2021
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICE: compiler/rustc_typeck/src/hir_wf_check.rs:133:29: Unexpected TraitItem
5 participants