diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2019-01-08 10:55:18 -0500 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2019-01-10 17:04:19 -0500 |
| commit | 1336b8e8c7417fdde5384119a588a11ef0818cf3 (patch) | |
| tree | 8b357440cee22e15f1ef273257d5ce6b4a7d440a /src/librustc/ty | |
| parent | 430553bc7766ecdbdb04113ef0137e6174e0dba2 (diff) | |
| download | rust-1336b8e8c7417fdde5384119a588a11ef0818cf3.tar.gz rust-1336b8e8c7417fdde5384119a588a11ef0818cf3.zip | |
integrate trait aliases into def-paths / metadata
Co-authored-by: Alexander Regueiro <alexreg@me.com>
Diffstat (limited to 'src/librustc/ty')
| -rw-r--r-- | src/librustc/ty/item_path.rs | 1 | ||||
| -rw-r--r-- | src/librustc/ty/mod.rs | 12 | ||||
| -rw-r--r-- | src/librustc/ty/util.rs | 9 |
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 a2c96e7cf9f..e2f696b0974 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -3178,18 +3178,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 { |
