Skip to content

Fix corner case in expr_kind #19370

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

Closed
wants to merge 1 commit into from
Closed

Conversation

Aatch
Copy link
Contributor

@Aatch Aatch commented Nov 28, 2014

It looks like the expression isn't getting an entry in the node_types map, meaning that when it checks the type of the expression in expr_kind to see if it should use RvalueDatumExpr or RvalueDpsExpr, it cant find the type and panics.

As far as I can tell, this only comes up in this case shown in issue #19337, a unit struct on the left-hand side of an assignment expression. The only reason this happens is because a DefStruct is the only case where expr_kind checks the type of the expression, so falling back to RvalueDpsExpr when no type is found should be fine.

Fixes #19337

Assume that an ExprPath that resolves to a DefStruct, but doesn't
have a type, is a unit struct constructor expression and return the kind
`RvalueDpsExpr`
@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nikomatsakis (or someone else) soon.

@emberian
Copy link
Member

Needs a test (the one from the issue ought to be fine)

@ghost
Copy link

ghost commented Nov 28, 2014

Will probably also fix #13407.

@Aatch
Copy link
Contributor Author

Aatch commented Dec 3, 2014

@nikomatsakis hmm, I wasn't entirely comfortable with the fix myself, further investigation shows that this actually compiles:

struct Foo;

fn foo() {
  *&mut Foo = Foo;
}

Doesn't seem like it should, so I'll try to figure out a better fix that covers that case as well.

@Aatch
Copy link
Contributor Author

Aatch commented Dec 3, 2014

Well I figured out why it's not in the table. That table is only updated at the end of the function. Until then, all the types are recorded in the function context, which isn't available to expr_kind.

As far as I can tell, the strange example I posted above is just a weird part of the language. It accepts it because there's no reason not to. It doesn't actually do anything (well, it assigns to a temporary, not exactly broken code...).

I've done some refactoring instead of this change though, now that I've looked at the issue properly. I'll open a new PR for it when I'm done.

@Aatch Aatch closed this Dec 3, 2014
lnicola pushed a commit to lnicola/rust that referenced this pull request Apr 28, 2025
…result

refactor: Simplify by removing ? operator
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.

ICE Struct += Struct
4 participants