diff options
| author | bors <bors@rust-lang.org> | 2018-07-15 10:29:00 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-07-15 10:29:00 +0000 |
| commit | 7afa0ccb37a3006ef3cedbdd60da4febee41500b (patch) | |
| tree | 0a57bdfca85695ee6e1c7bf443a93440bd113571 /src | |
| parent | ee8cc77b32e5480c92b0259347f32f9a4bef6f92 (diff) | |
| parent | ecab96fd7ce9991218145a9e0063ef3c25c7a977 (diff) | |
| download | rust-7afa0ccb37a3006ef3cedbdd60da4febee41500b.tar.gz rust-7afa0ccb37a3006ef3cedbdd60da4febee41500b.zip | |
Auto merge of #52381 - oli-obk:ty_to_def_id, r=eddyb
Remove `ty_to_def_id` fixes https://github.com/rust-lang/rust/issues/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
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/middle/dead.rs | 6 | ||||
| -rw-r--r-- | src/librustc/traits/error_reporting.rs | 10 | ||||
| -rw-r--r-- | src/librustc/ty/sty.rs | 11 | ||||
| -rw-r--r-- | src/librustc_codegen_llvm/back/write.rs | 20 | ||||
| -rw-r--r-- | src/librustc_lint/builtin.rs | 4 |
5 files changed, 20 insertions, 31 deletions
diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 42775e3a183..180469a5d84 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -469,13 +469,9 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> { fn should_warn_about_field(&mut self, field: &hir::StructField) -> bool { let field_type = self.tcx.type_of(self.tcx.hir.local_def_id(field.id)); - let is_marker_field = match field_type.ty_to_def_id() { - Some(def_id) => self.tcx.lang_items().items().iter().any(|item| *item == Some(def_id)), - _ => false - }; !field.is_positional() && !self.symbol_is_live(field.id, None) - && !is_marker_field + && !field_type.is_phantom_data() && !has_allow_dead_code_or_lang_attr(self.tcx, field.id, &field.attrs) } diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index e5559b7012d..a5caacea986 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -391,7 +391,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { flags.push((name, Some(value))); } - if let Some(true) = self_ty.ty_to_def_id().map(|def_id| def_id.is_local()) { + if let Some(true) = self_ty.ty_adt_def().map(|def| def.did.is_local()) { flags.push(("crate_local".to_string(), None)); } @@ -775,7 +775,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { } let found_trait_ty = found_trait_ref.self_ty(); - let found_did = found_trait_ty.ty_to_def_id(); + let found_did = match found_trait_ty.sty { + ty::TyClosure(did, _) | + ty::TyForeign(did) | + ty::TyFnDef(did, _) => Some(did), + ty::TyAdt(def, _) => Some(def.did), + _ => None, + }; let found_span = found_did.and_then(|did| { self.tcx.hir.span_if_local(did) }).map(|sp| self.tcx.sess.codemap().def_span(sp)); // the sp could be an fn def diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index f93da53e043..934bf9a416a 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -1767,17 +1767,6 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> { } } - pub fn ty_to_def_id(&self) -> Option<DefId> { - match self.sty { - TyDynamic(ref tt, ..) => tt.principal().map(|p| p.def_id()), - TyAdt(def, _) => Some(def.did), - TyForeign(did) => Some(did), - TyClosure(id, _) => Some(id), - TyFnDef(id, _) => Some(id), - _ => None, - } - } - pub fn ty_adt_def(&self) -> Option<&'tcx AdtDef> { match self.sty { TyAdt(adt, _) => Some(adt), diff --git a/src/librustc_codegen_llvm/back/write.rs b/src/librustc_codegen_llvm/back/write.rs index 99daf4b0ed6..2179999125b 100644 --- a/src/librustc_codegen_llvm/back/write.rs +++ b/src/librustc_codegen_llvm/back/write.rs @@ -399,7 +399,7 @@ impl CodegenContext { } struct DiagnosticHandlers<'a> { - inner: Box<(&'a CodegenContext, &'a Handler)>, + data: *mut (&'a CodegenContext, &'a Handler), llcx: ContextRef, } @@ -407,24 +407,22 @@ impl<'a> DiagnosticHandlers<'a> { fn new(cgcx: &'a CodegenContext, handler: &'a Handler, llcx: ContextRef) -> DiagnosticHandlers<'a> { - let data = Box::new((cgcx, handler)); + let data = Box::into_raw(Box::new((cgcx, handler))); unsafe { - let arg = &*data as &(_, _) as *const _ as *mut _; - llvm::LLVMRustSetInlineAsmDiagnosticHandler(llcx, inline_asm_handler, arg); - llvm::LLVMContextSetDiagnosticHandler(llcx, diagnostic_handler, arg); - } - DiagnosticHandlers { - inner: data, - llcx: llcx, + llvm::LLVMRustSetInlineAsmDiagnosticHandler(llcx, inline_asm_handler, data as *mut _); + llvm::LLVMContextSetDiagnosticHandler(llcx, diagnostic_handler, data as *mut _); } + DiagnosticHandlers { data, llcx } } } impl<'a> Drop for DiagnosticHandlers<'a> { fn drop(&mut self) { + use std::ptr::null_mut; unsafe { - llvm::LLVMRustSetInlineAsmDiagnosticHandler(self.llcx, inline_asm_handler, 0 as *mut _); - llvm::LLVMContextSetDiagnosticHandler(self.llcx, diagnostic_handler, 0 as *mut _); + llvm::LLVMRustSetInlineAsmDiagnosticHandler(self.llcx, inline_asm_handler, null_mut()); + llvm::LLVMContextSetDiagnosticHandler(self.llcx, diagnostic_handler, null_mut()); + drop(Box::from_raw(self.data)); } } } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index e48009c16d2..0b33e397d18 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -591,8 +591,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDebugImplementations { if self.impling_types.is_none() { let mut impls = NodeSet(); cx.tcx.for_each_impl(debug, |d| { - if let Some(ty_def) = cx.tcx.type_of(d).ty_to_def_id() { - if let Some(node_id) = cx.tcx.hir.as_local_node_id(ty_def) { + if let Some(ty_def) = cx.tcx.type_of(d).ty_adt_def() { + if let Some(node_id) = cx.tcx.hir.as_local_node_id(ty_def.did) { impls.insert(node_id); } } |
