Skip to content

Commit 3bb7da2

Browse files
Replace rustc_typeck::Namespace with rustc_hir::def::Namespace
1 parent ea3c9d2 commit 3bb7da2

File tree

10 files changed

+32
-48
lines changed

10 files changed

+32
-48
lines changed

src/librustc/ty/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use rustc_data_structures::fx::FxIndexMap;
3333
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
3434
use rustc_data_structures::sync::{self, par_iter, Lrc, ParallelIterator};
3535
use rustc_hir as hir;
36-
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
36+
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Namespace, Res};
3737
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
3838
use rustc_hir::{Constness, GlobMap, Node, TraitMap};
3939
use rustc_index::vec::{Idx, IndexVec};
@@ -216,6 +216,13 @@ impl AssocKind {
216216
ty::AssocKind::Const => "associated constant",
217217
}
218218
}
219+
220+
pub fn namespace(&self) -> Namespace {
221+
match *self {
222+
ty::AssocKind::OpaqueTy | ty::AssocKind::Type => Namespace::TypeNS,
223+
ty::AssocKind::Const | ty::AssocKind::Method => Namespace::ValueNS,
224+
}
225+
}
219226
}
220227

221228
impl AssocItem {

src/librustc_hir/hir.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::def::{DefKind, Res};
1+
use crate::def::{DefKind, Namespace, Res};
22
use crate::def_id::DefId;
33
crate use crate::hir_id::HirId;
44
use crate::itemlikevisit;
@@ -1897,6 +1897,15 @@ pub enum ImplItemKind<'hir> {
18971897
OpaqueTy(GenericBounds<'hir>),
18981898
}
18991899

1900+
impl ImplItemKind<'_> {
1901+
pub fn namespace(&self) -> Namespace {
1902+
match self {
1903+
ImplItemKind::OpaqueTy(..) | ImplItemKind::TyAlias(..) => Namespace::TypeNS,
1904+
ImplItemKind::Const(..) | ImplItemKind::Method(..) => Namespace::ValueNS,
1905+
}
1906+
}
1907+
}
1908+
19001909
// The name of the associated type for `Fn` return types.
19011910
pub const FN_OUTPUT_NAME: Symbol = sym::Output;
19021911

src/librustc_typeck/astconv.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use crate::collect::PlaceholderHirTyCollector;
99
use crate::lint;
1010
use crate::middle::lang_items::SizedTraitLangItem;
1111
use crate::middle::resolve_lifetime as rl;
12-
use crate::namespace::Namespace;
1312
use crate::require_c_abi_if_c_variadic;
1413
use crate::util::common::ErrorReported;
1514
use rustc::lint::builtin::AMBIGUOUS_ASSOCIATED_ITEMS;
@@ -20,7 +19,7 @@ use rustc::ty::{GenericParamDef, GenericParamDefKind};
2019
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
2120
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticId};
2221
use rustc_hir as hir;
23-
use rustc_hir::def::{CtorOf, DefKind, Res};
22+
use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
2423
use rustc_hir::def_id::DefId;
2524
use rustc_hir::intravisit::Visitor;
2625
use rustc_hir::print;
@@ -2202,7 +2201,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
22022201
let item = tcx
22032202
.associated_items(trait_did)
22042203
.iter()
2205-
.find(|i| Namespace::from(i.kind) == Namespace::Type && i.ident.modern() == assoc_ident)
2204+
.find(|i| i.kind.namespace() == Namespace::TypeNS && i.ident.modern() == assoc_ident)
22062205
.expect("missing associated type");
22072206

22082207
let ty = self.projected_ty_from_poly_trait_ref(span, item.def_id, assoc_segment, bound);

src/librustc_typeck/check/method/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ pub use self::CandidateSource::*;
1111
pub use self::MethodError::*;
1212

1313
use crate::check::FnCtxt;
14-
use crate::namespace::Namespace;
1514
use rustc::ty::subst::Subst;
1615
use rustc::ty::subst::{InternalSubsts, SubstsRef};
1716
use rustc::ty::GenericParamDefKind;
1817
use rustc::ty::{self, ToPolyTraitRef, ToPredicate, TraitRef, Ty, TypeFoldable, WithConstness};
1918
use rustc_data_structures::sync::Lrc;
2019
use rustc_errors::{Applicability, DiagnosticBuilder};
2120
use rustc_hir as hir;
22-
use rustc_hir::def::{CtorOf, DefKind};
21+
use rustc_hir::def::{CtorOf, DefKind, Namespace};
2322
use rustc_hir::def_id::DefId;
2423
use rustc_infer::infer::{self, InferOk};
2524
use rustc_infer::traits;
@@ -342,7 +341,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
342341
// Trait must have a method named `m_name` and it should not have
343342
// type parameters or early-bound regions.
344343
let tcx = self.tcx;
345-
let method_item = match self.associated_item(trait_def_id, m_name, Namespace::Value) {
344+
let method_item = match self.associated_item(trait_def_id, m_name, Namespace::ValueNS) {
346345
Some(method_item) => method_item,
347346
None => {
348347
tcx.sess.delay_span_bug(

src/librustc_typeck/check/method/probe.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use crate::check::autoderef::{self, Autoderef};
77
use crate::check::FnCtxt;
88
use crate::hir::def::DefKind;
99
use crate::hir::def_id::DefId;
10-
use crate::namespace::Namespace;
1110

1211
use rustc::lint;
1312
use rustc::middle::stability;
@@ -22,6 +21,7 @@ use rustc_data_structures::fx::FxHashSet;
2221
use rustc_data_structures::sync::Lrc;
2322
use rustc_errors::struct_span_err;
2423
use rustc_hir as hir;
24+
use rustc_hir::def::Namespace;
2525
use rustc_infer::infer::canonical::OriginalQueryValues;
2626
use rustc_infer::infer::canonical::{Canonical, QueryResponse};
2727
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
@@ -1699,13 +1699,13 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
16991699
.iter()
17001700
.filter(|x| {
17011701
let dist = lev_distance(&*name.as_str(), &x.ident.as_str());
1702-
Namespace::from(x.kind) == Namespace::Value && dist > 0 && dist <= max_dist
1702+
x.kind.namespace() == Namespace::ValueNS && dist > 0 && dist <= max_dist
17031703
})
17041704
.copied()
17051705
.collect()
17061706
} else {
17071707
self.fcx
1708-
.associated_item(def_id, name, Namespace::Value)
1708+
.associated_item(def_id, name, Namespace::ValueNS)
17091709
.map_or(Vec::new(), |x| vec![x])
17101710
}
17111711
} else {

src/librustc_typeck/check/method/suggest.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
44
use crate::check::FnCtxt;
55
use crate::middle::lang_items::FnOnceTraitLangItem;
6-
use crate::namespace::Namespace;
76
use rustc::hir::map as hir_map;
87
use rustc::hir::map::Map;
98
use rustc::ty::print::with_crate_prefix;
109
use rustc::ty::{self, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness};
1110
use rustc_data_structures::fx::FxHashSet;
1211
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder};
1312
use rustc_hir as hir;
14-
use rustc_hir::def::{DefKind, Res};
13+
use rustc_hir::def::{DefKind, Namespace, Res};
1514
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
1615
use rustc_hir::intravisit;
1716
use rustc_hir::{ExprKind, Node, QPath};
@@ -97,13 +96,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
9796
// Provide the best span we can. Use the item, if local to crate, else
9897
// the impl, if local to crate (item may be defaulted), else nothing.
9998
let item = match self
100-
.associated_item(impl_did, item_name, Namespace::Value)
99+
.associated_item(impl_did, item_name, Namespace::ValueNS)
101100
.or_else(|| {
102101
let impl_trait_ref = self.tcx.impl_trait_ref(impl_did)?;
103102
self.associated_item(
104103
impl_trait_ref.def_id,
105104
item_name,
106-
Namespace::Value,
105+
Namespace::ValueNS,
107106
)
108107
}) {
109108
Some(item) => item,
@@ -185,7 +184,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
185184
}
186185
CandidateSource::TraitSource(trait_did) => {
187186
let item =
188-
match self.associated_item(trait_did, item_name, Namespace::Value) {
187+
match self.associated_item(trait_did, item_name, Namespace::ValueNS) {
189188
Some(item) => item,
190189
None => continue,
191190
};
@@ -264,7 +263,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
264263
// be used exists at all, and the type is an ambiguous numeric type
265264
// ({integer}/{float}).
266265
let mut candidates = all_traits(self.tcx).into_iter().filter_map(|info| {
267-
self.associated_item(info.def_id, item_name, Namespace::Value)
266+
self.associated_item(info.def_id, item_name, Namespace::ValueNS)
268267
});
269268
if let (true, false, SelfSource::MethodCall(expr), Some(_)) = (
270269
actual.is_numeric(),
@@ -779,7 +778,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
779778
// here).
780779
(type_is_local || info.def_id.is_local())
781780
&& self
782-
.associated_item(info.def_id, item_name, Namespace::Value)
781+
.associated_item(info.def_id, item_name, Namespace::ValueNS)
783782
.filter(|item| {
784783
// We only want to suggest public or local traits (#45781).
785784
item.vis == ty::Visibility::Public || info.def_id.is_local()

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ pub mod writeback;
8989

9090
use crate::astconv::{AstConv, PathSeg};
9191
use crate::middle::lang_items;
92-
use crate::namespace::Namespace;
9392
use rustc::hir::map::blocks::FnLikeNode;
9493
use rustc::hir::map::Map;
9594
use rustc::middle::region;
@@ -1972,6 +1971,7 @@ fn check_impl_items_against_trait<'tcx>(
19721971
// Check existing impl methods to see if they are both present in trait
19731972
// and compatible with trait signature
19741973
for impl_item in impl_items() {
1974+
let namespace = impl_item.kind.namespace();
19751975
let ty_impl_item = tcx.associated_item(tcx.hir().local_def_id(impl_item.hir_id));
19761976
let ty_trait_item = tcx
19771977
.associated_items(impl_trait_ref.def_id)

src/librustc_typeck/coherence/inherent_impls_overlap.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::namespace::Namespace;
21
use rustc::ty::{AssocItem, TyCtxt};
32
use rustc_errors::struct_span_err;
43
use rustc_hir as hir;

src/librustc_typeck/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ mod collect;
8383
mod constrained_generic_params;
8484
mod impl_wf_check;
8585
mod mem_categorization;
86-
mod namespace;
8786
mod outlives;
8887
mod structured_errors;
8988
mod variance;

src/librustc_typeck/namespace.rs

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)