Skip to content

Change untagged_unions to not allow union fields with drop - #62330

Merged
bors merged 20 commits into
rust-lang:masterfrom
SimonSapin:no-drop-in-union-fields
Oct 22, 2019
Merged

Change untagged_unions to not allow union fields with drop#62330
bors merged 20 commits into
rust-lang:masterfrom
SimonSapin:no-drop-in-union-fields

Conversation

@SimonSapin

@SimonSapinSimonSapin commented Jul 3, 2019

Copy link
Copy Markdown
Contributor

This is a rebase of #56440, massaged to solve merge conflicts and make the test suite pass.

Change untagged_unions to not allow union fields with drop

Union fields may now never have a type with attached destructor. This for example allows unions to use arbitrary field types only by wrapping them in ManuallyDrop (or similar).

The stable rule remains, that union fields must be Copy. We use the new rule for the untagged_union feature.

Tracking issue: #55149

@SimonSapinSimonSapin added A-destructors Area: Destructors (`Drop`, …) B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 3, 2019
@rust-highfive

Copy link
Copy Markdown
Contributor

Some changes occurred in diagnostic error codes

cc @GuillaumeGomez

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @eddyb

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 3, 2019
Comment threadsrc/librustc_typeck/check/mod.rs Outdated
Comment threadsrc/librustc_typeck/check/mod.rs Outdated
Comment threadsrc/librustc_typeck/check/mod.rs Outdated
Comment threadsrc/librustc_typeck/error_codes.rs Outdated
Comment threadsrc/test/run-pass/drop/dynamic-drop.rs Outdated
Comment threadsrc/test/run-pass/union/union-nodrop.rs Outdated
Comment threadsrc/test/run-pass/union/union-nodrop.rs Outdated
@Centril

Copy link
Copy Markdown
Contributor

cc tracking issue: #55149

@bors

bors commented Jul 5, 2019

Copy link
Copy Markdown
Collaborator

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

@SimonSapin
SimonSapinforce-pushed the no-drop-in-union-fields branch from 81949b0 to 0951ccaCompareJuly 5, 2019 22:04
@eddyb

Copy link
Copy Markdown
Contributor

r? @RalfJung

@rust-highfiverust-highfive assigned RalfJung and unassigned eddybJul 11, 2019
Comment threadsrc/libcore/slice/rotate.rs Outdated
Comment threadsrc/librustc_typeck/check/mod.rs Outdated
Comment threadsrc/librustc_typeck/check/mod.rs Outdated
Comment threadsrc/libstd/panicking.rs Outdated
Comment threadsrc/test/run-pass/union/union-generic.rs Outdated
Comment threadsrc/test/ui/union/union-with-drop-fields.stderr Outdated
Comment threadsrc/librustc_typeck/check/mod.rs Outdated
@RalfJungRalfJung 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-review Status: Awaiting review from the assignee but also interested parties. labels Jul 24, 2019
@bors

bors commented Jul 27, 2019

Copy link
Copy Markdown
Collaborator

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

@JohnTitor

Copy link
Copy Markdown
Member

Ping from triage: @SimonSapin, any updates on this? you should also resolve conflicts.

@SimonSapin
SimonSapinforce-pushed the no-drop-in-union-fields branch from 0951cca to d2a4d57CompareAugust 5, 2019 16:00
@SimonSapin

Copy link
Copy Markdown
ContributorAuthor

Rebased, but I’m not the original author of this code so I feel I’m not able to answer some of the review comments. I’d appreciate if someone more familiar with compiler internals is willing to take over.

@rust-highfive

Copy link
Copy Markdown
Contributor

The job x86_64-gnu-llvm-6.0 of your PR failed (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.
2019-08-05T16:19:33.6312378Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-08-05T16:19:33.6505965Z ##[command]git config gc.auto 0
2019-08-05T16:19:33.6589564Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-08-05T16:19:33.6644934Z ##[command]git config --get-all http.proxy
2019-08-05T16:19:33.6787047Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/62330/merge:refs/remotes/pull/62330/merge
---
2019-08-05T16:20:10.3163046Z do so (now or later) by using -b with the checkout command again. Example:
2019-08-05T16:20:10.3163076Z 2019-08-05T16:20:10.3163283Z git checkout -b <new-branch-name>
2019-08-05T16:20:10.3163496Z 2019-08-05T16:20:10.3163563Z HEAD is now at a91151e62 Merge d2a4d5732f55204b21d0fc0b6ca31375e26f74df into 4be067558962c004b638e4c6f162d50f7c0c98b6
2019-08-05T16:20:10.3322060Z ##[section]Starting: Collect CPU-usage statistics in the background
2019-08-05T16:20:10.3324878Z ==============================================================================
2019-08-05T16:20:10.3324935Z Task : Bash
2019-08-05T16:20:10.3324981Z Description : Run a Bash script on macOS, Linux, or Windows
---
2019-08-05T17:23:21.8166646Z .................................................................................................... 1400/8828
2019-08-05T17:23:28.0171526Z .................................................................................................... 1500/8828
2019-08-05T17:23:40.9382506Z ....................................................................i...............i............... 1600/8828
2019-08-05T17:23:48.3033728Z .................................................................................................... 1700/8828
2019-08-05T17:24:04.2113395Z ......................................................iiiii......................................... 1800/8828
2019-08-05T17:24:16.0511268Z .................................................................................................... 2000/8828
2019-08-05T17:24:18.6973967Z .................................................................................................... 2100/8828
2019-08-05T17:24:22.1406633Z .................................................................................................... 2200/8828
2019-08-05T17:24:30.3514382Z .................................................................................................... 2300/8828
---
2019-08-05T17:28:25.9335711Z .................................................................................................... 5200/8828
2019-08-05T17:28:34.4877314Z .....................................................................i.............................. 5300/8828
2019-08-05T17:28:42.0481869Z .................................................................................................... 5400/8828
2019-08-05T17:28:49.2727584Z .................................................................................................... 5500/8828
2019-08-05T17:29:00.7763942Z ...............................................................ii...i..ii...........i............... 5600/8828
2019-08-05T17:29:25.6092377Z .................................................................................................... 5800/8828
2019-08-05T17:29:30.7832532Z .................................................................................................... 5900/8828
2019-08-05T17:29:30.7832532Z .................................................................................................... 5900/8828
2019-08-05T17:29:37.1194686Z ................................................................i..ii............................... 6000/8828
2019-08-05T17:30:06.9953633Z .................................................................................................... 6200/8828
2019-08-05T17:30:09.2799401Z .......i............................................................................................ 6300/8828
2019-08-05T17:30:11.5014800Z ...............................................................................i.................... 6400/8828
2019-08-05T17:30:14.2790581Z .................................................................................................... 6500/8828
---
2019-08-05T17:34:25.9845824Z failures:
2019-08-05T17:34:25.9873366Z 2019-08-05T17:34:25.9874167Z ---- [ui] ui/union/union-with-drop-fields-lint-rpass.rs stdout ----
2019-08-05T17:34:25.9874347Z 2019-08-05T17:34:25.9874870Z error: test compilation failed although it shouldn't!
2019-08-05T17:34:25.9875048Z status: exit code: 1
2019-08-05T17:34:25.9875973Z command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/union/union-with-drop-fields-lint-rpass.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/union/union-with-drop-fields-lint-rpass/a" "-Crpath" "-O" "-Cdebuginfo=0" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/union/union-with-drop-fields-lint-rpass/auxiliary" "-A" "unused"
2019-08-05T17:34:25.9876593Z ------------------------------------------
2019-08-05T17:34:25.9876741Z 2019-08-05T17:34:25.9877079Z ------------------------------------------
2019-08-05T17:34:25.9877238Z stderr:
2019-08-05T17:34:25.9877238Z stderr:
2019-08-05T17:34:25.9877589Z ------------------------------------------
2019-08-05T17:34:25.9877751Z warning: unknown lint: `unions_with_drop_fields`
2019-08-05T17:34:25.9878339Z |
2019-08-05T17:34:25.9878339Z |
2019-08-05T17:34:25.9878470Z LL | #![allow(unions_with_drop_fields)]
2019-08-05T17:34:25.9878751Z |
2019-08-05T17:34:25.9878873Z = note: `#[warn(unknown_lints)]` on by default
2019-08-05T17:34:25.9879000Z 2019-08-05T17:34:25.9879124Z error[E0740]: unions may not contain fields that need dropping
2019-08-05T17:34:25.9879124Z error[E0740]: unions may not contain fields that need dropping
2019-08-05T17:34:25.9879503Z --> /checkout/src/test/ui/union/union-with-drop-fields-lint-rpass.rs:12:5
2019-08-05T17:34:25.9879687Z |
2019-08-05T17:34:25.9879808Z LL | a: String, // OK
2019-08-05T17:34:25.9880064Z |
2019-08-05T17:34:25.9880186Z note: `std::mem::ManuallyDrop` can be used to wrap the type
2019-08-05T17:34:25.9880554Z --> /checkout/src/test/ui/union/union-with-drop-fields-lint-rpass.rs:12:5
2019-08-05T17:34:25.9880997Z |
2019-08-05T17:34:25.9880997Z |
2019-08-05T17:34:25.9881199Z LL | a: String, // OK
2019-08-05T17:34:25.9881677Z 2019-08-05T17:34:25.9881895Z error[E0740]: unions may not contain fields that need dropping
2019-08-05T17:34:25.9882380Z --> /checkout/src/test/ui/union/union-with-drop-fields-lint-rpass.rs:20:5
2019-08-05T17:34:25.9882578Z |
2019-08-05T17:34:25.9882578Z |
2019-08-05T17:34:25.9882698Z LL | a: S, // OK
2019-08-05T17:34:25.9882953Z |
2019-08-05T17:34:25.9883077Z note: `std::mem::ManuallyDrop` can be used to wrap the type
2019-08-05T17:34:25.9883466Z --> /checkout/src/test/ui/union/union-with-drop-fields-lint-rpass.rs:20:5
2019-08-05T17:34:25.9883632Z |
2019-08-05T17:34:25.9883632Z |
2019-08-05T17:34:25.9883751Z LL | a: S, // OK
2019-08-05T17:34:25.9883988Z 2019-08-05T17:34:25.9884351Z error[E0740]: unions may not contain fields that need dropping
2019-08-05T17:34:25.9884848Z --> /checkout/src/test/ui/union/union-with-drop-fields-lint-rpass.rs:25:5
2019-08-05T17:34:25.9885030Z |
2019-08-05T17:34:25.9885030Z |
2019-08-05T17:34:25.9885150Z LL | a: T, // OK
2019-08-05T17:34:25.9885412Z |
2019-08-05T17:34:25.9885533Z note: `std::mem::ManuallyDrop` can be used to wrap the type
2019-08-05T17:34:25.9885922Z --> /checkout/src/test/ui/union/union-with-drop-fields-lint-rpass.rs:25:5
2019-08-05T17:34:25.9886088Z |
2019-08-05T17:34:25.9886088Z |
2019-08-05T17:34:25.9886207Z LL | a: T, // OK
2019-08-05T17:34:25.9886445Z 2019-08-05T17:34:25.9886566Z error: aborting due to 3 previous errors
2019-08-05T17:34:25.9886667Z 2019-08-05T17:34:25.9887046Z For more information about this error, try `rustc --explain E0740`.
---
2019-08-05T17:34:25.9915626Z thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:536:22
2019-08-05T17:34:25.9915876Z note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
2019-08-05T17:34:25.9942831Z 2019-08-05T17:34:26.8257846Z 2019-08-05T17:34:26.8298815Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/ui" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "ui" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-6.0/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "6.0.0\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
2019-08-05T17:34:26.8299091Z 2019-08-05T17:34:26.8299136Z 2019-08-05T17:34:26.8299186Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
2019-08-05T17:34:26.8299239Z Build completed unsuccessfully in 1:07:58
2019-08-05T17:34:26.8299239Z Build completed unsuccessfully in 1:07:58
2019-08-05T17:34:26.8357601Z ##[error]Bash exited with code '1'.
2019-08-05T17:34:26.8411585Z ##[section]Starting: Checkout
2019-08-05T17:34:26.8413222Z ==============================================================================
2019-08-05T17:34:26.8413283Z Task : Get sources
2019-08-05T17:34:26.8413350Z Description : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

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)

@oli-obk
oli-obkforce-pushed the no-drop-in-union-fields branch from f8b45dd to bb5a652CompareOctober 17, 2019 11:28
@RalfJung

Copy link
Copy Markdown
Member

That fixes my reservations. :)

Let's finally do this... thanks to everyone involved! @bors r+

@bors

bors commented Oct 21, 2019

Copy link
Copy Markdown
Collaborator

📌 Commit 875bdd5 has been approved by RalfJung

@borsbors 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 Oct 21, 2019
@bors

bors commented Oct 21, 2019

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 875bdd5 with merge da66b096c142097755e3474b7f1b3f2dafd61f9a...

Centril added a commit to Centril/rust that referenced this pull request Oct 21, 2019
… r=RalfJung
Change untagged_unions to not allow union fields with drop
This is a rebase of rust-lang#56440, massaged to solve merge conflicts and make the test suite pass.
Change untagged_unions to not allow union fields with drop
Union fields may now never have a type with attached destructor. This for example allows unions to use arbitrary field types only by wrapping them in `ManuallyDrop` (or similar).
The stable rule remains, that union fields must be `Copy`. We use the new rule for the `untagged_union` feature.
Tracking issue: rust-lang#55149
@CentrilCentril mentioned this pull request Oct 21, 2019
@Centril

Copy link
Copy Markdown
Contributor

@bors retry rolled up.

@bors

bors commented Oct 21, 2019

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 875bdd5 with merge b3e8ca17bd0ec17cd42fb43f92ff37e4a72fa7b1...

Centril added a commit to Centril/rust that referenced this pull request Oct 21, 2019
… r=RalfJung
Change untagged_unions to not allow union fields with drop
This is a rebase of rust-lang#56440, massaged to solve merge conflicts and make the test suite pass.
Change untagged_unions to not allow union fields with drop
Union fields may now never have a type with attached destructor. This for example allows unions to use arbitrary field types only by wrapping them in `ManuallyDrop` (or similar).
The stable rule remains, that union fields must be `Copy`. We use the new rule for the `untagged_union` feature.
Tracking issue: rust-lang#55149
@CentrilCentril mentioned this pull request Oct 21, 2019
@Centril

Copy link
Copy Markdown
Contributor

@bors retry rolled up.

bors added a commit that referenced this pull request Oct 22, 2019
Rollup of 7 pull requests
Successful merges:
- #62330 (Change untagged_unions to not allow union fields with drop)
- #65092 (make is_power_of_two a const function)
- #65621 (miri: add write_bytes method to Memory doing bounds-checks and supporting iterators)
- #65647 (Remove unnecessary trait bounds and derivations)
- #65653 (keep the root dir clean from debugging)
- #65660 (Rename `ConstValue::Infer(InferConst::Canonical(..))` to `ConstValue::Bound(..)`)
- #65663 (Fix typo from #65214)
Failed merges:
r? @ghost
@bors
bors merged commit 875bdd5 into rust-lang:masterOct 22, 2019
@bluss

Copy link
Copy Markdown
Contributor

Awesome. Thanks to all that worked on this!

@CentrilCentril added the F-untagged_unions `#![feature(untagged_unions)]` label Oct 24, 2019
@SimonSapin
SimonSapin deleted the no-drop-in-union-fields branch November 28, 2019 12:04
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-destructorsArea: Destructors (`Drop`, …)B-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.F-untagged_unions`#![feature(untagged_unions)]`S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant 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.

12 participants

@SimonSapin@rust-highfive@Centril@bors@eddyb@JohnTitor@wirelessringo@JohnCSimon@oli-obk@RalfJung@bluss@matthewjasper