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

confusing diagnostic for incorrect type parameter on BoxFuture #72117

Closed
qutesy opened this issue May 11, 2020 · 5 comments · Fixed by #89390
Closed

confusing diagnostic for incorrect type parameter on BoxFuture #72117

qutesy opened this issue May 11, 2020 · 5 comments · Fixed by #89390
Assignees
Labels
A-async-await A-diagnostics AsyncAwait-Triaged C-enhancement D-invalid-suggestion E-mentor T-compiler

Comments

@qutesy
Copy link

@qutesy qutesy commented May 11, 2020

I tried this code:

use futures::{future::{BoxFuture, Future, FutureExt}};

async fn f() -> bool {
    true
}

#[allow(dead_code)]
struct Foo<'a, F>
where F: Future<Output=bool> + Send {
    f: Option<BoxFuture<'a, F>>,
}

impl<'a, F> Foo<'a, F>
where F: Future<Output=bool> + Send + 'a {
    fn new(f: F) -> Self {
        Self {
            f: Some(f.boxed())
        }
    }
}

fn main() {
    Foo::new(f());
}

I expected to see this happen:
I wish the compiler had suggested that I should change f: Option<BoxFuture<'a, F>> to f: Option<BoxFuture<'a, F::Output>>,

Instead, this happened:

27 | impl<'a, F> Foo<'a, F>
   |          - this type parameter
...
33 |             f: Some(f.boxed())
   |                     ^^^^^^^^^
   |                     |
   |                     expected type parameter `F`, found `bool`
   |                     help: you need to pin and box this expression: `Box::pin(f.boxed())`
*/

Meta

Rust compiler version (stable version on play.rust-lang.org).

1.43.1

Playground link

Backtrace

N/A (compile error)

@qutesy qutesy added the C-bug label May 11, 2020
@jonas-schievink jonas-schievink added A-async-await A-diagnostics C-enhancement T-compiler and removed C-bug labels May 11, 2020
@tmandry
Copy link
Contributor

@tmandry tmandry commented May 12, 2020

cc @estebank, I think the suggestion shouldn't be applied here. Is there a way we can target it more precisely?

@tmandry tmandry added AsyncAwait-Triaged D-invalid-suggestion labels May 12, 2020
@tmandry tmandry added this to On deck in wg-async work via automation May 12, 2020
@tmandry
Copy link
Contributor

@tmandry tmandry commented May 12, 2020

Triage: wg-async-foundations will track this until the incorrect suggestion is removed, other improvements to the suggestion are out of scope for us.

@estebank
Copy link
Contributor

@estebank estebank commented May 12, 2020

Some extra filtering in the following will be needed, but without further checking I can't tell for sure what the check should be:

https://github.com/rust-lang/rust/pull/69082/files#diff-1d1b0d29a2e8da97c6bfb6e364d920c7R5070-R5089

@bugaevc
Copy link

@bugaevc bugaevc commented Sep 9, 2020

Simple reproducer:

let f: BoxFuture<'static, bool> = async { }.boxed();

playground

@tmandry tmandry added the E-mentor label Sep 10, 2020
@eholk eholk moved this from On deck to In progress (current sprint) in wg-async work Sep 16, 2021
@tmandry
Copy link
Contributor

@tmandry tmandry commented Sep 20, 2021

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 14, 2021
Fix incorrect Box::pin suggestion

The suggestion checked if `Pin<Box<T>>` could be coeerced to the expected
type, but did not check predicates created by the coercion. We now
look for predicates that definitely cannot be satisfied before giving
the suggestion.

The suggestion is still marked MaybeIncorrect because we allow predicates that
are still ambiguous and can't be proven.

Fixes rust-lang#72117.
@bors bors closed this as completed in f9c9774 Oct 14, 2021
wg-async work automation moved this from In progress (current sprint) to Done Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await A-diagnostics AsyncAwait-Triaged C-enhancement D-invalid-suggestion E-mentor T-compiler
Projects
Development

Successfully merging a pull request may close this issue.

5 participants