- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
async/await: improve not-send errors #64895
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 #64895
Conversation
      
        
              This comment has been minimized.
        
        
      
    
  This comment has been minimized.
42ce06e    to
    f7cb10d      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some nits.
      
        
              This comment has been minimized.
        
        
      
    
  This comment has been minimized.
f7cb10d    to
    bdaec6a      
    Compare
  
    | I'm not sure where the duplicate diagnostic item error is coming from, a quick glance only found the  | 
| cc @oli-obk ^--- | 
      
        
              This comment has been minimized.
        
        
      
    
  This comment has been minimized.
bdaec6a    to
    e0f08b5      
    Compare
  
    e0f08b5    to
    28be5ae      
    Compare
  
    | @bors r+ | 
| 📌 Commit 28be5ae8c558613e59a56eb83f069da47eda56ed has been approved by  | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome. Beautiful work. My one concern is that I think we can do better still with the error, but I'm sort of inclined to land this PR and continue that work afterwards.
        
          
                src/test/ui/async-await/issue-64130-non-send-future-diags.stderr
              
                Outdated
          
            Show resolved
            Hide resolved
        
      28be5ae    to
    9076646      
    Compare
  
    This commit improves obligation errors for async/await:
```
note: future does not implement `std::marker::Send` because this value is used across an
      await
  --> $DIR/issue-64130-non-send-future-diags.rs:15:5
   |
LL |     let g = x.lock().unwrap();
   |         - has type `std::sync::MutexGuard<'_, u32>`
LL |     baz().await;
   |     ^^^^^^^^^^^ await occurs here, with `g` maybe used later
LL | }
   | - `g` is later dropped here
```
Signed-off-by: David Wood <david@davidtw.co>
    9076646    to
    04fa9b1      
    Compare
  
    | @bors r+ | 
| 📌 Commit 04fa9b1 has been approved by  | 
…efinition, r=nikomatsakis async/await: improve not-send errors cc rust-lang#64130. ``` note: future does not implement `std::marker::Send` because this value is used across an await --> $DIR/issue-64130-non-send-future-diags.rs:15:5 | LL | let g = x.lock().unwrap(); | - has type `std::sync::MutexGuard<'_, u32>` LL | baz().await; | ^^^^^^^^^^^ await occurs here, with `g` maybe used later LL | } | - `g` is later dropped here ``` r? @nikomatsakis
Rollup of 10 pull requests Successful merges: - #63674 (syntax: Support modern attribute syntax in the `meta` matcher) - #63931 (Stabilize macros in some more positions) - #64887 (syntax: recover trailing `|` in or-patterns) - #64895 (async/await: improve not-send errors) - #64896 (Remove legacy grammar) - #64907 (A small amount of tidying-up factored out from PR #64648) - #64928 (Add tests for some issues) - #64930 (Silence unreachable code lint from await desugaring) - #64935 (Improve code clarity) - #64937 (Deduplicate closure type errors) Failed merges: r? @ghost
| ☔ The latest upstream changes (presumably #64946) made this pull request unmergeable. Please resolve the merge conflicts. | 
| 
 
 | 
| I'd like to nominate this PR (and the follow-up #64989) for inclusion in beta. It's not the sort of thing I would normally include, but this error is (a) one of the most common problems I hear people complaining about with async-await and (b) particularly opaque without this fix. Moreover, it is early in the cycle, so it will presumably get a reasonable amount of testing before landing. The change is relatively low risk, in that it is confined to error reporting. | 
[beta] backport rollup This includes a bunch of PRs: * Fix redundant semicolon lint interaction with proc macro attributes #64387 * Upgrade async/await to "used" keywords. #64875 * syntax: fix dropping of attribute on first param of non-method assocated fn #64894 * async/await: improve not-send errors #64895 * Silence unreachable code lint from await desugaring #64930 * Always mark rust and rust-call abi's as unwind #65020 * Account for macro invocation in `let mut $pat` diagnostic. #65123 * Ensure that associated `async fn`s have unique fresh param names #65142 * Add troubleshooting section to PGO chapter in rustc book. #65402 * Upgrade GCC to 8.3.0, glibc to 1.17.0 and crosstool-ng to 1.24.0 for dist-armv7-linux #65302 * Optimize `try_expand_impl_trait_type` #65293 * use precalculated dominators in explain_borrow #65172 * Fix ICE #64964 #64989
[beta] backport rollup This includes a bunch of PRs: * Fix redundant semicolon lint interaction with proc macro attributes #64387 * Upgrade async/await to "used" keywords. #64875 * syntax: fix dropping of attribute on first param of non-method assocated fn #64894 * async/await: improve not-send errors #64895 * Silence unreachable code lint from await desugaring #64930 * Always mark rust and rust-call abi's as unwind #65020 * Account for macro invocation in `let mut $pat` diagnostic. #65123 * Ensure that associated `async fn`s have unique fresh param names #65142 * Add troubleshooting section to PGO chapter in rustc book. #65402 * Upgrade GCC to 8.3.0, glibc to 1.17.0 and crosstool-ng to 1.24.0 for dist-armv7-linux #65302 * Optimize `try_expand_impl_trait_type` #65293 * use precalculated dominators in explain_borrow #65172 * Fix ICE #64964 #64989 * [beta] Revert "Auto merge of #62948 - matklad:failable-file-loading, r=petro… #65273 * save-analysis: Don't ICE when resolving qualified type paths in struct members #65353 * save-analysis: Nest tables when processing impl block definitions #65511 * Avoid ICE when checking `Destination` of `break` inside a closure #65518 * Avoid ICE when adjusting bad self ty #65755 * workaround msys2 bug #65762
…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
cc #64130.
r? @nikomatsakis