Skip to content

Commit 7afa0cc

Browse files
committed
Auto merge of #52381 - oli-obk:ty_to_def_id, r=eddyb
Remove `ty_to_def_id` fixes #52341 The uses were mostly convenience and generally "too powerful" (would also have worked for types that weren't interesting at the use site) r? @eddyb
2 parents ee8cc77 + ecab96f commit 7afa0cc

File tree

5 files changed

+20
-31
lines changed

5 files changed

+20
-31
lines changed

src/librustc/middle/dead.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -469,13 +469,9 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
469469

470470
fn should_warn_about_field(&mut self, field: &hir::StructField) -> bool {
471471
let field_type = self.tcx.type_of(self.tcx.hir.local_def_id(field.id));
472-
let is_marker_field = match field_type.ty_to_def_id() {
473-
Some(def_id) => self.tcx.lang_items().items().iter().any(|item| *item == Some(def_id)),
474-
_ => false
475-
};
476472
!field.is_positional()
477473
&& !self.symbol_is_live(field.id, None)
478-
&& !is_marker_field
474+
&& !field_type.is_phantom_data()
479475
&& !has_allow_dead_code_or_lang_attr(self.tcx, field.id, &field.attrs)
480476
}
481477

src/librustc/traits/error_reporting.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
391391
flags.push((name, Some(value)));
392392
}
393393

394-
if let Some(true) = self_ty.ty_to_def_id().map(|def_id| def_id.is_local()) {
394+
if let Some(true) = self_ty.ty_adt_def().map(|def| def.did.is_local()) {
395395
flags.push(("crate_local".to_string(), None));
396396
}
397397

@@ -775,7 +775,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
775775
}
776776
let found_trait_ty = found_trait_ref.self_ty();
777777

778-
let found_did = found_trait_ty.ty_to_def_id();
778+
let found_did = match found_trait_ty.sty {
779+
ty::TyClosure(did, _) |
780+
ty::TyForeign(did) |
781+
ty::TyFnDef(did, _) => Some(did),
782+
ty::TyAdt(def, _) => Some(def.did),
783+
_ => None,
784+
};
779785
let found_span = found_did.and_then(|did| {
780786
self.tcx.hir.span_if_local(did)
781787
}).map(|sp| self.tcx.sess.codemap().def_span(sp)); // the sp could be an fn def

src/librustc/ty/sty.rs

-11
Original file line numberDiff line numberDiff line change
@@ -1767,17 +1767,6 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
17671767
}
17681768
}
17691769

1770-
pub fn ty_to_def_id(&self) -> Option<DefId> {
1771-
match self.sty {
1772-
TyDynamic(ref tt, ..) => tt.principal().map(|p| p.def_id()),
1773-
TyAdt(def, _) => Some(def.did),
1774-
TyForeign(did) => Some(did),
1775-
TyClosure(id, _) => Some(id),
1776-
TyFnDef(id, _) => Some(id),
1777-
_ => None,
1778-
}
1779-
}
1780-
17811770
pub fn ty_adt_def(&self) -> Option<&'tcx AdtDef> {
17821771
match self.sty {
17831772
TyAdt(adt, _) => Some(adt),

src/librustc_codegen_llvm/back/write.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -399,32 +399,30 @@ impl CodegenContext {
399399
}
400400

401401
struct DiagnosticHandlers<'a> {
402-
inner: Box<(&'a CodegenContext, &'a Handler)>,
402+
data: *mut (&'a CodegenContext, &'a Handler),
403403
llcx: ContextRef,
404404
}
405405

406406
impl<'a> DiagnosticHandlers<'a> {
407407
fn new(cgcx: &'a CodegenContext,
408408
handler: &'a Handler,
409409
llcx: ContextRef) -> DiagnosticHandlers<'a> {
410-
let data = Box::new((cgcx, handler));
410+
let data = Box::into_raw(Box::new((cgcx, handler)));
411411
unsafe {
412-
let arg = &*data as &(_, _) as *const _ as *mut _;
413-
llvm::LLVMRustSetInlineAsmDiagnosticHandler(llcx, inline_asm_handler, arg);
414-
llvm::LLVMContextSetDiagnosticHandler(llcx, diagnostic_handler, arg);
415-
}
416-
DiagnosticHandlers {
417-
inner: data,
418-
llcx: llcx,
412+
llvm::LLVMRustSetInlineAsmDiagnosticHandler(llcx, inline_asm_handler, data as *mut _);
413+
llvm::LLVMContextSetDiagnosticHandler(llcx, diagnostic_handler, data as *mut _);
419414
}
415+
DiagnosticHandlers { data, llcx }
420416
}
421417
}
422418

423419
impl<'a> Drop for DiagnosticHandlers<'a> {
424420
fn drop(&mut self) {
421+
use std::ptr::null_mut;
425422
unsafe {
426-
llvm::LLVMRustSetInlineAsmDiagnosticHandler(self.llcx, inline_asm_handler, 0 as *mut _);
427-
llvm::LLVMContextSetDiagnosticHandler(self.llcx, diagnostic_handler, 0 as *mut _);
423+
llvm::LLVMRustSetInlineAsmDiagnosticHandler(self.llcx, inline_asm_handler, null_mut());
424+
llvm::LLVMContextSetDiagnosticHandler(self.llcx, diagnostic_handler, null_mut());
425+
drop(Box::from_raw(self.data));
428426
}
429427
}
430428
}

src/librustc_lint/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDebugImplementations {
591591
if self.impling_types.is_none() {
592592
let mut impls = NodeSet();
593593
cx.tcx.for_each_impl(debug, |d| {
594-
if let Some(ty_def) = cx.tcx.type_of(d).ty_to_def_id() {
595-
if let Some(node_id) = cx.tcx.hir.as_local_node_id(ty_def) {
594+
if let Some(ty_def) = cx.tcx.type_of(d).ty_adt_def() {
595+
if let Some(node_id) = cx.tcx.hir.as_local_node_id(ty_def.did) {
596596
impls.insert(node_id);
597597
}
598598
}

0 commit comments

Comments
 (0)