Skip to content

Commit dc0d159

Browse files
committed
run cargo bless
1 parent 1b4025b commit dc0d159

5 files changed

+173
-2
lines changed

tests/ui/async_yields_async.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![warn(clippy::async_yields_async)]
2-
#![allow(clippy::redundant_async_block)]
2+
#![allow(clippy::redundant_async_block, clippy::missing_must_use_on_future_types)]
33

44
use core::future::Future;
55
use core::pin::Pin;

tests/ui/async_yields_async.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![warn(clippy::async_yields_async)]
2-
#![allow(clippy::redundant_async_block)]
2+
#![allow(clippy::redundant_async_block, clippy::missing_must_use_on_future_types)]
33

44
use core::future::Future;
55
use core::pin::Pin;

tests/ui/crashes/ice-13862.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![crate_type = "lib"]
22
#![no_std]
3+
#![allow(clippy::missing_must_use_on_future_types)]
34

45
use core::future::Future;
56
use core::pin::Pin;
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#![warn(clippy::missing_must_use_on_future_types)]
2+
#![allow(path_statements, unused, clippy::no_effect)]
3+
4+
use std::fmt::Display;
5+
use std::future::Future;
6+
use std::marker::PhantomData;
7+
use std::pin::Pin;
8+
use std::task::{Context, Poll};
9+
10+
// basic struct case
11+
#[must_use]
12+
struct BasicStruct;
13+
14+
impl Future for BasicStruct {
15+
type Output = ();
16+
17+
fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
18+
Poll::Ready(())
19+
}
20+
}
21+
22+
// basic enum case
23+
#[must_use]
24+
enum BasicEnum {
25+
Var1,
26+
Var2,
27+
}
28+
29+
impl Future for BasicEnum {
30+
type Output = ();
31+
32+
fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
33+
Poll::Ready(())
34+
}
35+
}
36+
37+
// should be ignored if type doesn't implement `Future`
38+
struct NonFuture;
39+
40+
// should still trigger if a type only sometimes implements `Future`
41+
#[must_use]
42+
struct SometimesFuture<T>(PhantomData<T>);
43+
44+
impl<T: Copy> Future for SometimesFuture<T> {
45+
type Output = ();
46+
47+
fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
48+
Poll::Ready(())
49+
}
50+
}
51+
52+
// should be ignored on trait objects
53+
trait Trait {}
54+
55+
impl Future for dyn Trait {
56+
type Output = ();
57+
58+
fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
59+
Poll::Ready(())
60+
}
61+
}
62+
63+
struct TraitImpl {}
64+
impl Trait for TraitImpl {}
65+
66+
fn trait_obj() -> Box<dyn Trait> {
67+
Box::new(TraitImpl {})
68+
}
69+
70+
// struct with multiple fields and impls
71+
#[derive(Debug)]
72+
#[must_use]
73+
pub struct ComplexStruct {
74+
x: usize,
75+
y: &'static str,
76+
}
77+
78+
impl ComplexStruct {
79+
fn sum(&self) -> usize {
80+
self.x + self.y.len()
81+
}
82+
}
83+
84+
impl Display for ComplexStruct {
85+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
86+
write!(f, "complex")
87+
}
88+
}
89+
90+
impl Future for ComplexStruct {
91+
type Output = ();
92+
93+
fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
94+
Poll::Ready(())
95+
}
96+
}
97+
98+
// should be ignored on already #[must_use] struct
99+
#[must_use]
100+
struct AlreadyMustUse;
101+
102+
impl Future for AlreadyMustUse {
103+
type Output = ();
104+
105+
fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
106+
Poll::Ready(())
107+
}
108+
}
109+
110+
fn main() {
111+
BasicStruct;
112+
BasicEnum::Var2;
113+
NonFuture;
114+
SometimesFuture::<String>(PhantomData);
115+
trait_obj();
116+
ComplexStruct { x: 42, y: "complex" };
117+
AlreadyMustUse;
118+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
error: this struct implements `Future` but is missing a `#[must_use]` attribute
2+
--> tests/ui/missing_must_use_on_future_types.rs:11:1
3+
|
4+
LL | struct BasicStruct;
5+
| ^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `-D clippy::missing-must-use-on-future-types` implied by `-D warnings`
8+
= help: to override `-D warnings` add `#[allow(clippy::missing_must_use_on_future_types)]`
9+
help: add the attribute
10+
|
11+
LL + #[must_use]
12+
LL | struct BasicStruct;
13+
|
14+
15+
error: this struct implements `Future` but is missing a `#[must_use]` attribute
16+
--> tests/ui/missing_must_use_on_future_types.rs:22:1
17+
|
18+
LL | enum BasicEnum {
19+
| ^^^^^^^^^^^^^^
20+
|
21+
help: add the attribute
22+
|
23+
LL + #[must_use]
24+
LL | enum BasicEnum {
25+
|
26+
27+
error: this struct implements `Future` but is missing a `#[must_use]` attribute
28+
--> tests/ui/missing_must_use_on_future_types.rs:39:1
29+
|
30+
LL | struct SometimesFuture<T>(PhantomData<T>);
31+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
32+
|
33+
help: add the attribute
34+
|
35+
LL + #[must_use]
36+
LL | struct SometimesFuture<T>(PhantomData<T>);
37+
|
38+
39+
error: this struct implements `Future` but is missing a `#[must_use]` attribute
40+
--> tests/ui/missing_must_use_on_future_types.rs:69:1
41+
|
42+
LL | pub struct ComplexStruct {
43+
| ^^^^^^^^^^^^^^^^^^^^^^^^
44+
|
45+
help: add the attribute
46+
|
47+
LL + #[must_use]
48+
LL | pub struct ComplexStruct {
49+
|
50+
51+
error: aborting due to 4 previous errors
52+

0 commit comments

Comments
 (0)