about summary refs log tree commit diff
path: root/src/librustc/ty
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-01-19 14:21:18 +0100
committerGitHub <noreply@github.com>2019-01-19 14:21:18 +0100
commit5272be5b5e7f7289b487d38cfbaebd18548b50be (patch)
tree5392e00013e1246f8a70520d1d44038261eb5ad1 /src/librustc/ty
parent349c9eeb355a979c2e51f832d05ce9212f0aeeba (diff)
parentb411994b3b9a571db486cb7de9ea06b071a22b6c (diff)
downloadrust-5272be5b5e7f7289b487d38cfbaebd18548b50be.tar.gz
rust-5272be5b5e7f7289b487d38cfbaebd18548b50be.zip
Rollup merge of #57502 - nikomatsakis:fix-trait-alias-1b, r=nikomatsakis
make trait-aliases work across crates

This is rebase of a small part of @alexreg's PR #55994. It focuses just on the changes that integrate trait aliases properly into crate metadata, excluding the stylistic edits and the trait objects.

The stylistic edits I also rebased and can open a separate PR.

The trait object stuff I found challenging and decided it basically needed to be reimplemented. For now I've excluded it.

Since this is really @alexreg's work (I really just rebased) I am going to make it r=me once it is working.

Fixes #56488.
Fixes #57023.
Diffstat (limited to 'src/librustc/ty')
-rw-r--r--src/librustc/ty/item_path.rs1
-rw-r--r--src/librustc/ty/mod.rs12
-rw-r--r--src/librustc/ty/util.rs9
3 files changed, 10 insertions, 12 deletions
diff --git a/src/librustc/ty/item_path.rs b/src/librustc/ty/item_path.rs
index 417e14054d2..9328de4f6a0 100644
--- a/src/librustc/ty/item_path.rs
+++ b/src/librustc/ty/item_path.rs
@@ -311,6 +311,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
             data @ DefPathData::Misc |
             data @ DefPathData::TypeNs(..) |
             data @ DefPathData::Trait(..) |
+            data @ DefPathData::TraitAlias(..) |
             data @ DefPathData::AssocTypeInTrait(..) |
             data @ DefPathData::AssocTypeInImpl(..) |
             data @ DefPathData::AssocExistentialInImpl(..) |
diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs
index f1b36e8def8..dd315cf42ce 100644
--- a/src/librustc/ty/mod.rs
+++ b/src/librustc/ty/mod.rs
@@ -3170,18 +3170,6 @@ pub fn is_impl_trait_defn(tcx: TyCtxt<'_, '_, '_>, def_id: DefId) -> Option<DefI
     None
 }
 
-/// Returns `true` if `def_id` is a trait alias.
-pub fn is_trait_alias(tcx: TyCtxt<'_, '_, '_>, def_id: DefId) -> bool {
-    if let Some(node_id) = tcx.hir().as_local_node_id(def_id) {
-        if let Node::Item(item) = tcx.hir().get(node_id) {
-            if let hir::ItemKind::TraitAlias(..) = item.node {
-                return true;
-            }
-        }
-    }
-    false
-}
-
 /// See `ParamEnv` struct definition for details.
 fn param_env<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
                        def_id: DefId)
diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs
index e989ef823e9..75fc0f716a2 100644
--- a/src/librustc/ty/util.rs
+++ b/src/librustc/ty/util.rs
@@ -526,6 +526,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
         }
     }
 
+    /// True if `def_id` refers to a trait alias (i.e., `trait Foo = ...;`).
+    pub fn is_trait_alias(self, def_id: DefId) -> bool {
+        if let DefPathData::TraitAlias(_) = self.def_key(def_id).disambiguated_data.data {
+            true
+        } else {
+            false
+        }
+    }
+
     /// True if this def-id refers to the implicit constructor for
     /// a tuple struct like `struct Foo(u32)`.
     pub fn is_struct_constructor(self, def_id: DefId) -> bool {