about summary refs log tree commit diff
path: root/tests/ui/const-generics
diff options
context:
space:
mode:
authorTrevor Gross <t.gross35@gmail.com>2025-06-20 23:25:55 -0400
committerGitHub <noreply@github.com>2025-06-20 23:25:55 -0400
commitc93fac7d64394c6b926d863c1903d2e91fd2e41d (patch)
treeede03935161542a7cded6910189cba25c3f88e26 /tests/ui/const-generics
parent8751016e20ff13f36327ec1527448522e8dc7247 (diff)
parent52167e04e62a84fe5073c4074733c72f96961ace (diff)
downloadrust-c93fac7d64394c6b926d863c1903d2e91fd2e41d.tar.gz
rust-c93fac7d64394c6b926d863c1903d2e91fd2e41d.zip
Rollup merge of #142485 - mu001999-contrib:dead-code/adt-pattern, r=petrochenkov
Marks ADT live if it appears in pattern

Marks ADT live if it appears in pattern, it implies the construction of the ADT.
1. Then we can detect unused private ADTs impl `Default`, without special logics for `Default` and other std traits.
2. We can also remove `rustc_trivial_field_reads` on `Default`, and the logic in `should_ignore_item` (introduced by rust-lang/rust#126302).

Fixes rust-lang/rust#120770

Extracted from rust-lang/rust#128637.
r? `@petrochenkov`
Diffstat (limited to 'tests/ui/const-generics')
-rw-r--r--tests/ui/const-generics/issues/issue-86535-2.rs2
-rw-r--r--tests/ui/const-generics/issues/issue-86535-2.stderr10
-rw-r--r--tests/ui/const-generics/issues/issue-86535.rs2
-rw-r--r--tests/ui/const-generics/issues/issue-86535.stderr10
4 files changed, 22 insertions, 2 deletions
diff --git a/tests/ui/const-generics/issues/issue-86535-2.rs b/tests/ui/const-generics/issues/issue-86535-2.rs
index 8d064f3eeb1..5c9132fe54d 100644
--- a/tests/ui/const-generics/issues/issue-86535-2.rs
+++ b/tests/ui/const-generics/issues/issue-86535-2.rs
@@ -9,7 +9,7 @@ pub trait Foo {
         [(); Self::ASSOC_C]:;
 }
 
-struct Bar<const N: &'static ()>;
+struct Bar<const N: &'static ()>; //~ WARN struct `Bar` is never constructed
 impl<const N: &'static ()> Foo for Bar<N> {
     const ASSOC_C: usize = 3;
 
diff --git a/tests/ui/const-generics/issues/issue-86535-2.stderr b/tests/ui/const-generics/issues/issue-86535-2.stderr
new file mode 100644
index 00000000000..0ba74836575
--- /dev/null
+++ b/tests/ui/const-generics/issues/issue-86535-2.stderr
@@ -0,0 +1,10 @@
+warning: struct `Bar` is never constructed
+  --> $DIR/issue-86535-2.rs:12:8
+   |
+LL | struct Bar<const N: &'static ()>;
+   |        ^^^
+   |
+   = note: `#[warn(dead_code)]` on by default
+
+warning: 1 warning emitted
+
diff --git a/tests/ui/const-generics/issues/issue-86535.rs b/tests/ui/const-generics/issues/issue-86535.rs
index 62454f4a388..2cdf801c156 100644
--- a/tests/ui/const-generics/issues/issue-86535.rs
+++ b/tests/ui/const-generics/issues/issue-86535.rs
@@ -2,7 +2,7 @@
 #![feature(adt_const_params, unsized_const_params, generic_const_exprs)]
 #![allow(incomplete_features, unused_variables)]
 
-struct F<const S: &'static str>;
+struct F<const S: &'static str>; //~ WARN struct `F` is never constructed
 impl<const S: &'static str> X for F<{ S }> {
     const W: usize = 3;
 
diff --git a/tests/ui/const-generics/issues/issue-86535.stderr b/tests/ui/const-generics/issues/issue-86535.stderr
new file mode 100644
index 00000000000..84d6c1c11ff
--- /dev/null
+++ b/tests/ui/const-generics/issues/issue-86535.stderr
@@ -0,0 +1,10 @@
+warning: struct `F` is never constructed
+  --> $DIR/issue-86535.rs:5:8
+   |
+LL | struct F<const S: &'static str>;
+   |        ^
+   |
+   = note: `#[warn(dead_code)]` on by default
+
+warning: 1 warning emitted
+