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 various issues with control-flow statements inside anonymous constants #51967

Merged
merged 9 commits into from
Jul 5, 2018

Conversation

varkor
Copy link
Member

@varkor varkor commented Jul 1, 2018

Fixes #51761.
Fixes #51963 (and the host of other reported issues there).
(Might be easiest to review per commit, as they should be standalone.)

r? @estebank

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 1, 2018
@rust-highfive

This comment has been minimized.

@rust-highfive

This comment has been minimized.

Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

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

Minor nitpicks, after that r=me.

@@ -1152,7 +1156,11 @@ fn lit_to_const<'a, 'tcx>(lit: &'tcx ast::LitKind,
ty::TyInt(other) => Int::Signed(other),
ty::TyUint(UintTy::Usize) => Int::Unsigned(tcx.sess.target.usize_ty),
ty::TyUint(other) => Int::Unsigned(other),
_ => bug!(),
ty::TyError => {
// Avoid ICE
Copy link
Contributor

Choose a reason for hiding this comment

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

Add Issue Number

@@ -1123,7 +1127,7 @@ fn lit_to_const<'a, 'tcx>(lit: &'tcx ast::LitKind,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
ty: Ty<'tcx>,
neg: bool)
-> Result<&'tcx ty::Const<'tcx>, ()> {
-> Result<&'tcx ty::Const<'tcx>, bool> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use an enum instead of a boolean? That way you can communicate the meaning of the different states, not only in the method signature, but also at the return point and when being checked.

bug!("LayoutDetails::compute: unexpected type `{}`", ty)
}
ty::TyError => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Merge with the ty::TyParam(_) branch above, as they return the same thing.

// Avoid ICE
return Err(false);
}
_ => bug!("{:?}", ty.sty),
Copy link
Contributor

Choose a reason for hiding this comment

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

Expand the bug description a little with something like "literal integer with bad type".

LL | [(); return |ice| {}];
| ^^^^^^^^^^^^^^^

error[E0572]: return statement outside of function body
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really like the wording here, but that is the current wording, so don't bother coming up with better wording if you can't think of one immediately (I can't).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I thought the same thing. It's hard to think of something snappy. Perhaps simply:

`return` found outside a function

?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe "outside of function scope"? It'd be good to also expand the diagnostic to include an explanation that it is in a const scope, presenting a terse explanation that whatever is in such a scope will be evaluated at compile time, as well as a link to the documentation (https://doc.rust-lang.org/book/second-edition/ch03-01-variables-and-mutability.html#differences-between-variables-and-constants seems like the appropriate place, but it doesn't go into detail about this case).

Regardless, out of scope for this PR.

@varkor varkor force-pushed the const-body-break-continue branch from 1e28faa to 9132e85 Compare July 2, 2018 01:12
@estebank
Copy link
Contributor

estebank commented Jul 2, 2018

@bors r+

@bors
Copy link
Contributor

bors commented Jul 2, 2018

📌 Commit 9132e8510337bdee76562e6e594016ac9e530c12 has been approved by estebank

@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 Jul 2, 2018
@bors
Copy link
Contributor

bors commented Jul 2, 2018

☔ The latest upstream changes (presumably #51321) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 2, 2018
@varkor varkor force-pushed the const-body-break-continue branch from 9132e85 to adf4ef7 Compare July 2, 2018 18:44
@varkor
Copy link
Member Author

varkor commented Jul 2, 2018

I'm just going to keep trying to talk to @bors until they listen to me...
@bors r=estebank

@bors
Copy link
Contributor

bors commented Jul 2, 2018

@varkor: 🔑 Insufficient privileges: Not in reviewers

@estebank
Copy link
Contributor

estebank commented Jul 2, 2018

@bors r+

@bors
Copy link
Contributor

bors commented Jul 2, 2018

📌 Commit adf4ef7 has been approved by estebank

@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 2, 2018
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request Jul 2, 2018
…=estebank

Fix various issues with control-flow statements inside anonymous constants

Fixes rust-lang#51761.
Fixes rust-lang#51963 (and the host of other reported issues there).
(Might be easiest to review per commit, as they should be standalone.)

r? @estebank
@rust-highfive
Copy link
Collaborator

The job mingw-check of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[00:03:50]  Downloading lazycell v0.6.0
[00:03:50] error: unable to get packages from source
[00:03:50] 
[00:03:50] Caused by:
[00:03:50]   [18] Transferred a partial file (transfer closed with outstanding read data remaining)
[00:03:50] thread 'main' panicked at 'command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "metadata" "--format-version" "1" "--features" "panic-unwind jemalloc backtrace" "--manifest-path" "/checkout/src/libstd/Cargo.toml"
[00:03:50] expected success, got: exit code: 101', build_helper/lib.rs:122:9
[00:03:50] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap check
[00:03:50] Build completed unsuccessfully in 0:02:18
travis_time:end:1444d154:start=1530557188789423760,finish=1530557419939705166,duration=231150281406

---
travis_time:end:1283bc83:start=1530557420286968071,finish=1530557420298180853,duration=11212782
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:051f0388
$ head -30 ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
head: cannot open ‘./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers��� for reading: No such file or directory
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:2f1619bf
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@varkor
Copy link
Member Author

varkor commented Jul 2, 2018

Looks like a spurious failure to me.

@estebank
Copy link
Contributor

estebank commented Jul 2, 2018

@bors retry

@bors
Copy link
Contributor

bors commented Jul 5, 2018

⌛ Testing commit adf4ef7 with merge 69b9e1e...

bors added a commit that referenced this pull request Jul 5, 2018
Fix various issues with control-flow statements inside anonymous constants

Fixes #51761.
Fixes #51963 (and the host of other reported issues there).
(Might be easiest to review per commit, as they should be standalone.)

r? @estebank
@bors
Copy link
Contributor

bors commented Jul 5, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: estebank
Pushing 69b9e1e to master...

@bors bors merged commit adf4ef7 into rust-lang:master Jul 5, 2018
@varkor varkor deleted the const-body-break-continue branch July 6, 2018 07:07
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.

4 participants