Skip to content

Commit 68bcbdf

Browse files
committed
Added PhantomPinned diagnostic item and prevented dead field warning on PhantomPinned
1 parent d2f2412 commit 68bcbdf

7 files changed

Lines changed: 19 additions & 11 deletions

File tree

‎compiler/rustc_span/src/symbol.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ symbols! {
267267
PartialEq,
268268
PartialOrd,
269269
Pending,
270+
PhantomPinned,
270271
PinDerefMutHelper,
271272
Pointer,
272273
Poll,

‎library/core/src/marker.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,7 @@ pub auto trait Unpin {}
10231023
// will likely eventually be deprecated, and all new code should be using `UnsafePinned` instead.
10241024
#[stable(feature = "pin", since = "1.33.0")]
10251025
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1026+
#[rustc_diagnostic_item = "PhantomPinned"]
10261027
pub struct PhantomPinned;
10271028

10281029
#[stable(feature = "pin", since = "1.33.0")]

‎src/tools/clippy/clippy_lints/src/missing_fields_in_debug.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ fn check_struct<'tcx>(
185185
.filter_map(|field| {
186186
if field_accesses.contains(&field.ident.name)
187187
|| field.ty.basic_res().is_lang_item(cx, LangItem::PhantomData)
188+
|| field.ty.basic_res().is_diag_item(cx, sym::PhantomPinned)
188189
{
189190
None
190191
} else {

‎src/tools/clippy/clippy_lints/src/pub_underscore_fields.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use clippy_utils::res::{MaybeDef, MaybeResPath};
66
use rustc_hir::{FieldDef, Item, ItemKind, LangItem};
77
use rustc_lint::{LateContext, LateLintPass};
88
use rustc_session::impl_lint_pass;
9+
use rustc_span::sym;
910

1011
declare_clippy_lint! {
1112
/// ### What it does
@@ -77,6 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for PubUnderscoreFields {
7778
&& !is_doc_hidden(cx.tcx.hir_attrs(field.hir_id))
7879
// We ignore fields that are `PhantomData`.
7980
&& !field.ty.basic_res().is_lang_item(cx, LangItem::PhantomData)
81+
&& !field.ty.basic_res().is_diag_item(cx, sym::PhantomPinned)
8082
{
8183
span_lint_hir_and_then(
8284
cx,

‎src/tools/clippy/tests/ui-toml/pub_underscore_fields/pub_underscore_fields.all_pub_fields.stderr‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,47 @@ LL | pub _b: u8,
99
= help: to override `-D warnings` add `#[allow(clippy::pub_underscore_fields)]`
1010

1111
error: field marked as public but also inferred as unused because it's prefixed with `_`
12-
--> tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs:24:13
12+
--> tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs:25:13
1313
|
1414
LL | pub(in crate::inner) _f: Option<()>,
1515
| ^^^^^^^^^^^^^^^^^^^^^^^
1616
|
1717
= help: consider removing the underscore, or making the field private
1818

1919
error: field marked as public but also inferred as unused because it's prefixed with `_`
20-
--> tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs:29:13
20+
--> tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs:30:13
2121
|
2222
LL | pub _g: String,
2323
| ^^^^^^
2424
|
2525
= help: consider removing the underscore, or making the field private
2626

2727
error: field marked as public but also inferred as unused because it's prefixed with `_`
28-
--> tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs:37:9
28+
--> tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs:38:9
2929
|
3030
LL | pub _a: usize,
3131
| ^^^^^^
3232
|
3333
= help: consider removing the underscore, or making the field private
3434

3535
error: field marked as public but also inferred as unused because it's prefixed with `_`
36-
--> tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs:45:9
36+
--> tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs:46:9
3737
|
3838
LL | pub _c: i64,
3939
| ^^^^^^
4040
|
4141
= help: consider removing the underscore, or making the field private
4242

4343
error: field marked as public but also inferred as unused because it's prefixed with `_`
44-
--> tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs:49:9
44+
--> tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs:50:9
4545
|
4646
LL | pub _e: Option<u8>,
4747
| ^^^^^^
4848
|
4949
= help: consider removing the underscore, or making the field private
5050

5151
error: field marked as public but also inferred as unused because it's prefixed with `_`
52-
--> tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs:63:9
52+
--> tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs:64:9
5353
|
5454
LL | pub(crate) _b: Option<String>,
5555
| ^^^^^^^^^^^^^

‎src/tools/clippy/tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#![allow(unused)]
66
#![warn(clippy::pub_underscore_fields)]
77

8-
use std::marker::PhantomData;
8+
use std::marker::{PhantomData, PhantomPinned};
99

1010
pub mod inner {
1111
use std::marker;
@@ -16,6 +16,7 @@ pub mod inner {
1616
//~^ pub_underscore_fields
1717
_c: i32,
1818
pub _mark: marker::PhantomData<u8>,
19+
pub _pinned: marker::PhantomPinned,
1920
}
2021

2122
mod inner2 {
@@ -69,6 +70,7 @@ fn main() {
6970
r#pub: bool,
7071
_pub: String,
7172
pub(crate) _mark: PhantomData<u8>,
73+
pub(crate) _pinned: PhantomPinned,
7274
}
7375

7476
// shouldn't warn when `#[allow]` is used on field level

‎src/tools/clippy/tests/ui/missing_fields_in_debug.rs‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![warn(clippy::missing_fields_in_debug)]
33

44
use std::fmt;
5-
use std::marker::PhantomData;
5+
use std::marker::{PhantomData, PhantomPinned};
66
use std::ops::Deref;
77
use std::thread::LocalKey;
88

@@ -179,14 +179,15 @@ mod comment1175473620 {
179179
}
180180

181181
// https://github.com/rust-lang/rust-clippy/pull/10616#discussion_r1175488757
182-
// PhantomData is an exception and does not need to be included
183-
struct WithPD {
182+
// PhantomData & PhantomPinned is an exception and does not need to be included
183+
struct WithPDPP {
184184
a: u8,
185185
b: u8,
186186
c: PhantomData<String>,
187+
d: PhantomPinned,
187188
}
188189

189-
impl fmt::Debug for WithPD {
190+
impl fmt::Debug for WithPDPP {
190191
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
191192
f.debug_struct("WithPD")
192193
.field("a", &self.a)

0 commit comments

Comments
 (0)