Skip to content

rustc_marker_type built in attribute created to have certain marker types not trigger dead code warnings from clippy#154978

Open
asder8215 wants to merge 1 commit intorust-lang:mainfrom
asder8215:phantom_pin_dead_code
Open

rustc_marker_type built in attribute created to have certain marker types not trigger dead code warnings from clippy#154978
asder8215 wants to merge 1 commit intorust-lang:mainfrom
asder8215:phantom_pin_dead_code

Conversation

@asder8215
Copy link
Copy Markdown
Contributor

@asder8215 asder8215 commented Apr 8, 2026

This PR fixes the issue on PhantomPinned triggering field is never read warning by clippy through a built in attribute called rustc_marker_type.

A few questions I have are:

  • If a built in attribute approach is okay to use here, should I extend this attribute to all the other Phantom* types?
  • Currently, I have every change I made into 1 commit. Should I separate the changes I made for compiler and the changes I made for clippy into different commits?
  • Does a built in attribute like this have uses outside of being internal to the standard library? I'm wondering if people create marker types and wish to not have dead code warnings on them.

Note: This is my first time contributing to the compiler side of Rust repos, so I'm unsure if I'm doing anything wrong with making a built in attribute. I'm just going based off my intuition from go to references in my IDE on what everything is doing.

cc @clarfonthey

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 8, 2026

Some changes occurred in compiler/rustc_hir/src/attrs

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 8, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 8, 2026

r? @davidtwco

rustbot has assigned @davidtwco.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 69 candidates
  • Random selection from 10 candidates

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 8, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rustbot

This comment has been minimized.

@rustbot rustbot added has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 8, 2026
@asder8215 asder8215 force-pushed the phantom_pin_dead_code branch from 218306c to 2206c25 Compare April 8, 2026 06:38
@rustbot rustbot removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. has-merge-commits PR has merge commits, merge with caution. labels Apr 8, 2026
@asder8215 asder8215 force-pushed the phantom_pin_dead_code branch 2 times, most recently from 260b712 to 55627ab Compare April 8, 2026 06:42
@rust-log-analyzer

This comment has been minimized.

@asder8215 asder8215 force-pushed the phantom_pin_dead_code branch from 55627ab to 7b574a6 Compare April 8, 2026 07:28
@rust-log-analyzer

This comment has been minimized.

…ypes not trigger dead code warnings from clippy
@asder8215 asder8215 force-pushed the phantom_pin_dead_code branch from 7b574a6 to 60f81d1 Compare April 8, 2026 07:41
@rust-log-analyzer
Copy link
Copy Markdown
Collaborator

The job x86_64-gnu-tools failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
tests/ui/size_of_in_element_count/functions.rs ... ok
tests/ui/crashes/third-party/conf_allowlisted.rs ... ok

FAILED TEST: tests/ui/missing_fields_in_debug.rs
command: CLIPPY_CONF_DIR="tests" RUSTC_ICE="0" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/clippy-driver" "--error-format=json" "--emit=metadata" "-Aunused" "-Ainternal_features" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Dwarnings" "-Ldependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/release/deps" "--sysroot=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui_test/0/tests/ui" "tests/ui/missing_fields_in_debug.rs" "--extern" "futures=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libfutures-fbb2c78a4397bb08.rlib" "--extern" "futures=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libfutures-fbb2c78a4397bb08.rmeta" "--extern" "itertools=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libitertools-08cb6de3a10b25d1.rlib" "--extern" "itertools=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libitertools-08cb6de3a10b25d1.rmeta" "--extern" "libc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/liblibc-ac3195ae9071a567.rlib" "--extern" "libc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/liblibc-ac3195ae9071a567.rmeta" "--extern" "parking_lot=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libparking_lot-cb20139ff7bab978.rlib" "--extern" "parking_lot=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libparking_lot-cb20139ff7bab978.rmeta" "--extern" "quote=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libquote-d52f64f9beb2b3e9.rlib" "--extern" "quote=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libquote-d52f64f9beb2b3e9.rmeta" "--extern" "regex=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libregex-099fa7d611da1769.rlib" "--extern" "regex=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libregex-099fa7d611da1769.rmeta" "--extern" "serde=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libserde-cc2552a331d3edc6.rlib" "--extern" "serde=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libserde-cc2552a331d3edc6.rmeta" "--extern" "syn=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libsyn-6fe3ac6a29af0bce.rlib" "--extern" "syn=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libsyn-6fe3ac6a29af0bce.rmeta" "--extern" "tokio=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libtokio-115c8b7669715635.rlib" "--extern" "tokio=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libtokio-115c8b7669715635.rmeta" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/debug/deps" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps" "--edition" "2024"

error: actual output differed from expected
Execute `./x test src/tools/clippy --bless` to update `tests/ui/missing_fields_in_debug.stderr` to the actual output
--- tests/ui/missing_fields_in_debug.stderr
+++ <stderr output>
---
-error: aborting due to 3 previous errors
+error: manual `Debug` impl does not include all fields
+  --> tests/ui/missing_fields_in_debug.rs:190:1
+   |
+LL | / impl fmt::Debug for WithPDPP {
+LL | |     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+LL | |         f.debug_struct("WithPD")
+LL | |             .field("a", &self.a)
+...  |
+LL | | }
+   | |_^
+   |
+note: this field is unused
+  --> tests/ui/missing_fields_in_debug.rs:186:5
+   |
+LL |     c: PhantomPinned,
+   |     ^^^^^^^^^^^^^^^^
+note: this field is unused
+  --> tests/ui/missing_fields_in_debug.rs:187:5
+   |
+LL |     d: PhantomData<String>,
+   |     ^^^^^^^^^^^^^^^^^^^^^^
+   = help: consider including all fields in this `Debug` impl
+   = help: consider calling `.finish_non_exhaustive()` if you intend to ignore fields
 
+error: aborting due to 4 previous errors
---
   |     ^^^^^^^^^^^^^^^
note: this field is unused
  --> tests/ui/missing_fields_in_debug.rs:31:5
   |
LL |     hidden4: ((((u8), u16), u32), u64),
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = help: consider including all fields in this `Debug` impl
   = help: consider calling `.finish_non_exhaustive()` if you intend to ignore fields

error: manual `Debug` impl does not include all fields
##[error]  --> tests/ui/missing_fields_in_debug.rs:97:1
   |
LL | / impl fmt::Debug for MultiExprDebugImpl {
LL | |
LL | |
LL | |     fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
...  |
LL | | }
   | |_^
   |
note: this field is unused
---

error: manual `Debug` impl does not include all fields
##[error]  --> tests/ui/missing_fields_in_debug.rs:190:1
   |
LL | / impl fmt::Debug for WithPDPP {
LL | |     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
LL | |         f.debug_struct("WithPD")
LL | |             .field("a", &self.a)
...  |
LL | | }
   | |_^
   |
note: this field is unused
  --> tests/ui/missing_fields_in_debug.rs:186:5
   |
LL |     c: PhantomPinned,
   |     ^^^^^^^^^^^^^^^^
note: this field is unused
  --> tests/ui/missing_fields_in_debug.rs:187:5
   |
LL |     d: PhantomData<String>,
   |     ^^^^^^^^^^^^^^^^^^^^^^
   = help: consider including all fields in this `Debug` impl
   = help: consider calling `.finish_non_exhaustive()` if you intend to ignore fields

error: aborting due to 4 previous errors



error: there was 1 unmatched diagnostic
##[error]   --> tests/ui/missing_fields_in_debug.rs:190:1
    |
190 | / impl fmt::Debug for WithPDPP {
191 | |     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
...   |
196 | |     }
197 | | }
    | |_^ Error[clippy::missing_fields_in_debug]: manual `Debug` impl does not include all fields
    |

full stderr:
error: manual `Debug` impl does not include all fields
##[error]  --> tests/ui/missing_fields_in_debug.rs:14:1
---
   |     ^^^^^^^^^^^^^^^
note: this field is unused
  --> tests/ui/missing_fields_in_debug.rs:31:5
   |
LL |     hidden4: ((((u8), u16), u32), u64),
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = help: consider including all fields in this `Debug` impl
   = help: consider calling `.finish_non_exhaustive()` if you intend to ignore fields

error: manual `Debug` impl does not include all fields
##[error]  --> tests/ui/missing_fields_in_debug.rs:97:1
   |
LL | / impl fmt::Debug for MultiExprDebugImpl {
LL | |
LL | |
LL | |     fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
...  |
LL | | }
   | |_^
   |
note: this field is unused
---

error: manual `Debug` impl does not include all fields
##[error]  --> tests/ui/missing_fields_in_debug.rs:190:1
   |
LL | / impl fmt::Debug for WithPDPP {
LL | |     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
LL | |         f.debug_struct("WithPD")
LL | |             .field("a", &self.a)
...  |
LL | | }
   | |_^
   |
note: this field is unused
  --> tests/ui/missing_fields_in_debug.rs:186:5
   |
LL |     c: PhantomPinned,
   |     ^^^^^^^^^^^^^^^^
note: this field is unused
  --> tests/ui/missing_fields_in_debug.rs:187:5
   |
LL |     d: PhantomData<String>,
   |     ^^^^^^^^^^^^^^^^^^^^^^
   = help: consider including all fields in this `Debug` impl
   = help: consider calling `.finish_non_exhaustive()` if you intend to ignore fields

error: aborting due to 4 previous errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants