Skip to content

Commit

Permalink
run cargo bless
Browse files Browse the repository at this point in the history
  • Loading branch information
rmehri01 committed Jan 23, 2025
1 parent 1b4025b commit dc0d159
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tests/ui/async_yields_async.fixed
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![warn(clippy::async_yields_async)]
#![allow(clippy::redundant_async_block)]
#![allow(clippy::redundant_async_block, clippy::missing_must_use_on_future_types)]

use core::future::Future;
use core::pin::Pin;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async_yields_async.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![warn(clippy::async_yields_async)]
#![allow(clippy::redundant_async_block)]
#![allow(clippy::redundant_async_block, clippy::missing_must_use_on_future_types)]

use core::future::Future;
use core::pin::Pin;
Expand Down
1 change: 1 addition & 0 deletions tests/ui/crashes/ice-13862.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![crate_type = "lib"]
#![no_std]
#![allow(clippy::missing_must_use_on_future_types)]

use core::future::Future;
use core::pin::Pin;
Expand Down
118 changes: 118 additions & 0 deletions tests/ui/missing_must_use_on_future_types.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#![warn(clippy::missing_must_use_on_future_types)]
#![allow(path_statements, unused, clippy::no_effect)]

use std::fmt::Display;
use std::future::Future;
use std::marker::PhantomData;
use std::pin::Pin;
use std::task::{Context, Poll};

// basic struct case
#[must_use]
struct BasicStruct;

impl Future for BasicStruct {
type Output = ();

fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
Poll::Ready(())
}
}

// basic enum case
#[must_use]
enum BasicEnum {
Var1,
Var2,
}

impl Future for BasicEnum {
type Output = ();

fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
Poll::Ready(())
}
}

// should be ignored if type doesn't implement `Future`
struct NonFuture;

// should still trigger if a type only sometimes implements `Future`
#[must_use]
struct SometimesFuture<T>(PhantomData<T>);

impl<T: Copy> Future for SometimesFuture<T> {
type Output = ();

fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
Poll::Ready(())
}
}

// should be ignored on trait objects
trait Trait {}

impl Future for dyn Trait {
type Output = ();

fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
Poll::Ready(())
}
}

struct TraitImpl {}
impl Trait for TraitImpl {}

fn trait_obj() -> Box<dyn Trait> {
Box::new(TraitImpl {})
}

// struct with multiple fields and impls
#[derive(Debug)]
#[must_use]
pub struct ComplexStruct {
x: usize,
y: &'static str,
}

impl ComplexStruct {
fn sum(&self) -> usize {
self.x + self.y.len()
}
}

impl Display for ComplexStruct {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "complex")
}
}

impl Future for ComplexStruct {
type Output = ();

fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
Poll::Ready(())
}
}

// should be ignored on already #[must_use] struct
#[must_use]
struct AlreadyMustUse;

impl Future for AlreadyMustUse {
type Output = ();

fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
Poll::Ready(())
}
}

fn main() {
BasicStruct;
BasicEnum::Var2;
NonFuture;
SometimesFuture::<String>(PhantomData);
trait_obj();
ComplexStruct { x: 42, y: "complex" };
AlreadyMustUse;
}
52 changes: 52 additions & 0 deletions tests/ui/missing_must_use_on_future_types.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
error: this struct implements `Future` but is missing a `#[must_use]` attribute
--> tests/ui/missing_must_use_on_future_types.rs:11:1
|
LL | struct BasicStruct;
| ^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::missing-must-use-on-future-types` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::missing_must_use_on_future_types)]`
help: add the attribute
|
LL + #[must_use]
LL | struct BasicStruct;
|

error: this struct implements `Future` but is missing a `#[must_use]` attribute
--> tests/ui/missing_must_use_on_future_types.rs:22:1
|
LL | enum BasicEnum {
| ^^^^^^^^^^^^^^
|
help: add the attribute
|
LL + #[must_use]
LL | enum BasicEnum {
|

error: this struct implements `Future` but is missing a `#[must_use]` attribute
--> tests/ui/missing_must_use_on_future_types.rs:39:1
|
LL | struct SometimesFuture<T>(PhantomData<T>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: add the attribute
|
LL + #[must_use]
LL | struct SometimesFuture<T>(PhantomData<T>);
|

error: this struct implements `Future` but is missing a `#[must_use]` attribute
--> tests/ui/missing_must_use_on_future_types.rs:69:1
|
LL | pub struct ComplexStruct {
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
help: add the attribute
|
LL + #[must_use]
LL | pub struct ComplexStruct {
|

error: aborting due to 4 previous errors

0 comments on commit dc0d159

Please sign in to comment.