Closed
Description
Code
pub async fn test() {
let a = async { loop { } };
let a = std::pin::pin!(a);
use std::future::Future;
use std::pin::Pin;
use std::task::{Poll, Context};
#[allow(non_camel_case_types)]
struct Foo<'a, a> {
a: Pin<&'a mut a>,
}
#[allow(non_camel_case_types)]
impl<'a, a: Future<Output = ()>> Future for Foo<'a, a> {
type Output = ();
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
self.a.as_mut().poll(cx)
}
}
Foo { a }.await
}
Current output
Compiling playground v0.0.1 (/playground)
error[E0403]: the name `a` is already used for a generic parameter in this item's generic parameters
--> src/lib.rs:11:20
|
3 | let a = async { loop { } };
| - first use of `a`
...
11 | struct Foo<'a, a> {
| ^ already used
error[E0403]: the name `a` is already used for a generic parameter in this item's generic parameters
--> src/lib.rs:16:14
|
3 | let a = async { loop { } };
| - first use of `a`
...
16 | impl<'a, a: Future<Output = ()>> Future for Foo<'a, a> {
| ^ already used
error[E0277]: `Foo<'_, _>` is not a future
--> src/lib.rs:23:15
|
23 | Foo { a }.await
| -^^^^^
| ||
| |`Foo<'_, _>` is not a future
| help: remove the `.await`
|
= help: the trait `Future` is not implemented for `Foo<'_, _>`, which is required by `Foo<'_, _>: IntoFuture`
= note: Foo<'_, _> must be a future or must implement `IntoFuture` to be awaited
= note: required for `Foo<'_, _>` to implement `IntoFuture`
Some errors have detailed explanations: E0277, E0403.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `playground` (lib) due to 3 previous errors
Desired output
No error code raised
Rationale and extra context
This code snippet uses neither of the two error code conditions presented in https://doc.rust-lang.org/error_codes/E0403.html.
It seems that the variable name a
for the assignment let a = async { loop { test::a().await; } };
is used implicitly in the type name, which would cause the struct declaration to shadow the first declaration.
Other cases
No response
Rust Version
Nightly channel
Build using the Nightly version: 1.82.0-nightly
(2024-08-18 6de928dce9472b864f4e)
Anything else?
No response