forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#56677 - aelred:must-use-on-traits, r=estebank
#[must_use] on traits in stdlib Based on rust-lang#55506. Adds `#[must_use]` attribute to traits in the stdlib: - `Iterator` - `Future` - `FnOnce` - `Fn` - `FnMut` There may be other traits that should have the attribute, but I couldn't find/think of any.
- Loading branch information
Showing
4 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#![deny(unused_must_use)] | ||
#![feature(futures_api, pin, arbitrary_self_types)] | ||
|
||
use std::iter::Iterator; | ||
use std::future::Future; | ||
|
||
use std::task::{Poll, LocalWaker}; | ||
use std::pin::Pin; | ||
use std::unimplemented; | ||
|
||
struct MyFuture; | ||
|
||
impl Future for MyFuture { | ||
type Output = u32; | ||
|
||
fn poll(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll<u32> { | ||
Poll::Pending | ||
} | ||
} | ||
|
||
fn iterator() -> impl Iterator { | ||
std::iter::empty::<u32>() | ||
} | ||
|
||
fn future() -> impl Future { | ||
MyFuture | ||
} | ||
|
||
fn square_fn_once() -> impl FnOnce(u32) -> u32 { | ||
|x| x * x | ||
} | ||
|
||
fn square_fn_mut() -> impl FnMut(u32) -> u32 { | ||
|x| x * x | ||
} | ||
|
||
fn square_fn() -> impl Fn(u32) -> u32 { | ||
|x| x * x | ||
} | ||
|
||
fn main() { | ||
iterator(); //~ ERROR unused implementer of `std::iter::Iterator` that must be used | ||
future(); //~ ERROR unused implementer of `std::future::Future` that must be used | ||
square_fn_once(); //~ ERROR unused implementer of `std::ops::FnOnce` that must be used | ||
square_fn_mut(); //~ ERROR unused implementer of `std::ops::FnMut` that must be used | ||
square_fn(); //~ ERROR unused implementer of `std::ops::Fn` that must be used | ||
} |