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 and report a human readable error #55071

Merged
merged 5 commits into from
Oct 19, 2018

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Oct 14, 2018

fixes #55063

r? @RalfJung

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 14, 2018
@@ -163,6 +163,10 @@ fn check_rvalue(
_ => check_operand(tcx, mir, operand, span),
}
}
Rvalue::Cast(_, _, _) => Err((
span,
"only int casts are allowed in const fn".into(),
Copy link
Member

Choose a reason for hiding this comment

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

"int casts" doesn't seem like the right description here, not all Misc casts involved integers -- do they?

There are not so many kinds of casts, so depending on that you could make it say "unsizing casts" or "function pointer casts".

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, can you add a test case for this code branch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if I can, but I'll try

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't let it be a blocker, but it'd be nice to have error cases so that later we can give them all their own error code and a good extended description.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I managed to get to the unsizing errors. Everything else errors out early due to fn pointers not being allowed

@rust-highfive

This comment has been minimized.

@estebank
Copy link
Contributor

lgtm++

)),
Rvalue::Cast(CastKind::ClosureFnPointer, _, _) => Err((
span,
"closures are not allowed in const fn".into(),
Copy link
Member

Choose a reason for hiding this comment

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

This is not just having a closure, but then casting it to fn() (I think). The message should contain the word "cast" one way or another.

I would have just grouped it with the other two fn ptr casts.

@RalfJung
Copy link
Member

r=me with that nit fixed.

@oli-obk
Copy link
Contributor Author

oli-obk commented Oct 17, 2018

@bors r=RalfJung

@bors
Copy link
Contributor

bors commented Oct 17, 2018

📌 Commit 38f3ad4 has been approved by RalfJung

@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 Oct 17, 2018
kennytm added a commit to kennytm/rust that referenced this pull request Oct 18, 2018
kennytm added a commit to kennytm/rust that referenced this pull request Oct 19, 2018
bors added a commit that referenced this pull request Oct 19, 2018
Rollup of 7 pull requests

Successful merges:

 - #54300 (Updated RELEASES.md for 1.30.0)
 - #55013 ([NLL] Propagate bounds from generators)
 - #55071 (Fix ICE and report a human readable error)
 - #55144 (Cleanup resolve)
 - #55166 (Don't warn about parentheses on `match (return)`)
 - #55169 (Add a `copysign` function to f32 and f64)
 - #55178 (Stabilize slice::chunks_exact(), chunks_exact_mut(), rchunks(), rchunks_mut(), rchunks_exact(), rchunks_exact_mut())
@bors bors merged commit 38f3ad4 into rust-lang:master Oct 19, 2018
@oli-obk oli-obk deleted the const_cast_🍨 branch June 15, 2020 15:29
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 when returning Vec from const fn
5 participants