]> git.lizzy.rs Git - rust.git/commitdiff
Remove `ty_to_def_id`
authorOliver Schneider <github35764891676564198441@oli-obk.de>
Sat, 14 Jul 2018 15:22:53 +0000 (17:22 +0200)
committerOliver Schneider <github35764891676564198441@oli-obk.de>
Sat, 14 Jul 2018 15:22:53 +0000 (17:22 +0200)
src/librustc/middle/dead.rs
src/librustc/traits/error_reporting.rs
src/librustc/ty/sty.rs
src/librustc_lint/builtin.rs

index 42775e3a1837ff4f63d1e62fb2185efec8afd8d8..180469a5d848ad4d5f099d77366da6a2717f037b 100644 (file)
@@ -469,13 +469,9 @@ fn should_warn_about_item(&mut self, item: &hir::Item) -> bool {
 
     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)
     }
 
index e5559b7012dc978145a233602ed09f59f6dbd79b..a5caacea986183a3e15245b30b414f36490f8df8 100644 (file)
@@ -391,7 +391,7 @@ fn on_unimplemented_note(
             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 @@ pub fn report_selection_error(&self,
                 }
                 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
index f93da53e0436d16f69f8ee23e76ebc737793f98d..934bf9a416a95f3e9a9f68d03a13c0976e63bd8d 100644 (file)
@@ -1767,17 +1767,6 @@ pub fn is_impl_trait(&self) -> bool {
         }
     }
 
-    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),
index d6e5c70b8f7e1b4320788cf5c83e5bfef44849c7..6149785b0485cdfab6463f6c0c50e0fbba6dbe6d 100644 (file)
@@ -591,8 +591,8 @@ fn check_item(&mut self, cx: &LateContext, item: &hir::Item) {
         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);
                     }
                 }