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

Use correct substs in enum discriminant cast #98429

Merged
merged 5 commits into from
Jun 25, 2022

Conversation

b-naber
Copy link
Contributor

@b-naber b-naber commented Jun 23, 2022

Fixes #97634

r? @lcnr

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 23, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 23, 2022
@rust-log-analyzer

This comment has been minimized.

@b-naber b-naber force-pushed the use-correct-substs-discriminant-cast branch from 9ce21ee to 2e3221a Compare June 24, 2022 09:11
Comment on lines 234 to 237
Some(did) => {
// in case we are offsetting from a computed discriminant
// and not the beginning of discriminants (which is always `0`)

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Some(did) => {
// in case we are offsetting from a computed discriminant
// and not the beginning of discriminants (which is always `0`)
// in case we are offsetting from a computed discriminant
// and not the beginning of discriminants (which is always `0`)
Some(did) => {

};

let res = self.typeck_results().qpath_res(qpath, source.hir_id);
let (discr_did, discr_offset, discr_ty, substs) = {
Copy link
Contributor

Choose a reason for hiding this comment

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

why use that let here instead of keeping the original variables in scope

compiler/rustc_mir_build/src/thir/cx/expr.rs Show resolved Hide resolved
Comment on lines 207 to 211
DefKind::Ctor(CtorOf::Variant, CtorKind::Const),
variant_ctor_id,
) = res else {
return ExprKind::Cast { source: self.mirror_expr(source)};
};
Copy link
Contributor

@lcnr lcnr Jun 24, 2022

Choose a reason for hiding this comment

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

wrong indentation, rustfmt doesn't work for let else for now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hm did call ./x.py fmt this time

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, but rustfmt does not work, you have to manually fix indentation for now

Comment on lines 205 to 207
let ty::Adt(adt_def, substs) = ty.kind() else {
return ExprKind::Cast { source: self.mirror_expr(source)};
};
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean the formatting here? As I said this is what x.py formats this to. We also don't get any tidy check failure.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes,

As I said this is what x.py formats this to. We also don't get any tidy check failure.

which is happening because rustfmt ignores let else for now. It just keeps the formatting from the user. You can change the formatting of let else to pretty much whatever you want and ./x.py fmt won't change it or complain

@@ -0,0 +1,10 @@
//build-pass
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
//build-pass
// build-pass

@lcnr
Copy link
Contributor

lcnr commented Jun 24, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Jun 24, 2022

📌 Commit bf48b62 has been approved by lcnr

@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 Jun 24, 2022
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Jun 25, 2022
…nant-cast, r=lcnr

Use correct substs in enum discriminant cast

Fixes rust-lang#97634

r? `@lcnr`
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jun 25, 2022
…nant-cast, r=lcnr

Use correct substs in enum discriminant cast

Fixes rust-lang#97634

r? ``@lcnr``
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 25, 2022
…askrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#96412 (Windows: Iterative `remove_dir_all`)
 - rust-lang#98126 (Mitigate MMIO stale data vulnerability)
 - rust-lang#98149 (Set relocation_model to Pic on emscripten target)
 - rust-lang#98194 (Leak pthread_{mutex,rwlock}_t if it's dropped while locked.)
 - rust-lang#98298 (Point to type parameter definition when not finding variant, method and associated item)
 - rust-lang#98311 (Reverse folder hierarchy)
 - rust-lang#98401 (Add tracking issues to `--extern` option docs.)
 - rust-lang#98429 (Use correct substs in enum discriminant cast)
 - rust-lang#98431 (Suggest defining variable as mutable on `&mut _` type mismatch in pats)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit ea07b96 into rust-lang:master Jun 25, 2022
@rustbot rustbot added this to the 1.64.0 milestone Jun 25, 2022
@b-naber b-naber deleted the use-correct-substs-discriminant-cast branch August 26, 2022 20:37
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.

Casting an enum with const generic causes compiler panic
6 participants