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 fn in trait: ICE with 2 generic params in method #102310

Closed
Dirbaio opened this issue Sep 26, 2022 · 3 comments · Fixed by #102334
Closed

async fn in trait: ICE with 2 generic params in method #102310

Dirbaio opened this issue Sep 26, 2022 · 3 comments · Fixed by #102334
Labels
C-bug Category: This is a bug. F-async_fn_in_trait Static async fn in traits I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Dirbaio
Copy link
Contributor

Dirbaio commented Sep 26, 2022

playground

pub trait SpiDevice {
    async fn transaction<F, R>(&mut self);
}

impl SpiDevice for () {
    async fn transaction<F, R>(&mut self) {}
}

gives

error: internal compiler error: compiler/rustc_middle/src/ty/subst.rs:674:9: expected type for `R/#1` (R/1) but found Lifetime(ReFree(DefId(0:11 ~ embedded_hal_async[dae4]::spi::{impl#0}::transaction), BrNamed(DefId(0:16 ~ embedded_hal_async[dae4]::spi::SpiDevice::transaction::'_), '_))) when substituting, substs=[R, ReFree(DefId(0:11 ~ embedded_hal_async[dae4]::spi::{impl#0}::transaction), BrNamed(DefId(0:16 ~ embedded_hal_async[dae4]::spi::SpiDevice::transaction::'_), '_)), ReFree(DefId(0:11 ~ embedded_hal_async[dae4]::spi::{impl#0}::transaction), BrNamed(DefId(0:16 ~ embedded_hal_async[dae4]::spi::SpiDevice::transaction::'_), '_))]

full stack trace

happens with either

rustc 1.66.0-dev (21265dd)
1.66.0-nightly (2022-09-25 f5193a9)

@Dirbaio
Copy link
Contributor Author

Dirbaio commented Sep 26, 2022

@rustbot label +F-async_fn_in_traits

@Rageking8
Copy link
Contributor

@rustbot label +T-compiler +C-bug +I-ICE +requires-nightly

@Dirbaio Please use the ICE issue template for subsequent ICE issues. Thanks.

@rustbot rustbot added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 26, 2022
@compiler-errors
Copy link
Member

This is fixed by #102334

@bors bors closed this as completed in 8be3ce9 Oct 16, 2022
bors bot added a commit to rust-embedded/embedded-hal that referenced this issue Nov 23, 2022
407: async: switch to async-fn-in-traits, release v0.2.0-alpha.0 r=eldruin a=Dirbaio

Latest Rust nightlies have somewhat usable async-fn-in-trait support already! 🎉 

embassy-nrf updated here embassy-rs/embassy#974

Paprecuts encountered:

- there's this annoying error [playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=f04fca1f2a3d643c323fb49c05bd3ed3), workaround is to use the concrete type instead of `Self::Error`. This is a limitation of all `async fn`s, not just in traits, but it hits especially hard within traits, so I dunno if there's plans to improve it.

> `async fn` return type cannot contain a projection or `Self` that references lifetimes from a parent scope

- The SpiDevice trait ICEs, issue filed rust-lang/rust#102310
- default methods don't work, but there's a PR already rust-lang/rust#102308

Due to the last 2 I've left `SpiDevice` alone for now.

Co-authored-by: Dario Nieuwenhuis <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-async_fn_in_trait Static async fn in traits I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. 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.

4 participants