Skip to content

Commit

Permalink
add test for pinned must_use pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
max-niederman committed Nov 19, 2023
1 parent 173b950 commit c5ed7b0
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/ui/lint/unused/must_use-pin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#![deny(unused_must_use)]

use std::{ops::Deref, pin::Pin};

#[must_use]
struct MustUse;

#[must_use]
struct MustUsePtr<'a, T>(&'a T);

impl<'a, T> Deref for MustUsePtr<'a, T> {
type Target = T;

fn deref(&self) -> &Self::Target {
self.0
}
}

fn pin_ref() -> Pin<&'static ()> {
Pin::new(&())
}

fn pin_ref_mut() -> Pin<&'static mut ()> {
Pin::new(unimplemented!())
}

fn pin_must_use_ptr() -> Pin<MustUsePtr<'static, ()>> {
Pin::new(MustUsePtr(&()))
}

fn pin_box() -> Pin<Box<()>> {
Box::pin(())
}

fn pin_box_must_use() -> Pin<Box<MustUse>> {
Box::pin(MustUse)
}

fn main() {
pin_ref();
pin_ref_mut();
pin_must_use_ptr(); //~ ERROR unused pinned `MustUsePtr` that must be used
pin_box();
pin_box_must_use(); //~ ERROR unused pinned boxed `MustUse` that must be used
}
20 changes: 20 additions & 0 deletions tests/ui/lint/unused/must_use-pin.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error: unused pinned `MustUsePtr` that must be used
--> $DIR/must_use-pin.rs:42:5
|
LL | pin_must_use_ptr();
| ^^^^^^^^^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/must_use-pin.rs:1:9
|
LL | #![deny(unused_must_use)]
| ^^^^^^^^^^^^^^^

error: unused pinned boxed `MustUse` that must be used
--> $DIR/must_use-pin.rs:44:5
|
LL | pin_box_must_use();
| ^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

0 comments on commit c5ed7b0

Please sign in to comment.