about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorDylan MacKenzie <ecstaticmorse@gmail.com>2020-02-11 10:41:28 -0800
committerDylan MacKenzie <ecstaticmorse@gmail.com>2020-02-19 10:51:40 -0800
commit3bb7da2e4fa54519069fd110cf665cdf0407f58d (patch)
tree99cdec1179023d91cadff2e27353bf6deb2e6c66 /src
parentea3c9d27cffceb9d4c8dcfda1c96b138d7f01f3d (diff)
downloadrust-3bb7da2e4fa54519069fd110cf665cdf0407f58d.tar.gz
rust-3bb7da2e4fa54519069fd110cf665cdf0407f58d.zip
Replace `rustc_typeck::Namespace` with `rustc_hir::def::Namespace`
Diffstat (limited to 'src')
-rw-r--r--src/librustc/ty/mod.rs9
-rw-r--r--src/librustc_hir/hir.rs11
-rw-r--r--src/librustc_typeck/astconv.rs5
-rw-r--r--src/librustc_typeck/check/method/mod.rs5
-rw-r--r--src/librustc_typeck/check/method/probe.rs6
-rw-r--r--src/librustc_typeck/check/method/suggest.rs13
-rw-r--r--src/librustc_typeck/check/mod.rs2
-rw-r--r--src/librustc_typeck/coherence/inherent_impls_overlap.rs1
-rw-r--r--src/librustc_typeck/lib.rs1
-rw-r--r--src/librustc_typeck/namespace.rs27
10 files changed, 32 insertions, 48 deletions
diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs
index a4b4e1d6574..c70a296e34b 100644
--- a/src/librustc/ty/mod.rs
+++ b/src/librustc/ty/mod.rs
@@ -33,7 +33,7 @@ use rustc_data_structures::fx::FxIndexMap;
 use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
 use rustc_data_structures::sync::{self, par_iter, Lrc, ParallelIterator};
 use rustc_hir as hir;
-use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
+use rustc_hir::def::{CtorKind, CtorOf, DefKind, Namespace, Res};
 use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
 use rustc_hir::{Constness, GlobMap, Node, TraitMap};
 use rustc_index::vec::{Idx, IndexVec};
@@ -216,6 +216,13 @@ impl AssocKind {
             ty::AssocKind::Const => "associated constant",
         }
     }
+
+    pub fn namespace(&self) -> Namespace {
+        match *self {
+            ty::AssocKind::OpaqueTy | ty::AssocKind::Type => Namespace::TypeNS,
+            ty::AssocKind::Const | ty::AssocKind::Method => Namespace::ValueNS,
+        }
+    }
 }
 
 impl AssocItem {
diff --git a/src/librustc_hir/hir.rs b/src/librustc_hir/hir.rs
index 56a8e2cfd02..8496a6ed23b 100644
--- a/src/librustc_hir/hir.rs
+++ b/src/librustc_hir/hir.rs
@@ -1,4 +1,4 @@
-use crate::def::{DefKind, Res};
+use crate::def::{DefKind, Namespace, Res};
 use crate::def_id::DefId;
 crate use crate::hir_id::HirId;
 use crate::itemlikevisit;
@@ -1897,6 +1897,15 @@ pub enum ImplItemKind<'hir> {
     OpaqueTy(GenericBounds<'hir>),
 }
 
+impl ImplItemKind<'_> {
+    pub fn namespace(&self) -> Namespace {
+        match self {
+            ImplItemKind::OpaqueTy(..) | ImplItemKind::TyAlias(..) => Namespace::TypeNS,
+            ImplItemKind::Const(..) | ImplItemKind::Method(..) => Namespace::ValueNS,
+        }
+    }
+}
+
 // The name of the associated type for `Fn` return types.
 pub const FN_OUTPUT_NAME: Symbol = sym::Output;
 
diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs
index 69970faab3f..635c3038e0a 100644
--- a/src/librustc_typeck/astconv.rs
+++ b/src/librustc_typeck/astconv.rs
@@ -9,7 +9,6 @@ use crate::collect::PlaceholderHirTyCollector;
 use crate::lint;
 use crate::middle::lang_items::SizedTraitLangItem;
 use crate::middle::resolve_lifetime as rl;
-use crate::namespace::Namespace;
 use crate::require_c_abi_if_c_variadic;
 use crate::util::common::ErrorReported;
 use rustc::lint::builtin::AMBIGUOUS_ASSOCIATED_ITEMS;
@@ -20,7 +19,7 @@ use rustc::ty::{GenericParamDef, GenericParamDefKind};
 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
 use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticId};
 use rustc_hir as hir;
-use rustc_hir::def::{CtorOf, DefKind, Res};
+use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
 use rustc_hir::def_id::DefId;
 use rustc_hir::intravisit::Visitor;
 use rustc_hir::print;
@@ -2202,7 +2201,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
         let item = tcx
             .associated_items(trait_did)
             .iter()
-            .find(|i| Namespace::from(i.kind) == Namespace::Type && i.ident.modern() == assoc_ident)
+            .find(|i| i.kind.namespace() == Namespace::TypeNS && i.ident.modern() == assoc_ident)
             .expect("missing associated type");
 
         let ty = self.projected_ty_from_poly_trait_ref(span, item.def_id, assoc_segment, bound);
diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs
index 1856157fffb..84e00244942 100644
--- a/src/librustc_typeck/check/method/mod.rs
+++ b/src/librustc_typeck/check/method/mod.rs
@@ -11,7 +11,6 @@ pub use self::CandidateSource::*;
 pub use self::MethodError::*;
 
 use crate::check::FnCtxt;
-use crate::namespace::Namespace;
 use rustc::ty::subst::Subst;
 use rustc::ty::subst::{InternalSubsts, SubstsRef};
 use rustc::ty::GenericParamDefKind;
@@ -19,7 +18,7 @@ use rustc::ty::{self, ToPolyTraitRef, ToPredicate, TraitRef, Ty, TypeFoldable, W
 use rustc_data_structures::sync::Lrc;
 use rustc_errors::{Applicability, DiagnosticBuilder};
 use rustc_hir as hir;
-use rustc_hir::def::{CtorOf, DefKind};
+use rustc_hir::def::{CtorOf, DefKind, Namespace};
 use rustc_hir::def_id::DefId;
 use rustc_infer::infer::{self, InferOk};
 use rustc_infer::traits;
@@ -342,7 +341,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         // Trait must have a method named `m_name` and it should not have
         // type parameters or early-bound regions.
         let tcx = self.tcx;
-        let method_item = match self.associated_item(trait_def_id, m_name, Namespace::Value) {
+        let method_item = match self.associated_item(trait_def_id, m_name, Namespace::ValueNS) {
             Some(method_item) => method_item,
             None => {
                 tcx.sess.delay_span_bug(
diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs
index 346406fff56..5ed39f04b07 100644
--- a/src/librustc_typeck/check/method/probe.rs
+++ b/src/librustc_typeck/check/method/probe.rs
@@ -7,7 +7,6 @@ use crate::check::autoderef::{self, Autoderef};
 use crate::check::FnCtxt;
 use crate::hir::def::DefKind;
 use crate::hir::def_id::DefId;
-use crate::namespace::Namespace;
 
 use rustc::lint;
 use rustc::middle::stability;
@@ -22,6 +21,7 @@ use rustc_data_structures::fx::FxHashSet;
 use rustc_data_structures::sync::Lrc;
 use rustc_errors::struct_span_err;
 use rustc_hir as hir;
+use rustc_hir::def::Namespace;
 use rustc_infer::infer::canonical::OriginalQueryValues;
 use rustc_infer::infer::canonical::{Canonical, QueryResponse};
 use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
@@ -1699,13 +1699,13 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
                     .iter()
                     .filter(|x| {
                         let dist = lev_distance(&*name.as_str(), &x.ident.as_str());
-                        Namespace::from(x.kind) == Namespace::Value && dist > 0 && dist <= max_dist
+                        x.kind.namespace() == Namespace::ValueNS && dist > 0 && dist <= max_dist
                     })
                     .copied()
                     .collect()
             } else {
                 self.fcx
-                    .associated_item(def_id, name, Namespace::Value)
+                    .associated_item(def_id, name, Namespace::ValueNS)
                     .map_or(Vec::new(), |x| vec![x])
             }
         } else {
diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs
index 83f063aceda..ea83b40a1cb 100644
--- a/src/librustc_typeck/check/method/suggest.rs
+++ b/src/librustc_typeck/check/method/suggest.rs
@@ -3,7 +3,6 @@
 
 use crate::check::FnCtxt;
 use crate::middle::lang_items::FnOnceTraitLangItem;
-use crate::namespace::Namespace;
 use rustc::hir::map as hir_map;
 use rustc::hir::map::Map;
 use rustc::ty::print::with_crate_prefix;
@@ -11,7 +10,7 @@ use rustc::ty::{self, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, TypeFoldable, Wit
 use rustc_data_structures::fx::FxHashSet;
 use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder};
 use rustc_hir as hir;
-use rustc_hir::def::{DefKind, Res};
+use rustc_hir::def::{DefKind, Namespace, Res};
 use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
 use rustc_hir::intravisit;
 use rustc_hir::{ExprKind, Node, QPath};
@@ -97,13 +96,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                         // Provide the best span we can. Use the item, if local to crate, else
                         // the impl, if local to crate (item may be defaulted), else nothing.
                         let item = match self
-                            .associated_item(impl_did, item_name, Namespace::Value)
+                            .associated_item(impl_did, item_name, Namespace::ValueNS)
                             .or_else(|| {
                                 let impl_trait_ref = self.tcx.impl_trait_ref(impl_did)?;
                                 self.associated_item(
                                     impl_trait_ref.def_id,
                                     item_name,
-                                    Namespace::Value,
+                                    Namespace::ValueNS,
                                 )
                             }) {
                             Some(item) => item,
@@ -185,7 +184,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                     }
                     CandidateSource::TraitSource(trait_did) => {
                         let item =
-                            match self.associated_item(trait_did, item_name, Namespace::Value) {
+                            match self.associated_item(trait_did, item_name, Namespace::ValueNS) {
                                 Some(item) => item,
                                 None => continue,
                             };
@@ -264,7 +263,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                     // be used exists at all, and the type is an ambiguous numeric type
                     // ({integer}/{float}).
                     let mut candidates = all_traits(self.tcx).into_iter().filter_map(|info| {
-                        self.associated_item(info.def_id, item_name, Namespace::Value)
+                        self.associated_item(info.def_id, item_name, Namespace::ValueNS)
                     });
                     if let (true, false, SelfSource::MethodCall(expr), Some(_)) = (
                         actual.is_numeric(),
@@ -779,7 +778,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                 // here).
                 (type_is_local || info.def_id.is_local())
                     && self
-                        .associated_item(info.def_id, item_name, Namespace::Value)
+                        .associated_item(info.def_id, item_name, Namespace::ValueNS)
                         .filter(|item| {
                             // We only want to suggest public or local traits (#45781).
                             item.vis == ty::Visibility::Public || info.def_id.is_local()
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index f7145140401..d6acd8dd894 100644
--- a/src/librustc_typeck/check/mod.rs
+++ b/src/librustc_typeck/check/mod.rs
@@ -89,7 +89,6 @@ pub mod writeback;
 
 use crate::astconv::{AstConv, PathSeg};
 use crate::middle::lang_items;
-use crate::namespace::Namespace;
 use rustc::hir::map::blocks::FnLikeNode;
 use rustc::hir::map::Map;
 use rustc::middle::region;
@@ -1972,6 +1971,7 @@ fn check_impl_items_against_trait<'tcx>(
     // Check existing impl methods to see if they are both present in trait
     // and compatible with trait signature
     for impl_item in impl_items() {
+        let namespace = impl_item.kind.namespace();
         let ty_impl_item = tcx.associated_item(tcx.hir().local_def_id(impl_item.hir_id));
         let ty_trait_item = tcx
             .associated_items(impl_trait_ref.def_id)
diff --git a/src/librustc_typeck/coherence/inherent_impls_overlap.rs b/src/librustc_typeck/coherence/inherent_impls_overlap.rs
index 2a0d19b69fd..ad0e462afc7 100644
--- a/src/librustc_typeck/coherence/inherent_impls_overlap.rs
+++ b/src/librustc_typeck/coherence/inherent_impls_overlap.rs
@@ -1,4 +1,3 @@
-use crate::namespace::Namespace;
 use rustc::ty::{AssocItem, TyCtxt};
 use rustc_errors::struct_span_err;
 use rustc_hir as hir;
diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs
index 0a1c61b8aea..c5f339d6b76 100644
--- a/src/librustc_typeck/lib.rs
+++ b/src/librustc_typeck/lib.rs
@@ -83,7 +83,6 @@ mod collect;
 mod constrained_generic_params;
 mod impl_wf_check;
 mod mem_categorization;
-mod namespace;
 mod outlives;
 mod structured_errors;
 mod variance;
diff --git a/src/librustc_typeck/namespace.rs b/src/librustc_typeck/namespace.rs
deleted file mode 100644
index 2aa97aa7e6f..00000000000
--- a/src/librustc_typeck/namespace.rs
+++ /dev/null
@@ -1,27 +0,0 @@
-use rustc::ty;
-use rustc_hir as hir;
-
-// Whether an item exists in the type or value namespace.
-#[derive(Copy, Clone, PartialEq, Eq, Debug)]
-pub enum Namespace {
-    Type,
-    Value,
-}
-
-impl From<ty::AssocKind> for Namespace {
-    fn from(a_kind: ty::AssocKind) -> Self {
-        match a_kind {
-            ty::AssocKind::OpaqueTy | ty::AssocKind::Type => Namespace::Type,
-            ty::AssocKind::Const | ty::AssocKind::Method => Namespace::Value,
-        }
-    }
-}
-
-impl<'a> From<&'a hir::ImplItemKind<'_>> for Namespace {
-    fn from(impl_kind: &'a hir::ImplItemKind<'_>) -> Self {
-        match *impl_kind {
-            hir::ImplItemKind::OpaqueTy(..) | hir::ImplItemKind::TyAlias(..) => Namespace::Type,
-            hir::ImplItemKind::Const(..) | hir::ImplItemKind::Method(..) => Namespace::Value,
-        }
-    }
-}