Rollup merge of #129034 - henryksloan:coroutine-must-use, r=joboet
Add `#[must_use]` attribute to `Coroutine` trait [Coroutines tracking issue](https://github.com/rust-lang/rust/issues/43122) Like closures (`FnOnce`, `AsyncFn`, etc.), coroutines are lazy and do nothing unless called (resumed). Closure traits like `FnOnce` have `#[must_use = "closures are lazy and do nothing unless called"]` to catch likely bugs for users of APIs that produce them. This PR adds such a `#[must_use]` attribute to `trait Coroutine`.
This commit is contained in:
commit
d4f5a89f6e
2 changed files with 4 additions and 2 deletions
|
@ -69,6 +69,7 @@ pub enum CoroutineState<Y, R> {
|
||||||
#[lang = "coroutine"]
|
#[lang = "coroutine"]
|
||||||
#[unstable(feature = "coroutine_trait", issue = "43122")]
|
#[unstable(feature = "coroutine_trait", issue = "43122")]
|
||||||
#[fundamental]
|
#[fundamental]
|
||||||
|
#[must_use = "coroutines are lazy and do nothing unless resumed"]
|
||||||
pub trait Coroutine<R = ()> {
|
pub trait Coroutine<R = ()> {
|
||||||
/// The type of value this coroutine yields.
|
/// The type of value this coroutine yields.
|
||||||
///
|
///
|
||||||
|
|
|
@ -13,7 +13,8 @@ impl Database {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_connection(&self) -> impl Coroutine<Yield = (), Return = ()> + '_ {
|
fn check_connection(&self) -> impl Coroutine<Yield = (), Return = ()> + '_ {
|
||||||
#[coroutine] move || {
|
#[coroutine]
|
||||||
|
move || {
|
||||||
let iter = self.get_connection();
|
let iter = self.get_connection();
|
||||||
for i in iter {
|
for i in iter {
|
||||||
yield i
|
yield i
|
||||||
|
@ -23,5 +24,5 @@ impl Database {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
Database.check_connection();
|
let _ = Database.check_connection();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue