Skip to content

derive Debug diagnostics with type parameters add test#154251

Open
JumpiiX wants to merge 1 commit intorust-lang:mainfrom
JumpiiX:fix-52560-derive-debug-diagnostics
Open

derive Debug diagnostics with type parameters add test#154251
JumpiiX wants to merge 1 commit intorust-lang:mainfrom
JumpiiX:fix-52560-derive-debug-diagnostics

Conversation

@JumpiiX
Copy link

@JumpiiX JumpiiX commented Mar 23, 2026

CC #52560

This PR adds a test for improved derive Debug diagnostics when type parameters are incorrectly assumed to need Debug bounds.

What this PR does:

  • Adds test file tests/ui/derives/derive-debug-type-param-issue-52560.rs
  • Adds expected stderr output tests/ui/derives/derive-debug-type-param-issue-52560.stderr
  • Tests the improved diagnostic that points to the derive macro as the source of the bound

The test verifies that the compiler correctly identifies when derive Debug incorrectly requires type parameter bounds when only associated types are
actually used.

r? rust-lang/compiler

Tests improved diagnostics when derive Debug incorrectly assumes
type parameters need Debug bound when only associated types are used.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 23, 2026
@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu-llvm-21-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
Executing "/scripts/stage_2_test_set1.sh"
+ /scripts/stage_2_test_set1.sh
PR_CI_JOB set; skipping tidy
+ '[' 1 == 1 ']'
+ echo 'PR_CI_JOB set; skipping tidy'
+ SKIP_TIDY='--skip tidy'
+ ../x.py --stage 2 test --skip tidy --skip compiler --skip src
##[group]Building bootstrap
    Finished `dev` profile [unoptimized] target(s) in 0.04s
##[endgroup]
downloading https://static.rust-lang.org/dist/2026-03-05/rustfmt-nightly-aarch64-unknown-linux-gnu.tar.xz
---
test [ui] tests/ui/zero-sized/zero-sized-btreemap-insert.rs ... ok

failures:

---- [ui] tests/ui/derives/derive-debug-type-param-issue-52560.rs stdout ----
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/derives/derive-debug-type-param-issue-52560/derive-debug-type-param-issue-52560.stderr`
diff of stderr:

7    |               required by this formatting parameter
8    |
9 note: required for `Foo<B>` to implement `Debug`
-   --> $DIR/derive-debug-type-param-issue-52560.rs:6:10
+   --> $DIR/derive-debug-type-param-issue-52560.rs:7:8
11    |
12 LL | #[derive(Debug)]
-    |          ^^^^^ unsatisfied trait bound introduced in this `derive` macro
+    |          ----- in this derive macro expansion
+ LL | struct Foo<B: Bar>(B::Item);
+    |        ^^^ - type parameter would need to implement `Debug`
+    = help: consider manually implementing `Debug` to avoid undesired bounds
14 help: consider further restricting type parameter `B` with trait `Debug`
15    |
16 LL | fn foo<B: Bar + std::fmt::Debug>(f: Foo<B>) {

19 error: aborting due to 1 previous error
20 
21 For more information about this error, try `rustc --explain E0277`.
+ 

Note: some mismatched output was normalized before being compared
-   --> /checkout/tests/ui/derives/derive-debug-type-param-issue-52560.rs:7:8
+   --> $DIR/derive-debug-type-param-issue-52560.rs:7:8
+    |          ----- in this derive macro expansion
+ LL | struct Foo<B: Bar>(B::Item);
+    |        ^^^ - type parameter would need to implement `Debug`
+    = help: consider manually implementing `Debug` to avoid undesired bounds
+ 


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args derives/derive-debug-type-param-issue-52560.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/derives/derive-debug-type-param-issue-52560.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/derives/derive-debug-type-param-issue-52560" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error[E0277]: `B` doesn't implement `Debug`
##[error]  --> /checkout/tests/ui/derives/derive-debug-type-param-issue-52560.rs:14:22
   |
LL |     println!("{:?}", f); //~ ERROR `B` doesn't implement `Debug`
   |               ----   ^ `B` cannot be formatted using `{:?}` because it doesn't implement `Debug`
   |               |
   |               required by this formatting parameter
   |
note: required for `Foo<B>` to implement `Debug`
  --> /checkout/tests/ui/derives/derive-debug-type-param-issue-52560.rs:7:8
   |
LL | #[derive(Debug)]
   |          ----- in this derive macro expansion
LL | struct Foo<B: Bar>(B::Item);
   |        ^^^ - type parameter would need to implement `Debug`
   = help: consider manually implementing `Debug` to avoid undesired bounds
help: consider further restricting type parameter `B` with trait `Debug`
   |
LL | fn foo<B: Bar + std::fmt::Debug>(f: Foo<B>) {
   |               +++++++++++++++++

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.

@Kivooeo Kivooeo assigned Kivooeo and unassigned mati865 Mar 23, 2026
@estebank
Copy link
Contributor

You need to rebless the stderr file. It looks like you might have modified the test after blessing it for the first time.

This PR can't close that ticket, there's one outstanding case that needs to be handled.

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

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants