Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions internal/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::fmt::Display;

use proc_macro2::TokenStream;
use quote::quote_spanned;
use syn::{spanned::Spanned, Error};

pub(crate) struct DiagCtxt(TokenStream);
Expand All @@ -15,6 +16,19 @@ impl DiagCtxt {
ErrorGuaranteed(())
}

pub(crate) fn warn(&mut self, span: impl Spanned, msg: impl Display) {
// Have the message start on a new line for visual clarity.
let msg = format!("\n{}", msg);
self.0.extend(quote_spanned!(span.span() =>
// Approximate using deprecated warning while `proc_macro_diagnostic` is unstable.
const _: () = {
#[deprecated = #msg]
const fn warn() {}
warn();
};
));
}

pub(crate) fn with(
fun: impl FnOnce(&mut DiagCtxt) -> Result<TokenStream, ErrorGuaranteed>,
) -> TokenStream {
Expand Down
2 changes: 1 addition & 1 deletion internal/src/pin_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub(crate) fn pin_data(

for (pinned, field) in &fields {
if !pinned && is_phantom_pinned(&field.ty) {
dcx.error(
dcx.warn(
field,
format!(
"The field `{}` of type `PhantomPinned` only has an effect \
Expand Down
4 changes: 3 additions & 1 deletion tests/ui/compile-fail/pin_data/no_pin_on_phantompinned.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![deny(warnings)]

use pin_init::*;
// use std::marker::{self, PhantomPinned};
use std::marker::{self, PhantomPinned};

#[pin_data]
struct Foo {
Expand Down
43 changes: 27 additions & 16 deletions tests/ui/compile-fail/pin_data/no_pin_on_phantompinned.stderr
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
error: The field `pin1` of type `PhantomPinned` only has an effect if it has the `#[pin]` attribute
--> tests/ui/compile-fail/pin_data/no_pin_on_phantompinned.rs:6:5
error: use of deprecated function `_::warn`:
The field `pin1` of type `PhantomPinned` only has an effect if it has the `#[pin]` attribute
--> tests/ui/compile-fail/pin_data/no_pin_on_phantompinned.rs:8:5
|
6 | pin1: PhantomPinned,
8 | pin1: PhantomPinned,
| ^^^^^^^^^^^^^^^^^^^

error: The field `pin2` of type `PhantomPinned` only has an effect if it has the `#[pin]` attribute
--> tests/ui/compile-fail/pin_data/no_pin_on_phantompinned.rs:7:5
|
7 | pin2: marker::PhantomPinned,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: The field `pin3` of type `PhantomPinned` only has an effect if it has the `#[pin]` attribute
--> tests/ui/compile-fail/pin_data/no_pin_on_phantompinned.rs:8:5
note: the lint level is defined here
--> tests/ui/compile-fail/pin_data/no_pin_on_phantompinned.rs:1:9
|
8 | pin3: core::marker::PhantomPinned,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1 | #![deny(warnings)]
| ^^^^^^^^
= note: `#[deny(deprecated)]` implied by `#[deny(warnings)]`

error: The field `pin4` of type `PhantomPinned` only has an effect if it has the `#[pin]` attribute
error: use of deprecated function `_::warn`:
The field `pin2` of type `PhantomPinned` only has an effect if it has the `#[pin]` attribute
--> tests/ui/compile-fail/pin_data/no_pin_on_phantompinned.rs:9:5
|
9 | pin4: ::core::marker::PhantomPinned,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9 | pin2: marker::PhantomPinned,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: use of deprecated function `_::warn`:
The field `pin3` of type `PhantomPinned` only has an effect if it has the `#[pin]` attribute
--> tests/ui/compile-fail/pin_data/no_pin_on_phantompinned.rs:10:5
|
10 | pin3: core::marker::PhantomPinned,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: use of deprecated function `_::warn`:
The field `pin4` of type `PhantomPinned` only has an effect if it has the `#[pin]` attribute
--> tests/ui/compile-fail/pin_data/no_pin_on_phantompinned.rs:11:5
|
11 | pin4: ::core::marker::PhantomPinned,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^