Skip to content

Commit a41fc00

Browse files
committed
Auto merge of #110295 - matthiaskrgr:rollup-xas29a1, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #109036 (Fix diff option conflict in UI test) - #110193 (Check for body owner fallibly in error reporting) - #110233 (Make rust-intrinsic ABI unwindable) - #110259 (Added diagnostic for pin! macro in addition to Box::pin if Unpin isn't implemented) - #110265 (Automatically update the LLVM submodule for musl target (and other places)) - #110277 (dead-code-lint: de-dup multiple unused assoc functions) - #110283 (Only emit alignment checks if we have a panic_impl) - #110291 (Implement `Copy` for `LocationDetail`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents e4dae0d + 46c6301 commit a41fc00

Some content is hidden

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

41 files changed

+580
-103
lines changed

compiler/rustc_const_eval/src/interpret/intrinsics/caller_location.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
7777
line: u32,
7878
col: u32,
7979
) -> MPlaceTy<'tcx, M::Provenance> {
80-
let loc_details = &self.tcx.sess.opts.unstable_opts.location_detail;
80+
let loc_details = self.tcx.sess.opts.unstable_opts.location_detail;
8181
// This can fail if rustc runs out of memory right here. Trying to emit an error would be
8282
// pointless, since that would require allocating more memory than these short strings.
8383
let file = if loc_details.file {

compiler/rustc_middle/src/ty/layout.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1226,10 +1226,11 @@ pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option<DefId>, abi: SpecAbi) ->
12261226
| AvrNonBlockingInterrupt
12271227
| CCmseNonSecureCall
12281228
| Wasm
1229-
| RustIntrinsic
12301229
| PlatformIntrinsic
12311230
| Unadjusted => false,
1232-
Rust | RustCall | RustCold => tcx.sess.panic_strategy() == PanicStrategy::Unwind,
1231+
Rust | RustCall | RustCold | RustIntrinsic => {
1232+
tcx.sess.panic_strategy() == PanicStrategy::Unwind
1233+
}
12331234
}
12341235
}
12351236

compiler/rustc_mir_transform/src/check_alignment.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::MirPass;
22
use rustc_hir::def_id::DefId;
3+
use rustc_hir::lang_items::LangItem;
34
use rustc_index::vec::IndexVec;
45
use rustc_middle::mir::*;
56
use rustc_middle::mir::{
@@ -17,6 +18,12 @@ impl<'tcx> MirPass<'tcx> for CheckAlignment {
1718
}
1819

1920
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
21+
// This pass emits new panics. If for whatever reason we do not have a panic
22+
// implementation, running this pass may cause otherwise-valid code to not compile.
23+
if tcx.lang_items().get(LangItem::PanicImpl).is_none() {
24+
return;
25+
}
26+
2027
let basic_blocks = body.basic_blocks.as_mut();
2128
let local_decls = &mut body.local_decls;
2229

compiler/rustc_passes/src/dead.rs

+42-20
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,13 @@ impl<'tcx> DeadVisitor<'tcx> {
700700
.collect();
701701

702702
let descr = tcx.def_descr(first_id.to_def_id());
703+
// `impl` blocks are "batched" and (unlike other batching) might
704+
// contain different kinds of associated items.
705+
let descr = if dead_codes.iter().any(|did| tcx.def_descr(did.to_def_id()) != descr) {
706+
"associated item"
707+
} else {
708+
descr
709+
};
703710
let num = dead_codes.len();
704711
let multiple = num > 6;
705712
let name_list = names.into();
@@ -712,12 +719,12 @@ impl<'tcx> DeadVisitor<'tcx> {
712719

713720
let parent_info = if let Some(parent_item) = parent_item {
714721
let parent_descr = tcx.def_descr(parent_item.to_def_id());
715-
Some(ParentInfo {
716-
num,
717-
descr,
718-
parent_descr,
719-
span: tcx.def_ident_span(parent_item).unwrap(),
720-
})
722+
let span = if let DefKind::Impl { .. } = tcx.def_kind(parent_item) {
723+
tcx.def_span(parent_item)
724+
} else {
725+
tcx.def_ident_span(parent_item).unwrap()
726+
};
727+
Some(ParentInfo { num, descr, parent_descr, span })
721728
} else {
722729
None
723730
};
@@ -800,16 +807,7 @@ impl<'tcx> DeadVisitor<'tcx> {
800807
}
801808

802809
fn check_definition(&mut self, def_id: LocalDefId) {
803-
if self.live_symbols.contains(&def_id) {
804-
return;
805-
}
806-
if has_allow_dead_code_or_lang_attr(self.tcx, def_id) {
807-
return;
808-
}
809-
let Some(name) = self.tcx.opt_item_name(def_id.to_def_id()) else {
810-
return
811-
};
812-
if name.as_str().starts_with('_') {
810+
if self.is_live_code(def_id) {
813811
return;
814812
}
815813
match self.tcx.def_kind(def_id) {
@@ -827,6 +825,18 @@ impl<'tcx> DeadVisitor<'tcx> {
827825
_ => {}
828826
}
829827
}
828+
829+
fn is_live_code(&self, def_id: LocalDefId) -> bool {
830+
// if we cannot get a name for the item, then we just assume that it is
831+
// live. I mean, we can't really emit a lint.
832+
let Some(name) = self.tcx.opt_item_name(def_id.to_def_id()) else {
833+
return true;
834+
};
835+
836+
self.live_symbols.contains(&def_id)
837+
|| has_allow_dead_code_or_lang_attr(self.tcx, def_id)
838+
|| name.as_str().starts_with('_')
839+
}
830840
}
831841

832842
fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalDefId) {
@@ -836,6 +846,22 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalDefId) {
836846
let module_items = tcx.hir_module_items(module);
837847

838848
for item in module_items.items() {
849+
if let hir::ItemKind::Impl(impl_item) = tcx.hir().item(item).kind {
850+
let mut dead_items = Vec::new();
851+
for item in impl_item.items {
852+
let did = item.id.owner_id.def_id;
853+
if !visitor.is_live_code(did) {
854+
dead_items.push(did)
855+
}
856+
}
857+
visitor.warn_multiple_dead_codes(
858+
&dead_items,
859+
"used",
860+
Some(item.owner_id.def_id),
861+
false,
862+
);
863+
}
864+
839865
if !live_symbols.contains(&item.owner_id.def_id) {
840866
let parent = tcx.local_parent(item.owner_id.def_id);
841867
if parent != module && !live_symbols.contains(&parent) {
@@ -900,10 +926,6 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalDefId) {
900926
}
901927
}
902928

903-
for impl_item in module_items.impl_items() {
904-
visitor.check_definition(impl_item.owner_id.def_id);
905-
}
906-
907929
for foreign_item in module_items.foreign_items() {
908930
visitor.check_definition(foreign_item.owner_id.def_id);
909931
}

compiler/rustc_session/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ impl LinkerPluginLto {
222222
}
223223

224224
/// The different settings that can be enabled via the `-Z location-detail` flag.
225-
#[derive(Clone, PartialEq, Hash, Debug)]
225+
#[derive(Copy, Clone, PartialEq, Hash, Debug)]
226226
pub struct LocationDetail {
227227
pub file: bool,
228228
pub line: bool,

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2396,8 +2396,8 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
23962396
}
23972397

23982398
if let Some(ty::subst::GenericArgKind::Type(_)) = subst.map(|subst| subst.unpack())
2399+
&& let Some(body_id) = self.tcx.hir().maybe_body_owned_by(obligation.cause.body_id)
23992400
{
2400-
let body_id = self.tcx.hir().body_owned_by(obligation.cause.body_id);
24012401
let mut expr_finder = FindExprBySpan::new(span);
24022402
expr_finder.visit_expr(&self.tcx.hir().body(body_id).value);
24032403

library/core/src/ffi/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -615,12 +615,15 @@ impl<'f> Drop for VaListImpl<'f> {
615615
extern "rust-intrinsic" {
616616
/// Destroy the arglist `ap` after initialization with `va_start` or
617617
/// `va_copy`.
618+
#[rustc_nounwind]
618619
fn va_end(ap: &mut VaListImpl<'_>);
619620

620621
/// Copies the current location of arglist `src` to the arglist `dst`.
622+
#[rustc_nounwind]
621623
fn va_copy<'f>(dest: *mut VaListImpl<'f>, src: &VaListImpl<'f>);
622624

623625
/// Loads an argument of type `T` from the `va_list` `ap` and increment the
624626
/// argument `ap` points to.
627+
#[rustc_nounwind]
625628
fn va_arg<T: sealed_trait::VaArgSafe>(ap: &mut VaListImpl<'_>) -> T;
626629
}

0 commit comments

Comments
 (0)