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

async/await: improve not-send errors, part 2 #65345

Merged

Conversation

@davidtwco
Copy link
Member

davidtwco commented Oct 12, 2019

Part of #64130. Fixes #65667.

This PR improves the errors introduced in #64895 so that they have specialized messages for Send and Sync.

r? @nikomatsakis

src/libcore/marker.rs Outdated Show resolved Hide resolved
@rust-highfive

This comment was marked as resolved.

Copy link
Collaborator

rust-highfive commented Oct 30, 2019

The job x86_64-gnu-llvm-6.0 of your PR failed (pretty log, 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-10-30T13:28:57.2867360Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-10-30T13:28:57.3069164Z ##[command]git config gc.auto 0
2019-10-30T13:28:57.3143250Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-10-30T13:28:57.3174356Z ##[command]git config --get-all http.proxy
2019-10-30T13:28:57.3318757Z ##[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/65345/merge:refs/remotes/pull/65345/merge
---
2019-10-30T14:21:14.0270676Z .................................................................................................... 1600/9266
2019-10-30T14:21:18.9819100Z .................................................................................................... 1700/9266
2019-10-30T14:21:29.8362489Z .............................................................i...............i...................... 1800/9266
2019-10-30T14:21:36.8760227Z .................................................................................................... 1900/9266
2019-10-30T14:21:49.6672570Z ...................................................iiiii............................................ 2000/9266
2019-10-30T14:21:59.1452146Z .................................................................................................... 2200/9266
2019-10-30T14:22:01.3985468Z .................................................................................................... 2300/9266
2019-10-30T14:22:04.4678045Z .................................................................................................... 2400/9266
2019-10-30T14:22:24.5858582Z .................................................................................................... 2500/9266
2019-10-30T14:22:24.5858582Z .................................................................................................... 2500/9266
2019-10-30T14:22:26.9717385Z .................................................................................................... 2600/9266
2019-10-30T14:22:33.7890125Z .................................................................................................... 2700/9266
2019-10-30T14:22:41.4615953Z ....................i....................................................................F.......... 2800/9266
2019-10-30T14:22:49.1801166Z .................................................................................................... 2900/9266
2019-10-30T14:22:53.2478467Z ...................i................................................................................ 3000/9266
2019-10-30T14:23:00.7099958Z .................................................................................................... 3100/9266
2019-10-30T14:23:05.5578906Z .................................................................................................... 3200/9266
2019-10-30T14:23:13.1301051Z .ii................................................................................................. 3300/9266
2019-10-30T14:23:27.9770756Z ..............................................................................................i..... 3500/9266
2019-10-30T14:23:34.6348573Z .........................................i.......................................................... 3600/9266
2019-10-30T14:23:40.4282501Z .................................................................................................... 3700/9266
2019-10-30T14:23:46.0902197Z .................................................................................................... 3800/9266
---
2019-10-30T14:24:54.6050137Z ....................................................i...............i............................... 4800/9266
2019-10-30T14:25:02.9998277Z .................................................................................................... 4900/9266
2019-10-30T14:25:10.7919721Z .................................................................................................... 5000/9266
2019-10-30T14:25:16.4537990Z .................................................................................................... 5100/9266
2019-10-30T14:25:25.8484256Z .....................................................ii.ii...........i.............................. 5200/9266
2019-10-30T14:25:34.9935399Z .................................................................................................... 5400/9266
2019-10-30T14:25:43.9340324Z .................................................................................................... 5500/9266
2019-10-30T14:25:50.6354087Z ..........................i......................................................................... 5600/9266
2019-10-30T14:25:56.4895022Z .................................................................................................... 5700/9266
2019-10-30T14:25:56.4895022Z .................................................................................................... 5700/9266
2019-10-30T14:26:07.2203053Z .................................................................................................... 5800/9266
2019-10-30T14:26:17.9336496Z ...........ii...i..ii...........i................................................................... 5900/9266
2019-10-30T14:26:36.1777464Z .................................................................................................... 6100/9266
2019-10-30T14:26:43.8060717Z .................................................................................................... 6200/9266
2019-10-30T14:26:43.8060717Z .................................................................................................... 6200/9266
2019-10-30T14:26:59.5466089Z ..............................i..ii................................................................. 6300/9266
2019-10-30T14:27:17.8034447Z ................................................................................................i... 6500/9266
2019-10-30T14:27:19.8298669Z .................................................................................................... 6600/9266
2019-10-30T14:27:21.9172080Z .......................................................................i............................ 6700/9266
2019-10-30T14:27:24.6487589Z .................................................................................................... 6800/9266
---
2019-10-30T14:28:53.4355214Z .................................................................................................... 7400/9266
2019-10-30T14:28:58.4279104Z .................................................................................................... 7500/9266
2019-10-30T14:29:06.5606015Z .................................................................................................... 7600/9266
2019-10-30T14:29:16.5736794Z .................................................................................................... 7700/9266
2019-10-30T14:29:25.2151429Z ..........................................................................................ii......i. 7800/9266
2019-10-30T14:29:35.3697960Z .................................................................................................... 8000/9266
2019-10-30T14:29:50.6310796Z .................................................................................................... 8100/9266
2019-10-30T14:29:58.4441043Z .................................................................................................... 8200/9266
2019-10-30T14:30:07.3419463Z .................................................................................................... 8300/9266
---
2019-10-30T14:31:44.3040144Z 
2019-10-30T14:31:44.3040923Z ---- [ui] ui/generator/not-send-sync.rs stdout ----
2019-10-30T14:31:44.3041280Z diff of stderr:
2019-10-30T14:31:44.3041522Z 
2019-10-30T14:31:44.3041694Z 11    = note: required because of the requirements on the impl of `std::marker::Send` for `&std::cell::Cell<i32>`
2019-10-30T14:31:44.3042136Z 12    = note: required because it appears within the type `[generator@$DIR/not-send-sync.rs:16:17: 20:6 a:&std::cell::Cell<i32> _]`
2019-10-30T14:31:44.3042330Z 13 
2019-10-30T14:31:44.3042693Z - error[E0277]: `std::cell::Cell<i32>` cannot be shared between threads safely
2019-10-30T14:31:44.3042861Z + error: future cannot be shared between threads safely
2019-10-30T14:31:44.3044057Z 16    |
2019-10-30T14:31:44.3044057Z 16    |
2019-10-30T14:31:44.3044345Z 17 LL |     fn assert_sync<T: Sync>(_: T) {}
2019-10-30T14:31:44.3044928Z 18    |        -----------    ---- required by this bound in `main::assert_sync`
2019-10-30T14:31:44.3045117Z 19 ...
2019-10-30T14:31:44.3045117Z 19 ...
2019-10-30T14:31:44.3045273Z 20 LL |     assert_sync(|| {
2019-10-30T14:31:44.3045685Z -    |     ^^^^^^^^^^^ `std::cell::Cell<i32>` cannot be shared between threads safely
2019-10-30T14:31:44.3045872Z +    |     ^^^^^^^^^^^ future returned by `main` is not `Sync`
2019-10-30T14:31:44.3046029Z 22    |
2019-10-30T14:31:44.3046504Z 23    = help: within `[generator@$DIR/not-send-sync.rs:9:17: 13:6 {std::cell::Cell<i32>, ()}]`, the trait `std::marker::Sync` is not implemented for `std::cell::Cell<i32>`
2019-10-30T14:31:44.3046960Z -    = note: required because it appears within the type `{std::cell::Cell<i32>, ()}`
2019-10-30T14:31:44.3047566Z -    = note: required because it appears within the type `[generator@$DIR/not-send-sync.rs:9:17: 13:6 {std::cell::Cell<i32>, ()}]`
2019-10-30T14:31:44.3047873Z + note: future is not `Sync` as this value is used across an await
2019-10-30T14:31:44.3048199Z +   --> $DIR/not-send-sync.rs:12:9
2019-10-30T14:31:44.3048502Z + LL |         let a = Cell::new(2);
2019-10-30T14:31:44.3049027Z +    |             - has type `std::cell::Cell<i32>`
2019-10-30T14:31:44.3049198Z + LL |         yield;
2019-10-30T14:31:44.3049360Z +    |         ^^^^^ await occurs here, with `a` maybe used later
---
2019-10-30T14:31:44.3050220Z 28 
2019-10-30T14:31:44.3050337Z 
2019-10-30T14:31:44.3050439Z 
2019-10-30T14:31:44.3050561Z The actual stderr differed from the expected stderr.
2019-10-30T14:31:44.3050975Z Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/generator/not-send-sync/not-send-sync.stderr
2019-10-30T14:31:44.3051361Z To update references, rerun the tests and pass the `--bless` flag
2019-10-30T14:31:44.3051749Z To only update this specific test, also pass `--test-args generator/not-send-sync.rs`
2019-10-30T14:31:44.3052039Z error: 1 errors occurred comparing output.
2019-10-30T14:31:44.3052170Z status: exit code: 1
2019-10-30T14:31:44.3052170Z status: exit code: 1
2019-10-30T14:31:44.3052962Z command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/generator/not-send-sync.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/generator/not-send-sync" "-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/generator/not-send-sync/auxiliary" "-A" "unused"
2019-10-30T14:31:44.3053641Z ------------------------------------------
2019-10-30T14:31:44.3053915Z 
2019-10-30T14:31:44.3054399Z ------------------------------------------
2019-10-30T14:31:44.3054579Z stderr:
2019-10-30T14:31:44.3054579Z stderr:
2019-10-30T14:31:44.3054935Z ------------------------------------------
2019-10-30T14:31:44.3055153Z error[E0277]: `std::cell::Cell<i32>` cannot be shared between threads safely
2019-10-30T14:31:44.3055731Z    |
2019-10-30T14:31:44.3055731Z    |
2019-10-30T14:31:44.3055889Z LL |     fn assert_send<T: Send>(_: T) {}
2019-10-30T14:31:44.3056464Z ...
2019-10-30T14:31:44.3056621Z LL |     assert_send(|| {
2019-10-30T14:31:44.3056621Z LL |     assert_send(|| {
2019-10-30T14:31:44.3056767Z    |     ^^^^^^^^^^^ `std::cell::Cell<i32>` cannot be shared between threads safely
2019-10-30T14:31:44.3057170Z    = help: the trait `std::marker::Sync` is not implemented for `std::cell::Cell<i32>`
2019-10-30T14:31:44.3057366Z    = note: required because of the requirements on the impl of `std::marker::Send` for `&std::cell::Cell<i32>`
2019-10-30T14:31:44.3057366Z    = note: required because of the requirements on the impl of `std::marker::Send` for `&std::cell::Cell<i32>`
2019-10-30T14:31:44.3057894Z    = note: required because it appears within the type `[generator@/checkout/src/test/ui/generator/not-send-sync.rs:16:17: 20:6 a:&std::cell::Cell<i32> _]`
2019-10-30T14:31:44.3058090Z 
2019-10-30T14:31:44.3058259Z error: future cannot be shared between threads safely
2019-10-30T14:31:44.3058827Z    |
2019-10-30T14:31:44.3058827Z    |
2019-10-30T14:31:44.3058986Z LL |     fn assert_sync<T: Sync>(_: T) {}
2019-10-30T14:31:44.3059376Z    |        -----------    ---- required by this bound in `main::assert_sync`
2019-10-30T14:31:44.3059554Z ...
2019-10-30T14:31:44.3059712Z LL |     assert_sync(|| {
2019-10-30T14:31:44.3059853Z    |     ^^^^^^^^^^^ future returned by `main` is not `Sync`
2019-10-30T14:31:44.3059986Z    |
2019-10-30T14:31:44.3060522Z    = help: within `[generator@/checkout/src/test/ui/generator/not-send-sync.rs:9:17: 13:6 {std::cell::Cell<i32>, ()}]`, the trait `std::marker::Sync` is not implemented for `std::cell::Cell<i32>`
2019-10-30T14:31:44.3060729Z note: future is not `Sync` as this value is used across an await
2019-10-30T14:31:44.3061549Z    |
2019-10-30T14:31:44.3061693Z LL |         let a = Cell::new(2);
2019-10-30T14:31:44.3062114Z    |             - has type `std::cell::Cell<i32>`
2019-10-30T14:31:44.3062355Z LL |         yield;
---
2019-10-30T14:31:44.3100504Z thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:537:22
2019-10-30T14:31:44.3100574Z note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
2019-10-30T14:31:45.2778683Z 
2019-10-30T14:31:45.2778894Z 
2019-10-30T14:31:45.2781136Z 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-10-30T14:31:45.2781442Z 
2019-10-30T14:31:45.2781598Z 
2019-10-30T14:31:45.2781644Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
2019-10-30T14:31:45.2781692Z Build completed unsuccessfully in 0:56:46
2019-10-30T14:31:45.2781692Z Build completed unsuccessfully in 0:56:46
2019-10-30T14:31:45.2781765Z == clock drift check ==
2019-10-30T14:31:45.2781812Z   local time: Wed Oct 30 14:31:44 UTC 2019
2019-10-30T14:31:45.2781858Z   network time: Wed, 30 Oct 2019 14:31:44 GMT
2019-10-30T14:31:45.2781921Z == end clock drift check ==
2019-10-30T14:31:45.7165288Z 
2019-10-30T14:31:45.7221491Z ##[error]Bash exited with code '1'.
2019-10-30T14:31:45.7258827Z ##[section]Starting: Checkout
2019-10-30T14:31:45.7260735Z ==============================================================================
2019-10-30T14:31:45.7260788Z Task         : Get sources
2019-10-30T14:31:45.7260830Z 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)

@davidtwco davidtwco force-pushed the davidtwco:issue-64130-async-send-sync-error-improvements branch from 964759e to 6d16511 Oct 30, 2019
Copy link
Member Author

davidtwco left a comment

Updated the PR (with help from @nikomatsakis) so that it now applies to more cases.

let ty = ty.builtin_deref(false).map(|ty_and_mut| ty_and_mut.ty).unwrap_or(ty);
let target_ty = target_ty.builtin_deref(false)
.map(|ty_and_mut| ty_and_mut.ty)
.unwrap_or(target_ty);

This comment has been minimized.

Copy link
@davidtwco

davidtwco Oct 30, 2019

Author Member

This is hack that I wasn't able to find a better solution for.

This comment has been minimized.

Copy link
@nikomatsakis

nikomatsakis Nov 8, 2019

Contributor

What problem is it solving, exactly? I guess that we sometimes capture things "by reference"?

This comment has been minimized.

Copy link
@davidtwco

davidtwco Nov 8, 2019

Author Member

I wasn’t able to find a way to check for equality of types that were ty::Ref, nothing seemed to work. There are some messages in the Zulip thread detailing what I tried when I was last looking at this. Nope, misremembered.

LL | fut().await;
| ^^^^^^^^^^^ await occurs here, with `x` maybe used later
LL | }
| - `x` is later dropped here

This comment has been minimized.

Copy link
@davidtwco

davidtwco Oct 30, 2019

Author Member

This diagnostic is misleading.

This comment has been minimized.

Copy link
@nikomatsakis

nikomatsakis Nov 8, 2019

Contributor

Hmm, because of the drop(x) that comes before? I suppose that's true, though it'd ordinarily be quite helpful. Perhaps we can just weaken the language to "x may be dropped here"?

This comment has been minimized.

Copy link
@davidtwco

davidtwco Nov 8, 2019

Author Member

Yeah, I think we could adjust the wording to better explain why the drop call isn’t enough to avoid the type being held over the await point.

This comment has been minimized.

Copy link
@nikomatsakis

nikomatsakis Nov 19, 2019

Contributor

I consider this a bit of a bug, also -- it'd be nice if we were more precise around particularly this case)

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Oct 30, 2019

@davidtwco should this still be considered "draft"?

@davidtwco davidtwco marked this pull request as ready for review Oct 30, 2019
@davidtwco

This comment has been minimized.

Copy link
Member Author

davidtwco commented Oct 30, 2019

@davidtwco should this still be considered "draft"?

Probably not, I’ve unmarked it.

@bors

This comment was marked as resolved.

Copy link
Contributor

bors commented Nov 8, 2019

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

@davidtwco davidtwco force-pushed the davidtwco:issue-64130-async-send-sync-error-improvements branch from 473d24e to 6c18dd6 Nov 8, 2019
Copy link
Contributor

nikomatsakis left a comment

uh I had some comments I apparently never posted :(

src/librustc/traits/error_reporting.rs Show resolved Hide resolved
};

// Look at the last interior type to get a span for the `.await`.
let await_span = tables.generator_interior_types.iter().map(|i| i.span).last().unwrap();

This comment has been minimized.

Copy link
@nikomatsakis

nikomatsakis Nov 8, 2019

Contributor

huh, so we just take the last span from the table? seems a bit arbitrary. Ideally, it would be tied to the value we are citing..?

This comment has been minimized.

Copy link
@nikomatsakis

nikomatsakis Nov 8, 2019

Contributor

but I guess that's pre-existing


// Get the tables from the infcx if the generator is the function we are
// currently type-checking; otherwise, get them by performing a query.
// This is needed to avoid cycles.

This comment has been minimized.

Copy link
@nikomatsakis

nikomatsakis Nov 8, 2019

Contributor

I wonder if we want a helper function for this

let ty = ty.builtin_deref(false).map(|ty_and_mut| ty_and_mut.ty).unwrap_or(ty);
let target_ty = target_ty.builtin_deref(false)
.map(|ty_and_mut| ty_and_mut.ty)
.unwrap_or(target_ty);

This comment has been minimized.

Copy link
@nikomatsakis

nikomatsakis Nov 8, 2019

Contributor

What problem is it solving, exactly? I guess that we sometimes capture things "by reference"?

@JohnCSimon

This comment has been minimized.

Copy link
Member

JohnCSimon commented Nov 16, 2019

Ping from triage:
@davidtwco Can you please address the comments from @nikomatsakis ? Thank you!
cc: @Centril

@davidtwco

This comment has been minimized.

Copy link
Member Author

davidtwco commented Nov 16, 2019

@Alexendoo

This comment has been minimized.

Copy link
Member

Alexendoo commented Nov 27, 2019

Ping from triage, any updates? @nikomatsakis

@JohnCSimon

This comment has been minimized.

Copy link
Member

JohnCSimon commented Dec 7, 2019

ping from triage:
@davidtwco - can you please address the merge conflict?
once that happens...
@nikomatsakis - please review this PR

Signed-off-by: David Wood <david@davidtw.co>
This commit corrects the diagnostic note for `async move {}` so that
`await` is mentioned, rather than `yield`.

Signed-off-by: David Wood <david@davidtw.co>
@davidtwco davidtwco force-pushed the davidtwco:issue-64130-async-send-sync-error-improvements branch from 6c18dd6 to f0b5114 Dec 8, 2019
The reason we were invoking `builtin_deref` was to enable comparisons
when the type was `&T`. For the reasons outlined in the comment, those
comparisons failed because the regions disagreed.
@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Dec 11, 2019

@bors r+

(Tests pass locally)

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Dec 11, 2019

📌 Commit 5cd9f22 has been approved by nikomatsakis

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Dec 11, 2019

⌛️ Testing commit 5cd9f22 with merge 27d6f55...

bors added a commit that referenced this pull request Dec 11, 2019
…provements, r=nikomatsakis

async/await: improve not-send errors, part 2

Part of #64130. Fixes #65667.

This PR improves the errors introduced in #64895 so that they have specialized messages for `Send` and `Sync`.

r? @nikomatsakis
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Dec 11, 2019

☀️ Test successful - checks-azure
Approved by: nikomatsakis
Pushing 27d6f55 to master...

@bors bors added the merged-by-bors label Dec 11, 2019
@bors bors merged commit 5cd9f22 into rust-lang:master Dec 11, 2019
5 checks passed
5 checks passed
homu Test successful
Details
pr #20191211.46 succeeded
Details
pr (Linux mingw-check) Linux mingw-check succeeded
Details
pr (Linux x86_64-gnu-llvm-7) Linux x86_64-gnu-llvm-7 succeeded
Details
pr (Linux x86_64-gnu-tools) Linux x86_64-gnu-tools succeeded
Details
@davidtwco davidtwco deleted the davidtwco:issue-64130-async-send-sync-error-improvements branch Dec 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants
You can’t perform that action at this time.