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 Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-enhancement Category: An issue proposing an enhancement or a PR with one. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@qutesy
Copy link

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 Category: This is a bug. label May 11, 2020
@jonas-schievink jonas-schievink added A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed C-bug Category: This is a bug. labels May 11, 2020
@tmandry
Copy link
Member

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 Async-await issues that have been triaged during a working group meeting. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels May 12, 2020
@tmandry
Copy link
Member

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

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 commented Sep 9, 2020

Simple reproducer:

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

playground

@tmandry tmandry added the E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. label Sep 10, 2020
@tmandry
Copy link
Member

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-enhancement Category: An issue proposing an enhancement or a PR with one. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

5 participants