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
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ symbols! {
PartialEq,
PartialOrd,
Pending,
PhantomPinned,
PinDerefMutHelper,
Pointer,
Poll,
Expand Down
1 change: 1 addition & 0 deletions library/core/src/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,7 @@ pub auto trait Unpin {}
// will likely eventually be deprecated, and all new code should be using `UnsafePinned` instead.
#[stable(feature = "pin", since = "1.33.0")]
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[rustc_diagnostic_item = "PhantomPinned"]
pub struct PhantomPinned;

#[stable(feature = "pin", since = "1.33.0")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ fn check_struct<'tcx>(
.filter_map(|field| {
if field_accesses.contains(&field.ident.name)
|| field.ty.basic_res().is_lang_item(cx, LangItem::PhantomData)
|| field.ty.basic_res().is_diag_item(cx, sym::PhantomPinned)
{
None
} else {
Expand Down
4 changes: 3 additions & 1 deletion src/tools/clippy/clippy_lints/src/pub_underscore_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use clippy_utils::res::{MaybeDef, MaybeResPath};
use rustc_hir::{FieldDef, Item, ItemKind, LangItem};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::impl_lint_pass;
use rustc_span::sym;

declare_clippy_lint! {
/// ### What it does
Expand Down Expand Up @@ -75,8 +76,9 @@ impl<'tcx> LateLintPass<'tcx> for PubUnderscoreFields {
if field.ident.as_str().starts_with('_') && is_visible(field)
// We ignore fields that have `#[doc(hidden)]`.
&& !is_doc_hidden(cx.tcx.hir_attrs(field.hir_id))
// We ignore fields that are `PhantomData`.
// We ignore fields that are `PhantomData` and `PhantomPinned`.
&& !field.ty.basic_res().is_lang_item(cx, LangItem::PhantomData)
&& !field.ty.basic_res().is_diag_item(cx, sym::PhantomPinned)
{
span_lint_hir_and_then(
cx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,47 @@ LL | pub _b: u8,
= help: to override `-D warnings` add `#[allow(clippy::pub_underscore_fields)]`

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

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

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

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

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

error: field marked as public but also inferred as unused because it's prefixed with `_`
--> tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs:63:9
--> tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs:64:9
|
LL | pub(crate) _b: Option<String>,
| ^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#![allow(unused)]
#![warn(clippy::pub_underscore_fields)]

use std::marker::PhantomData;
use std::marker::{PhantomData, PhantomPinned};

pub mod inner {
use std::marker;
Expand All @@ -16,6 +16,7 @@ pub mod inner {
//~^ pub_underscore_fields
_c: i32,
pub _mark: marker::PhantomData<u8>,
pub _pinned: marker::PhantomPinned,
}

mod inner2 {
Expand Down Expand Up @@ -69,6 +70,7 @@ fn main() {
r#pub: bool,
_pub: String,
pub(crate) _mark: PhantomData<u8>,
pub(crate) _pinned: PhantomPinned,
}

// shouldn't warn when `#[allow]` is used on field level
Expand Down
12 changes: 7 additions & 5 deletions src/tools/clippy/tests/ui/missing_fields_in_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![warn(clippy::missing_fields_in_debug)]

use std::fmt;
use std::marker::PhantomData;
use std::marker::{PhantomData, PhantomPinned};
use std::ops::Deref;
use std::thread::LocalKey;

Expand Down Expand Up @@ -179,16 +179,18 @@ mod comment1175473620 {
}

// https://github.com/rust-lang/rust-clippy/pull/10616#discussion_r1175488757
Comment thread
asder8215 marked this conversation as resolved.
// PhantomData is an exception and does not need to be included
struct WithPD {
// https://github.com/rust-lang/rust/issues/154888
// PhantomData & PhantomPinned are exceptions and do not need to be included
struct WithPDPP {
a: u8,
b: u8,
c: PhantomData<String>,
d: PhantomPinned,
}

impl fmt::Debug for WithPD {
impl fmt::Debug for WithPDPP {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("WithPD")
f.debug_struct("WithPDPP")
.field("a", &self.a)
.field("b", &self.b)
.finish()
Expand Down
Loading