rust/compiler
Matthias Krüger 7e0721b798
Rollup merge of #143519 - mu001999-contrib:dead-code/impl-items, r=petrochenkov
Check assoc consts and tys later like assoc fns

This PR
1. checks assoc consts and tys later like assoc fns
2. marks assoc consts appear in poly-trait-ref live

For assoc consts, considering
```rust
#![deny(dead_code)]

trait Tr { // ERROR trait `Tr` is never used
    const I: Self;
}

struct Foo; //~ ERROR struct `Foo` is never constructed

impl Tr for Foo {
    const I: Self = Foo;
}

fn main() {}
```

Current this will produce unused `I` instead of unused `Tr` and `Foo` ([play](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=e0490d4a2d522cb70437b26e514a3d9c)), because `const I: Self = Foo;` will be added into the worklist at first:
```
error: associated constant `I` is never used
 --> src/main.rs:4:11
  |
3 | trait Tr { // ERROR trait `Tr` is never used
  |       -- associated constant in this trait
4 |     const I: Self;
  |           ^
  |
note: the lint level is defined here
 --> src/main.rs:1:9
  |
1 | #![deny(dead_code)]
  |         ^^^^^^^^^

error: could not compile `playground` (bin "playground") due to 1 previous error
```

This also happens to assoc tys, see the [new test](https://github.com/rust-lang/rust/compare/master...mu001999-contrib:rust:dead-code/impl-items?expand=1#diff-bf45fa403934a31c9d610a073ed2603d885e7e81572e8edf38b7f4e08a1f3531)

Fixes rust-lang/rust#126729

r? `````@petrochenkov`````
2025-07-13 15:15:57 +02:00
..
rustc Revert "Use workspace lints for crates in compiler/ #138084" 2025-03-10 18:12:47 +08:00
rustc_abi Auto merge of #143182 - xdoardo:more-addrspace, r=workingjubilee 2025-07-07 17:28:14 +00:00
rustc_arena Introduce Arena::try_alloc_from_iter. 2025-04-19 01:13:18 +00:00
rustc_ast compiler: rename {ast,hir}::BareFn* to FnPtr* 2025-07-06 15:03:08 -07:00
rustc_ast_ir Use -Wunused_crate_dependencies for compiler crates. 2025-03-20 08:59:43 +11:00
rustc_ast_lowering Auto merge of #143213 - dianne:lower-cond-tweaks, r=cjgillot 2025-07-13 04:20:07 +00:00
rustc_ast_passes compiler: rename {ast,hir}::BareFn* to FnPtr* 2025-07-06 15:03:08 -07:00
rustc_ast_pretty fix: Include frontmatter in -Zunpretty output 2025-07-10 10:26:02 -05:00
rustc_attr_data_structures Port #[rustc_coherence_is_core] to the new attribute system 2025-07-09 01:26:39 +03:00
rustc_attr_parsing Rollup merge of #143796 - JonathanBrouwer:fix-builtin-attribute-prefix, r=jdonszelmann 2025-07-13 07:21:21 +02:00
rustc_baked_icu_data Add unreachable_pub to RUSTC_LINT_FLAGS for compiler/ crates. 2025-03-11 13:14:21 +11:00
rustc_borrowck Expose nested bodies in rustc_borrowck::consumers 2025-07-08 19:09:14 -07:00
rustc_builtin_macros Rollup merge of #143544 - workingjubilee:rename-bare-fn, r=fmease 2025-07-07 03:26:09 +02:00
rustc_codegen_cranelift Add opaque TypeId handles for CTFE 2025-07-09 16:37:11 +00:00
rustc_codegen_gcc Auto merge of #142911 - mejrs:unsized, r=compiler-errors 2025-07-11 05:27:32 +00:00
rustc_codegen_llvm Rollup merge of #143633 - dillona:noinline-assert, r=fee1-dead 2025-07-11 19:45:23 +02:00
rustc_codegen_ssa Auto merge of #143810 - matthiaskrgr:rollup-iw7a23z, r=matthiaskrgr 2025-07-12 10:46:43 +00:00
rustc_const_eval Avoid creating a helper allocation for creating new TypeId values in the interpreter 2025-07-09 16:37:11 +00:00
rustc_data_structures Fix wrong cache event query key 2025-07-07 15:16:42 +02:00
rustc_driver Remove recursion_limit increases. 2025-04-02 16:25:27 +11:00
rustc_driver_impl Rollup merge of #143019 - danielframpton:codegen-backend-parse, r=bjorn3 2025-06-30 20:49:40 +02:00
rustc_error_codes compiler: Trim the misleading C of C-cmse from errors 2025-06-25 00:52:10 -07:00
rustc_error_messages Remove unused feature gates 2025-06-28 23:36:46 +00:00
rustc_errors Rollup merge of #143661 - Muscraft:other-suggestion-message, r=estebank 2025-07-11 07:35:20 +02:00
rustc_expand mbe: Refactor the diagnostic for unrecognized metavariable expressions 2025-07-09 21:11:09 -04:00
rustc_feature Auto merge of #143214 - camsteffen:remove-let-chains-feature, r=est31 2025-07-02 17:18:47 +00:00
rustc_fluent_macro Remove all unused feature gates from the compiler 2025-06-08 14:50:42 +00:00
rustc_fs_util Retry if creating temp fails with access denied 2025-04-25 11:28:36 +00:00
rustc_graphviz Remove #![warn(unreachable_pub)] from all compiler/ crates. 2025-03-11 13:14:21 +11:00
rustc_hashes Revert "Use workspace lints for crates in compiler/ #138084" 2025-03-10 18:12:47 +08:00
rustc_hir Add opaque TypeId handles for CTFE 2025-07-09 16:37:11 +00:00
rustc_hir_analysis Auto merge of #143213 - dianne:lower-cond-tweaks, r=cjgillot 2025-07-13 04:20:07 +00:00
rustc_hir_pretty compiler: rename {ast,hir}::BareFn* to FnPtr* 2025-07-06 15:03:08 -07:00
rustc_hir_typeck Auto merge of #143213 - dianne:lower-cond-tweaks, r=cjgillot 2025-07-13 04:20:07 +00:00
rustc_incremental Auto merge of #139758 - Zoxc:thread-local-graph, r=oli-obk 2025-05-07 12:39:54 +00:00
rustc_index use div_ceil instead of manual logic 2025-07-05 10:55:42 +02:00
rustc_index_macros In rustc_mir_tranform, iterate over index newtypes instead of ints 2025-04-12 11:53:07 +00:00
rustc_infer Remove unused allow attrs 2025-07-07 12:58:16 +00:00
rustc_interface Save metadata among work products. 2025-07-04 14:02:17 +00:00
rustc_lexer test(lexer): Add frontmatter unit test 2025-07-10 10:25:29 -05:00
rustc_lint Auto merge of #140717 - mejrs:diagnostic_lints, r=oli-obk 2025-07-13 01:11:56 +00:00
rustc_lint_defs Auto merge of #140717 - mejrs:diagnostic_lints, r=oli-obk 2025-07-13 01:11:56 +00:00
rustc_llvm awhile -> a while where appropriate 2025-07-02 20:17:29 +02:00
rustc_log Add documentation for init_logger_with_additional_layer 2025-06-12 12:11:15 +02:00
rustc_macros Fix line break after ":" in unpretty attribute print 2025-07-06 09:51:47 +02:00
rustc_metadata Clean up implementation of RPITIT assoc item lowering 2025-07-12 19:31:15 +00:00
rustc_middle Clean up implementation of RPITIT assoc item lowering 2025-07-12 19:31:15 +00:00
rustc_mir_build Auto merge of #143472 - dianne:deref-pat-column-check, r=Nadrieril 2025-07-09 09:45:36 +00:00
rustc_mir_dataflow Remove support for SwitchInt edge effects in backward dataflow analyses 2025-07-11 10:56:50 +02:00
rustc_mir_transform Propagate from borrowed locals in CopyProp 2025-07-10 09:36:20 +02:00
rustc_monomorphize Add opaque TypeId handles for CTFE 2025-07-09 16:37:11 +00:00
rustc_next_trait_solver Don't compress input universes 2025-07-05 18:41:59 +00:00
rustc_parse Rollup merge of #143403 - GrigorenkoPV:attributes/traits, r=jdonszelmann 2025-07-11 19:45:22 +02:00
rustc_parse_format update to literal-escaper 0.0.4 for better API without unreachable and faster string parsing 2025-06-23 06:36:22 +00:00
rustc_passes Rollup merge of #143519 - mu001999-contrib:dead-code/impl-items, r=petrochenkov 2025-07-13 15:15:57 +02:00
rustc_pattern_analysis only check for mixed deref/normal constructors when needed 2025-07-04 23:47:31 -07:00
rustc_privacy Reorder fields in hir::ItemKind variants. 2025-05-30 02:23:20 +10:00
rustc_proc_macro update to literal-escaper 0.0.4 for better API without unreachable and faster string parsing 2025-06-23 06:36:22 +00:00
rustc_query_impl Remove unused allow attrs 2025-07-07 12:58:16 +00:00
rustc_query_system use is_multiple_of instead of manual modulo 2025-07-05 10:55:35 +02:00
rustc_resolve Auto merge of #140717 - mejrs:diagnostic_lints, r=oli-obk 2025-07-13 01:11:56 +00:00
rustc_sanitizers Remove support for dyn* 2025-07-01 19:00:21 +00:00
rustc_serialize use div_ceil instead of manual logic 2025-07-05 10:55:42 +02:00
rustc_session stabilize -Clink-self-contained=-linker on x64 linux 2025-07-08 09:21:35 +00:00
rustc_smir Auto merge of #143182 - xdoardo:more-addrspace, r=workingjubilee 2025-07-07 17:28:14 +00:00
rustc_span Auto merge of #143213 - dianne:lower-cond-tweaks, r=cjgillot 2025-07-13 04:20:07 +00:00
rustc_symbol_mangling Remove support for dyn* 2025-07-01 19:00:21 +00:00
rustc_target stabilize -Clinker-features=-lld on x64 linux 2025-07-08 09:04:21 +00:00
rustc_thread_pool Correct comments. 2025-06-28 17:58:21 +08:00
rustc_trait_selection Auto merge of #140717 - mejrs:diagnostic_lints, r=oli-obk 2025-07-13 01:11:56 +00:00
rustc_traits Remove fast path from codegen_select, since Sized has no methods 2025-07-02 00:33:06 +00:00
rustc_transmute compiler: Parse p- specs in datalayout string, allow definition of custom default data address space 2025-07-07 09:04:53 +02:00
rustc_ty_utils Clean up implementation of RPITIT assoc item lowering 2025-07-12 19:31:15 +00:00
rustc_type_ir setup CI and tidy to use typos for spellchecking and fix few typos 2025-07-03 10:51:06 +03:00
rustc_type_ir_macros Split TypeFolder and FallibleTypeFolder 2025-04-15 18:30:35 +00:00
stable_mir Add opaque TypeId handles for CTFE 2025-07-09 16:37:11 +00:00