Skip to content

Commit

Permalink
Auto merge of #110295 - matthiaskrgr:rollup-xas29a1, r=matthiaskrgr
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Apr 13, 2023
2 parents e4dae0d + 46c6301 commit a41fc00
Show file tree
Hide file tree
Showing 41 changed files with 580 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
line: u32,
col: u32,
) -> MPlaceTy<'tcx, M::Provenance> {
let loc_details = &self.tcx.sess.opts.unstable_opts.location_detail;
let loc_details = self.tcx.sess.opts.unstable_opts.location_detail;
// This can fail if rustc runs out of memory right here. Trying to emit an error would be
// pointless, since that would require allocating more memory than these short strings.
let file = if loc_details.file {
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1226,10 +1226,11 @@ pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option<DefId>, abi: SpecAbi) ->
| AvrNonBlockingInterrupt
| CCmseNonSecureCall
| Wasm
| RustIntrinsic
| PlatformIntrinsic
| Unadjusted => false,
Rust | RustCall | RustCold => tcx.sess.panic_strategy() == PanicStrategy::Unwind,
Rust | RustCall | RustCold | RustIntrinsic => {
tcx.sess.panic_strategy() == PanicStrategy::Unwind
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_mir_transform/src/check_alignment.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::MirPass;
use rustc_hir::def_id::DefId;
use rustc_hir::lang_items::LangItem;
use rustc_index::vec::IndexVec;
use rustc_middle::mir::*;
use rustc_middle::mir::{
Expand All @@ -17,6 +18,12 @@ impl<'tcx> MirPass<'tcx> for CheckAlignment {
}

fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
// This pass emits new panics. If for whatever reason we do not have a panic
// implementation, running this pass may cause otherwise-valid code to not compile.
if tcx.lang_items().get(LangItem::PanicImpl).is_none() {
return;
}

let basic_blocks = body.basic_blocks.as_mut();
let local_decls = &mut body.local_decls;

Expand Down
62 changes: 42 additions & 20 deletions compiler/rustc_passes/src/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,13 @@ impl<'tcx> DeadVisitor<'tcx> {
.collect();

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

let parent_info = if let Some(parent_item) = parent_item {
let parent_descr = tcx.def_descr(parent_item.to_def_id());
Some(ParentInfo {
num,
descr,
parent_descr,
span: tcx.def_ident_span(parent_item).unwrap(),
})
let span = if let DefKind::Impl { .. } = tcx.def_kind(parent_item) {
tcx.def_span(parent_item)
} else {
tcx.def_ident_span(parent_item).unwrap()
};
Some(ParentInfo { num, descr, parent_descr, span })
} else {
None
};
Expand Down Expand Up @@ -800,16 +807,7 @@ impl<'tcx> DeadVisitor<'tcx> {
}

fn check_definition(&mut self, def_id: LocalDefId) {
if self.live_symbols.contains(&def_id) {
return;
}
if has_allow_dead_code_or_lang_attr(self.tcx, def_id) {
return;
}
let Some(name) = self.tcx.opt_item_name(def_id.to_def_id()) else {
return
};
if name.as_str().starts_with('_') {
if self.is_live_code(def_id) {
return;
}
match self.tcx.def_kind(def_id) {
Expand All @@ -827,6 +825,18 @@ impl<'tcx> DeadVisitor<'tcx> {
_ => {}
}
}

fn is_live_code(&self, def_id: LocalDefId) -> bool {
// if we cannot get a name for the item, then we just assume that it is
// live. I mean, we can't really emit a lint.
let Some(name) = self.tcx.opt_item_name(def_id.to_def_id()) else {
return true;
};

self.live_symbols.contains(&def_id)
|| has_allow_dead_code_or_lang_attr(self.tcx, def_id)
|| name.as_str().starts_with('_')
}
}

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

for item in module_items.items() {
if let hir::ItemKind::Impl(impl_item) = tcx.hir().item(item).kind {
let mut dead_items = Vec::new();
for item in impl_item.items {
let did = item.id.owner_id.def_id;
if !visitor.is_live_code(did) {
dead_items.push(did)
}
}
visitor.warn_multiple_dead_codes(
&dead_items,
"used",
Some(item.owner_id.def_id),
false,
);
}

if !live_symbols.contains(&item.owner_id.def_id) {
let parent = tcx.local_parent(item.owner_id.def_id);
if parent != module && !live_symbols.contains(&parent) {
Expand Down Expand Up @@ -900,10 +926,6 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalDefId) {
}
}

for impl_item in module_items.impl_items() {
visitor.check_definition(impl_item.owner_id.def_id);
}

for foreign_item in module_items.foreign_items() {
visitor.check_definition(foreign_item.owner_id.def_id);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ impl LinkerPluginLto {
}

/// The different settings that can be enabled via the `-Z location-detail` flag.
#[derive(Clone, PartialEq, Hash, Debug)]
#[derive(Copy, Clone, PartialEq, Hash, Debug)]
pub struct LocationDetail {
pub file: bool,
pub line: bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2396,8 +2396,8 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
}

if let Some(ty::subst::GenericArgKind::Type(_)) = subst.map(|subst| subst.unpack())
&& let Some(body_id) = self.tcx.hir().maybe_body_owned_by(obligation.cause.body_id)
{
let body_id = self.tcx.hir().body_owned_by(obligation.cause.body_id);
let mut expr_finder = FindExprBySpan::new(span);
expr_finder.visit_expr(&self.tcx.hir().body(body_id).value);

Expand Down
3 changes: 3 additions & 0 deletions library/core/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,12 +615,15 @@ impl<'f> Drop for VaListImpl<'f> {
extern "rust-intrinsic" {
/// Destroy the arglist `ap` after initialization with `va_start` or
/// `va_copy`.
#[rustc_nounwind]
fn va_end(ap: &mut VaListImpl<'_>);

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

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

0 comments on commit a41fc00

Please sign in to comment.