Resolve async fn signature even without body (in trait)
This commit is contained in:
parent
6580010551
commit
59c4a92baf
@ -789,9 +789,8 @@ fn visit_fn(&mut self, fn_kind: FnKind<'ast>, sp: Span, fn_id: NodeId) {
|
||||
let previous_value = self.diagnostic_metadata.current_function;
|
||||
match fn_kind {
|
||||
// Bail if the function is foreign, and thus cannot validly have
|
||||
// a body, or if there's no body for some other reason.
|
||||
FnKind::Fn(FnCtxt::Foreign, _, sig, _, generics, _)
|
||||
| FnKind::Fn(_, _, sig, _, generics, None) => {
|
||||
// a body.
|
||||
FnKind::Fn(FnCtxt::Foreign, _, sig, _, generics, _) => {
|
||||
self.visit_fn_header(&sig.header);
|
||||
self.visit_generics(generics);
|
||||
self.with_lifetime_rib(
|
||||
|
46
src/test/ui/async-await/in-trait/issue-102138.rs
Normal file
46
src/test/ui/async-await/in-trait/issue-102138.rs
Normal file
@ -0,0 +1,46 @@
|
||||
// check-pass
|
||||
// edition:2021
|
||||
|
||||
#![feature(async_fn_in_trait)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
use std::future::Future;
|
||||
|
||||
async fn yield_now() {}
|
||||
|
||||
trait AsyncIterator {
|
||||
type Item;
|
||||
async fn next(&mut self) -> Option<Self::Item>;
|
||||
}
|
||||
|
||||
struct YieldingRange {
|
||||
counter: u32,
|
||||
stop: u32,
|
||||
}
|
||||
|
||||
impl AsyncIterator for YieldingRange {
|
||||
type Item = u32;
|
||||
|
||||
async fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.counter == self.stop {
|
||||
None
|
||||
} else {
|
||||
let c = self.counter;
|
||||
self.counter += 1;
|
||||
yield_now().await;
|
||||
Some(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn async_main() {
|
||||
let mut x = YieldingRange { counter: 0, stop: 10 };
|
||||
|
||||
while let Some(v) = x.next().await {
|
||||
println!("Hi: {v}");
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _ = async_main();
|
||||
}
|
46
src/test/ui/async-await/issue-102138.rs
Normal file
46
src/test/ui/async-await/issue-102138.rs
Normal file
@ -0,0 +1,46 @@
|
||||
// check-pass
|
||||
// edition:2021
|
||||
|
||||
#![feature(return_position_impl_trait_in_trait)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
use std::future::Future;
|
||||
|
||||
async fn yield_now() {}
|
||||
|
||||
trait AsyncIterator {
|
||||
type Item;
|
||||
async fn next(&mut self) -> Option<Self::Item>;
|
||||
}
|
||||
|
||||
struct YieldingRange {
|
||||
counter: u32,
|
||||
stop: u32,
|
||||
}
|
||||
|
||||
impl AsyncIterator for YieldingRange {
|
||||
type Item = u32;
|
||||
|
||||
async fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.counter == self.stop {
|
||||
None
|
||||
} else {
|
||||
let c = self.counter;
|
||||
self.counter += 1;
|
||||
yield_now().await;
|
||||
Some(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn async_main() {
|
||||
let mut x = YieldingRange { counter: 0, stop: 10 };
|
||||
|
||||
while let Some(v) = x.next().await {
|
||||
println!("Hi: {v}");
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _ = async_main();
|
||||
}
|
@ -2,5 +2,5 @@ fn main() {}
|
||||
|
||||
trait Foo {
|
||||
fn fn_with_type_named_same_as_local_in_param(b: b);
|
||||
//~^ ERROR cannot find type `b` in this scope [E0412]
|
||||
//~^ ERROR expected type, found local variable `b`
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
error[E0412]: cannot find type `b` in this scope
|
||||
error[E0573]: expected type, found local variable `b`
|
||||
--> $DIR/issue-69401-trait-fn-no-body-ty-local.rs:4:53
|
||||
|
|
||||
LL | fn fn_with_type_named_same_as_local_in_param(b: b);
|
||||
| ^ not found in this scope
|
||||
| ^ not a type
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0412`.
|
||||
For more information about this error, try `rustc --explain E0573`.
|
||||
|
Loading…
Reference in New Issue
Block a user