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

[MIR] Cannot explicitly set discriminant #35186

Closed
scottcarr opened this issue Aug 2, 2016 · 5 comments
Closed

[MIR] Cannot explicitly set discriminant #35186

scottcarr opened this issue Aug 2, 2016 · 5 comments
Labels
A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html

Comments

@scottcarr
Copy link
Contributor

scottcarr commented Aug 2, 2016

In #35168, we might like to deaggregate enums like:

x = Foo::Bar{a: 0, b: 0};

Into:

(x as Foo::Bar).0 = 0;
(x as Foo:Bar).1 = 0;

The problem (as far I know) is that the deaggregated version never sets the discrimnant.

I had some code that at least did the casting:

// if we handled enums:
let lhs_cast = if adt_def.variants.len() > 1 {
     Lvalue::Projection(Box::new(LvalueProjection {
         base: ai.lhs.clone(),
         elem: ProjectionElem::Downcast(ai.adt_def, ai.variant),
     }))
 } else {
     lhs_cast
};
@nagisa
Copy link
Member

nagisa commented Aug 2, 2016

I have long wanted to add a Discriminant lvalue projection. Might be a time to do it.

@nikomatsakis
Copy link
Contributor

Could also use it to rewrite Switch vs SwitchInt, which I think @nagisa was in favor of :)

@bstrie bstrie added the A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html label Aug 3, 2016
Manishearth added a commit to Manishearth/rust that referenced this issue Aug 13, 2016
…akis

[MIR] Add explicit SetDiscriminant StatementKind for deaggregating enums

cc rust-lang#35186

To deaggregate enums, we need to be able to explicitly set the discriminant.  This PR implements a new StatementKind that does that.

I think some of the places that have `panics!` now could maybe do something smarter.
bors added a commit that referenced this issue Aug 13, 2016
[MIR] Add explicit SetDiscriminant StatementKind for deaggregating enums

cc #35186

To deaggregate enums, we need to be able to explicitly set the discriminant.  This PR implements a new StatementKind that does that.

I think some of the places that have `panics!` now could maybe do something smarter.
@bluss
Copy link
Member

bluss commented Dec 13, 2016

Is this fixed now?

@nagisa
Copy link
Member

nagisa commented Dec 13, 2016

The original issue is fixed, yes.

@bluss
Copy link
Member

bluss commented Dec 13, 2016

Closed as fixed by #35348

@bluss bluss closed this as completed Dec 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html
Projects
None yet
Development

No branches or pull requests

5 participants