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

Typo in error output: Instead of clone()..await it should be .clone().await #110761

Closed
Boscop opened this issue Apr 24, 2023 · 1 comment · Fixed by #110823
Closed

Typo in error output: Instead of clone()..await it should be .clone().await #110761

Boscop opened this issue Apr 24, 2023 · 1 comment · Fixed by #110823
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Boscop
Copy link

Boscop commented Apr 24, 2023

Code

// Full code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=03b0d135b9b888d739a99a580d406314
    let g = async || 1;
    let h = async || 1;
    let f = {
        let g_plus_h = memoize!(g().await + h().await);
        let two_plus_two = memoize!(2 + 2);
        async move || -> Vec<Shared<Pin<Box<dyn Future<Output = i64> + Send + 'static>>>> {
            vec![g_plus_h, two_plus_two]
        }
    };
    let a = f().await[0].await;
    let b = f().await[1].await;

Current output

error[E0507]: cannot move out of index of `Vec<Shared<Pin<Box<dyn futures::Future<Output = i64> + std::marker::Send>>>>`
  --> src/main.rs:62:13
   |
62 |     let a = f().await[0].await;
   |             ^^^^^^^^^^^^------ value moved due to this method call
   |             |
   |             move occurs because value has type `Shared<Pin<Box<dyn futures::Future<Output = i64> + std::marker::Send>>>`, which does not implement the `Copy` trait
   |
note: `std::future::IntoFuture::into_future` takes ownership of the receiver `self`, which moves value
  --> /rustc/7f94b314cead7059a71a265a8b64905ef2511796/library/core/src/future/into_future.rs:128:20
help: you can `clone` the value and consume it, but this might not be your desired behavior
   |
62 |     let a = f().await[0]clone()..await;
   |                         ++++++++

Desired output

Instead of `clone()..await` it should be `.clone().await`.

Rationale and extra context

image

Other cases

No response

Anything else?

No response

@Boscop Boscop added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 24, 2023
@Boscop Boscop changed the title Typo in error output Typo in error output: Instead of clone()..await it should be .clone().await Apr 24, 2023
@Boscop
Copy link
Author

Boscop commented Apr 24, 2023

Another one: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=63c8871e7074109dea8ae252a010963a

help: to declare that the trait object captures data from argument `f`, you can add a lifetime parameter `'a` in the type alias
   |
82 | type Lazy<T><'a> = Shared<Pin<Box<dyn Future<Output = T> + Send + 'static + 'a>>>;
   |             ++++                                                          ++++

It should print type Lazy<'a, T> = ...

@compiler-errors compiler-errors self-assigned this Apr 25, 2023
@bors bors closed this as completed in 1b262b8 May 1, 2023
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue May 8, 2023
…wup, r=cjgillot

Fix lifetime suggestion for type aliases with objects in them

Fixes an issue identified in rust-lang#110761 (comment)

This suggestion, like many other borrowck suggestions, are very fragile and there are other ways to trigger strange behavior even after this PR, so this is just a small improvement and not a total rework 💀
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants