From dc0d1590b7493f070af8d516307149093942e9a5 Mon Sep 17 00:00:00 2001 From: Ryan Mehri Date: Wed, 22 Jan 2025 21:00:40 -0800 Subject: [PATCH] run `cargo bless` --- tests/ui/async_yields_async.fixed | 2 +- tests/ui/async_yields_async.rs | 2 +- tests/ui/crashes/ice-13862.rs | 1 + .../ui/missing_must_use_on_future_types.fixed | 118 ++++++++++++++++++ .../missing_must_use_on_future_types.stderr | 52 ++++++++ 5 files changed, 173 insertions(+), 2 deletions(-) create mode 100644 tests/ui/missing_must_use_on_future_types.fixed create mode 100644 tests/ui/missing_must_use_on_future_types.stderr diff --git a/tests/ui/async_yields_async.fixed b/tests/ui/async_yields_async.fixed index 48402164a827..ecfeefe5a6a6 100644 --- a/tests/ui/async_yields_async.fixed +++ b/tests/ui/async_yields_async.fixed @@ -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; diff --git a/tests/ui/async_yields_async.rs b/tests/ui/async_yields_async.rs index 8ad016b6bb4e..3bb6588270f3 100644 --- a/tests/ui/async_yields_async.rs +++ b/tests/ui/async_yields_async.rs @@ -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; diff --git a/tests/ui/crashes/ice-13862.rs b/tests/ui/crashes/ice-13862.rs index a5f010054b2f..911cfb876dbd 100644 --- a/tests/ui/crashes/ice-13862.rs +++ b/tests/ui/crashes/ice-13862.rs @@ -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; diff --git a/tests/ui/missing_must_use_on_future_types.fixed b/tests/ui/missing_must_use_on_future_types.fixed new file mode 100644 index 000000000000..b64fbac29947 --- /dev/null +++ b/tests/ui/missing_must_use_on_future_types.fixed @@ -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 { + 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 { + 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(PhantomData); + +impl Future for SometimesFuture { + type Output = (); + + fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll { + 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 { + Poll::Ready(()) + } +} + +struct TraitImpl {} +impl Trait for TraitImpl {} + +fn trait_obj() -> Box { + 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 { + 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 { + Poll::Ready(()) + } +} + +fn main() { + BasicStruct; + BasicEnum::Var2; + NonFuture; + SometimesFuture::(PhantomData); + trait_obj(); + ComplexStruct { x: 42, y: "complex" }; + AlreadyMustUse; +} diff --git a/tests/ui/missing_must_use_on_future_types.stderr b/tests/ui/missing_must_use_on_future_types.stderr new file mode 100644 index 000000000000..4b17d90de741 --- /dev/null +++ b/tests/ui/missing_must_use_on_future_types.stderr @@ -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(PhantomData); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: add the attribute + | +LL + #[must_use] +LL | struct SometimesFuture(PhantomData); + | + +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 +