Skip to content

Commit f2b044e

Browse files
committed
Auto merge of #156254 - JonathanBrouwer:rollup-u4Djp8E, r=JonathanBrouwer
Rollup of 9 pull requests Successful merges: - #156061 (Support `-Cpanic=unwind` on WASI targets) - #146273 (lint ImproperCTypes: refactor linting architecture (part 2)) - #149509 (Lint unused pub items in binary crates) - #156173 (Fewer global node_id_to_def_id lookups) - #155961 (Deny warnings in the test for crates that are available on stable) - #155981 (Use special DefIds for aliases) - #156130 (Fold/visit tweaks) - #156131 (Metadata macro/query cleanups) - #156202 (llvm: Use correct type for splat mask) Failed merges: - #156236 (resolve: Remove `MacroData`)
2 parents 365c0e1 + b4c4bbe commit f2b044e

73 files changed

Lines changed: 1159 additions & 545 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,7 +2086,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
20862086
}
20872087

20882088
if name == sym::simd_splat {
2089-
let (_out_len, out_ty) = require_simd!(ret_ty, SimdReturn);
2089+
let (out_len, out_ty) = require_simd!(ret_ty, SimdReturn);
20902090

20912091
require!(
20922092
args[0].layout.ty == out_ty,
@@ -2105,7 +2105,8 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
21052105

21062106
// `shufflevector <N x elem> v0, <N x elem> poison, <N x i32> zeroinitializer`
21072107
// The masks is all zeros, so this splats lane 0 (which has our element in it).
2108-
let splat = bx.shuffle_vector(v0, poison_vec, bx.const_null(llret_ty));
2108+
let mask_ty = bx.type_vector(bx.type_i32(), out_len);
2109+
let splat = bx.shuffle_vector(v0, poison_vec, bx.const_null(mask_ty));
21092110

21102111
return Ok(splat);
21112112
}

compiler/rustc_lint/src/types/improper_ctypes.rs

Lines changed: 172 additions & 114 deletions
Large diffs are not rendered by default.

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ declare_lint_pass! {
3434
CONST_EVALUATABLE_UNCHECKED,
3535
CONST_ITEM_MUTATION,
3636
DEAD_CODE,
37+
DEAD_CODE_PUB_IN_BINARY,
3738
DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK,
3839
DEPRECATED,
3940
DEPRECATED_IN_FUTURE,
@@ -789,6 +790,37 @@ declare_lint! {
789790
"detect unused, unexported items"
790791
}
791792

793+
declare_lint! {
794+
/// The `dead_code_pub_in_binary` lint detects unused `pub` items in
795+
/// executable crates.
796+
///
797+
/// ### Example
798+
///
799+
/// ```rust
800+
/// #![deny(dead_code_pub_in_binary)]
801+
///
802+
/// pub fn unused_pub_fn() {}
803+
///
804+
/// fn main() {}
805+
/// ```
806+
///
807+
/// {{produces}}
808+
///
809+
/// ### Explanation
810+
///
811+
/// In executable crates, `pub` items are often implementation details
812+
/// rather than part of an external API. This lint helps find those items
813+
/// when they are never used.
814+
///
815+
/// This lint only applies to executable crates. In library crates, public
816+
/// items are considered part of the crate's API and are not reported by
817+
/// this lint.
818+
pub DEAD_CODE_PUB_IN_BINARY,
819+
Allow,
820+
"detect public items in executable crates that are never used",
821+
crate_level_only
822+
}
823+
792824
declare_lint! {
793825
/// The `unused_attributes` lint detects attributes that were not used by
794826
/// the compiler.

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ provide! { tcx, def_id, other, cdata,
261261
.coerce_unsized_info
262262
.get(cdata, def_id.index)
263263
.map(|lazy| lazy.decode((cdata, tcx)))
264-
.process_decoded(tcx, || panic!("{def_id:?} does not have coerce_unsized_info"))) }
264+
.process_decoded(tcx, || panic!("{def_id:?} does not have coerce_unsized_info")))
265+
}
265266
mir_const_qualif => { table }
266267
rendered_const => { table }
267268
rendered_precise_capturing_args => { table }
@@ -300,10 +301,10 @@ provide! { tcx, def_id, other, cdata,
300301
Ok(cdata
301302
.root
302303
.tables
303-
.trait_impl_trait_tys
304+
.collect_return_position_impl_trait_in_trait_tys
304305
.get(cdata, def_id.index)
305306
.map(|lazy| lazy.decode((cdata, tcx)))
306-
.process_decoded(tcx, || panic!("{def_id:?} does not have trait_impl_trait_tys")))
307+
.process_decoded(tcx, || panic!("{def_id:?} does not have collect_return_position_impl_trait_in_trait_tys")))
307308
}
308309

309310
associated_types_for_impl_traits_in_trait_or_impl => { table }
@@ -695,6 +696,7 @@ impl CrateStore for CStore {
695696
fn as_any(&self) -> &dyn Any {
696697
self
697698
}
699+
698700
fn untracked_as_any(&mut self) -> &mut dyn Any {
699701
self
700702
}

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1628,7 +1628,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
16281628
if tcx.impl_method_has_trait_impl_trait_tys(def_id)
16291629
&& let Ok(table) = self.tcx.collect_return_position_impl_trait_in_trait_tys(def_id)
16301630
{
1631-
record!(self.tables.trait_impl_trait_tys[def_id] <- table);
1631+
record!(self.tables.collect_return_position_impl_trait_in_trait_tys[def_id] <- table);
16321632
}
16331633
if let DefKind::Impl { .. } | DefKind::Trait = def_kind {
16341634
let table = tcx.associated_types_for_impl_traits_in_trait_or_impl(def_id);

compiler/rustc_metadata/src/rmeta/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ define_tables! {
466466
macro_definition: Table<DefIndex, LazyValue<ast::DelimArgs>>,
467467
proc_macro: Table<DefIndex, MacroKind>,
468468
deduced_param_attrs: Table<DefIndex, LazyArray<DeducedParamAttrs>>,
469-
trait_impl_trait_tys: Table<DefIndex, LazyValue<DefIdMap<ty::EarlyBinder<'static, Ty<'static>>>>>,
469+
collect_return_position_impl_trait_in_trait_tys: Table<DefIndex, LazyValue<DefIdMap<ty::EarlyBinder<'static, Ty<'static>>>>>,
470470
doc_link_resolutions: Table<DefIndex, LazyValue<DocLinkResMap>>,
471471
doc_link_traits_in_scope: Table<DefIndex, LazyArray<DefId>>,
472472
assumed_wf_types_for_rpitit: Table<DefIndex, LazyArray<(Ty<'static>, Span)>>,

compiler/rustc_middle/src/arena.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
/// This higher-order macro declares a list of types which can be allocated by `Arena`.
22
///
33
/// Specifying the `decode` modifier will add decode impls for `&T` and `&[T]` where `T` is the type
4-
/// listed. These impls will appear in the implement_ty_decoder! macro.
4+
/// listed. See the `impl_arena_allocatable_decoder!` macro for more.
55
#[macro_export]
66
macro_rules! arena_types {
77
($macro:path) => (
88
$macro!([
99
[] layout: rustc_abi::LayoutData<rustc_abi::FieldIdx, rustc_abi::VariantIdx>,
1010
[] proxy_coroutine_layout: rustc_middle::mir::CoroutineLayout<'tcx>,
1111
[] fn_abi: rustc_target::callconv::FnAbi<'tcx, rustc_middle::ty::Ty<'tcx>>,
12-
// AdtDef are interned and compared by address
13-
[decode] adt_def: rustc_middle::ty::AdtDefData,
12+
[] adt_def: rustc_middle::ty::AdtDefData,
1413
[] steal_thir: rustc_data_structures::steal::Steal<rustc_middle::thir::Thir<'tcx>>,
1514
[] steal_mir: rustc_data_structures::steal::Steal<rustc_middle::mir::Body<'tcx>>,
1615
[decode] mir: rustc_middle::mir::Body<'tcx>,
@@ -27,7 +26,7 @@ macro_rules! arena_types {
2726
rustc_middle::mir::Body<'tcx>
2827
>,
2928
[decode] typeck_results: rustc_middle::ty::TypeckResults<'tcx>,
30-
[decode] borrowck_result: rustc_data_structures::fx::FxIndexMap<
29+
[] borrowck_result: rustc_data_structures::fx::FxIndexMap<
3130
rustc_hir::def_id::LocalDefId,
3231
rustc_middle::ty::DefinitionSiteHiddenType<'tcx>,
3332
>,
@@ -100,7 +99,7 @@ macro_rules! arena_types {
10099
// (during lowering) and the `rustc_middle` arena (for decoding MIR)
101100
[decode] asm_template: rustc_ast::InlineAsmTemplatePiece,
102101
[decode] used_trait_imports: rustc_data_structures::unord::UnordSet<rustc_hir::def_id::LocalDefId>,
103-
[decode] is_late_bound_map: rustc_data_structures::fx::FxIndexSet<rustc_hir::ItemLocalId>,
102+
[] is_late_bound_map: rustc_data_structures::fx::FxIndexSet<rustc_hir::ItemLocalId>,
104103
[decode] impl_source: rustc_middle::traits::ImplSource<'tcx, ()>,
105104

106105
[] dep_kind_vtable: rustc_middle::dep_graph::DepKindVTable<'tcx>,
@@ -111,7 +110,7 @@ macro_rules! arena_types {
111110
rustc_middle::ty::EarlyBinder<'tcx, rustc_middle::ty::Ty<'tcx>>
112111
>,
113112
[] external_constraints: rustc_middle::traits::solve::ExternalConstraintsData<rustc_middle::ty::TyCtxt<'tcx>>,
114-
[decode] doc_link_resolutions: rustc_hir::def::DocLinkResMap,
113+
[] doc_link_resolutions: rustc_hir::def::DocLinkResMap,
115114
[] stripped_cfg_items: rustc_hir::attrs::StrippedCfgItem,
116115
[] mod_child: rustc_middle::metadata::ModChild,
117116
[] features: rustc_feature::Features,
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use rustc_data_structures::fx::FxIndexSet;
2+
use rustc_hir::def_id::{DefId, LocalDefIdMap, LocalDefIdSet};
3+
use rustc_macros::StableHash;
4+
5+
/// A single snapshot of dead-code liveness analysis state.
6+
#[derive(Clone, Debug, StableHash)]
7+
pub struct DeadCodeLivenessSnapshot {
8+
pub live_symbols: LocalDefIdSet,
9+
/// Maps each ADT to derived traits (for example `Debug` and `Clone`) that should be ignored
10+
/// when checking for dead code diagnostics.
11+
pub ignored_derived_traits: LocalDefIdMap<FxIndexSet<DefId>>,
12+
}
13+
14+
/// Dead-code liveness data for both analysis phases.
15+
///
16+
/// `pre_deferred_seeding` is computed before reachable-public and `#[allow(dead_code)]` seeding,
17+
/// and is used for lint `dead_code_pub_in_binary`.
18+
/// `final_result` is the final liveness snapshot used for lint `dead_code`.
19+
#[derive(Clone, Debug, StableHash)]
20+
pub struct DeadCodeLivenessSummary {
21+
pub pre_deferred_seeding: DeadCodeLivenessSnapshot,
22+
pub final_result: DeadCodeLivenessSnapshot,
23+
}

compiler/rustc_middle/src/middle/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub mod codegen_fn_attrs;
2+
pub mod dead_code;
23
pub mod debugger_visualizer;
34
pub mod deduced_param_attrs;
45
pub mod dependency_format;

compiler/rustc_middle/src/queries.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ use rustc_errors::{ErrorGuaranteed, catch_fatal_errors};
6464
use rustc_hir as hir;
6565
use rustc_hir::attrs::{EiiDecl, EiiImpl, StrippedCfgItem};
6666
use rustc_hir::def::{DefKind, DocLinkResMap};
67-
use rustc_hir::def_id::{
68-
CrateNum, DefId, DefIdMap, LocalDefId, LocalDefIdMap, LocalDefIdSet, LocalModDefId,
69-
};
67+
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LocalDefIdSet, LocalModDefId};
7068
use rustc_hir::lang_items::{LangItem, LanguageItems};
7169
use rustc_hir::{ItemLocalId, ItemLocalMap, PreciseCapturingArgKind, TraitCandidate};
7270
use rustc_index::IndexVec;
@@ -87,6 +85,7 @@ use crate::infer::canonical::{self, Canonical};
8785
use crate::lint::LintExpectation;
8886
use crate::metadata::ModChild;
8987
use crate::middle::codegen_fn_attrs::{CodegenFnAttrs, SanitizerFnAttrs};
88+
use crate::middle::dead_code::DeadCodeLivenessSummary;
9089
use crate::middle::debugger_visualizer::DebuggerVisualizerFile;
9190
use crate::middle::deduced_param_attrs::DeducedParamAttrs;
9291
use crate::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo};
@@ -1203,13 +1202,8 @@ rustc_queries! {
12031202
desc { "checking liveness of variables in `{}`", tcx.def_path_str(key.to_def_id()) }
12041203
}
12051204

1206-
/// Return the live symbols in the crate for dead code check.
1207-
///
1208-
/// The second return value maps from ADTs to ignored derived traits (e.g. Debug and Clone).
1209-
query live_symbols_and_ignored_derived_traits(_: ()) -> Result<&'tcx (
1210-
LocalDefIdSet,
1211-
LocalDefIdMap<FxIndexSet<DefId>>,
1212-
), ErrorGuaranteed> {
1205+
/// Return dead-code liveness summary for the crate.
1206+
query live_symbols_and_ignored_derived_traits(_: ()) -> Result<&'tcx DeadCodeLivenessSummary, ErrorGuaranteed> {
12131207
arena_cache
12141208
desc { "finding live symbols in crate" }
12151209
}

0 commit comments

Comments
 (0)