Skip to content

Commit df0eb16

Browse files
committed
Rollup merge of rust-lang#33045 - jseyfried:no_def_modifiers, r=eddyb
resolve: Refactor away `DefModifiers` This refactors away `DefModifiers`, which is unneeded now that rust-lang#32875 has landed. r? @eddyb
2 parents 02e40d9 + 2c978dc commit df0eb16

File tree

4 files changed

+56
-75
lines changed

4 files changed

+56
-75
lines changed

src/librustc_resolve/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ crate-type = ["dylib"]
1212
log = { path = "../liblog" }
1313
syntax = { path = "../libsyntax" }
1414
rustc = { path = "../librustc" }
15-
rustc_bitflags = { path = "../librustc_bitflags" }
1615
arena = { path = "../libarena" }

src/librustc_resolve/build_reduced_graph.rs

+18-30
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
//! Here we build the "reduced graph": the graph of the module tree without
1414
//! any imports resolved.
1515
16-
use DefModifiers;
1716
use resolve_imports::ImportDirectiveSubclass::{self, GlobImport};
1817
use Module;
1918
use Namespace::{self, TypeNS, ValueNS};
@@ -53,10 +52,9 @@ impl<'a> ToNameBinding<'a> for (Module<'a>, Span) {
5352
}
5453
}
5554

56-
impl<'a> ToNameBinding<'a> for (Def, Span, DefModifiers, ty::Visibility) {
55+
impl<'a> ToNameBinding<'a> for (Def, Span, ty::Visibility) {
5756
fn to_name_binding(self) -> NameBinding<'a> {
58-
let kind = NameBindingKind::Def(self.0);
59-
NameBinding { modifiers: self.2, kind: kind, span: Some(self.1), vis: self.3 }
57+
NameBinding { kind: NameBindingKind::Def(self.0), span: Some(self.1), vis: self.2 }
6058
}
6159
}
6260

@@ -136,7 +134,6 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
136134
let parent = *parent_ref;
137135
let name = item.name;
138136
let sp = item.span;
139-
let modifiers = DefModifiers::IMPORTABLE;
140137
self.current_module = parent;
141138
let vis = self.resolve_visibility(&item.vis);
142139

@@ -284,21 +281,21 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
284281
ItemStatic(_, m, _) => {
285282
let mutbl = m == hir::MutMutable;
286283
let def = Def::Static(self.ast_map.local_def_id(item.id), mutbl);
287-
self.define(parent, name, ValueNS, (def, sp, modifiers, vis));
284+
self.define(parent, name, ValueNS, (def, sp, vis));
288285
}
289286
ItemConst(_, _) => {
290287
let def = Def::Const(self.ast_map.local_def_id(item.id));
291-
self.define(parent, name, ValueNS, (def, sp, modifiers, vis));
288+
self.define(parent, name, ValueNS, (def, sp, vis));
292289
}
293290
ItemFn(_, _, _, _, _, _) => {
294291
let def = Def::Fn(self.ast_map.local_def_id(item.id));
295-
self.define(parent, name, ValueNS, (def, sp, modifiers, vis));
292+
self.define(parent, name, ValueNS, (def, sp, vis));
296293
}
297294

298295
// These items live in the type namespace.
299296
ItemTy(..) => {
300297
let def = Def::TyAlias(self.ast_map.local_def_id(item.id));
301-
self.define(parent, name, TypeNS, (def, sp, modifiers, vis));
298+
self.define(parent, name, TypeNS, (def, sp, vis));
302299
}
303300

304301
ItemEnum(ref enum_definition, _) => {
@@ -317,13 +314,13 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
317314
ItemStruct(ref struct_def, _) => {
318315
// Define a name in the type namespace.
319316
let def = Def::Struct(self.ast_map.local_def_id(item.id));
320-
self.define(parent, name, TypeNS, (def, sp, modifiers, vis));
317+
self.define(parent, name, TypeNS, (def, sp, vis));
321318

322319
// If this is a newtype or unit-like struct, define a name
323320
// in the value namespace as well
324321
if !struct_def.is_struct() {
325322
let def = Def::Struct(self.ast_map.local_def_id(struct_def.id()));
326-
self.define(parent, name, ValueNS, (def, sp, modifiers, vis));
323+
self.define(parent, name, ValueNS, (def, sp, vis));
327324
}
328325

329326
// Record the def ID and fields of this struct.
@@ -355,8 +352,7 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
355352
hir::TypeTraitItem(..) => (Def::AssociatedTy(def_id, item_def_id), TypeNS),
356353
};
357354

358-
let modifiers = DefModifiers::empty(); // NB: not DefModifiers::IMPORTABLE
359-
self.define(module_parent, item.name, ns, (def, item.span, modifiers, vis));
355+
self.define(module_parent, item.name, ns, (def, item.span, vis));
360356

361357
self.trait_item_map.insert((item.name, def_id), item_def_id);
362358
}
@@ -379,19 +375,16 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
379375

380376
// Variants are always treated as importable to allow them to be glob used.
381377
// All variants are defined in both type and value namespaces as future-proofing.
382-
let modifiers = DefModifiers::IMPORTABLE;
383378
let def = Def::Variant(item_id, self.ast_map.local_def_id(variant.node.data.id()));
384-
385-
self.define(parent, name, ValueNS, (def, variant.span, modifiers, parent.vis));
386-
self.define(parent, name, TypeNS, (def, variant.span, modifiers, parent.vis));
379+
self.define(parent, name, ValueNS, (def, variant.span, parent.vis));
380+
self.define(parent, name, TypeNS, (def, variant.span, parent.vis));
387381
}
388382

389383
/// Constructs the reduced graph for one foreign item.
390384
fn build_reduced_graph_for_foreign_item(&mut self,
391385
foreign_item: &ForeignItem,
392386
parent: Module<'b>) {
393387
let name = foreign_item.name;
394-
let modifiers = DefModifiers::IMPORTABLE;
395388

396389
let def = match foreign_item.node {
397390
ForeignItemFn(..) => {
@@ -403,7 +396,7 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
403396
};
404397
self.current_module = parent;
405398
let vis = self.resolve_visibility(&foreign_item.vis);
406-
self.define(parent, name, ValueNS, (def, foreign_item.span, modifiers, vis));
399+
self.define(parent, name, ValueNS, (def, foreign_item.span, vis));
407400
}
408401

409402
fn build_reduced_graph_for_block(&mut self, block: &Block, parent: &mut Module<'b>) {
@@ -438,10 +431,6 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
438431

439432
let name = xcdef.name;
440433
let vis = if parent.is_trait() { ty::Visibility::Public } else { xcdef.vis };
441-
let modifiers = match parent.is_normal() {
442-
true => DefModifiers::IMPORTABLE,
443-
false => DefModifiers::empty(),
444-
};
445434

446435
match def {
447436
Def::Mod(_) | Def::ForeignMod(_) | Def::Enum(..) => {
@@ -455,9 +444,8 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
455444
debug!("(building reduced graph for external crate) building variant {}", name);
456445
// Variants are always treated as importable to allow them to be glob used.
457446
// All variants are defined in both type and value namespaces as future-proofing.
458-
let modifiers = DefModifiers::IMPORTABLE;
459-
self.try_define(parent, name, TypeNS, (def, DUMMY_SP, modifiers, vis));
460-
self.try_define(parent, name, ValueNS, (def, DUMMY_SP, modifiers, vis));
447+
self.try_define(parent, name, TypeNS, (def, DUMMY_SP, vis));
448+
self.try_define(parent, name, ValueNS, (def, DUMMY_SP, vis));
461449
if self.session.cstore.variant_kind(variant_id) == Some(VariantKind::Struct) {
462450
// Not adding fields for variants as they are not accessed with a self receiver
463451
self.structs.insert(variant_id, Vec::new());
@@ -470,7 +458,7 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
470458
Def::Method(..) => {
471459
debug!("(building reduced graph for external crate) building value (fn/static) {}",
472460
name);
473-
self.try_define(parent, name, ValueNS, (def, DUMMY_SP, modifiers, vis));
461+
self.try_define(parent, name, ValueNS, (def, DUMMY_SP, vis));
474462
}
475463
Def::Trait(def_id) => {
476464
debug!("(building reduced graph for external crate) building type {}", name);
@@ -496,16 +484,16 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
496484
}
497485
Def::TyAlias(..) | Def::AssociatedTy(..) => {
498486
debug!("(building reduced graph for external crate) building type {}", name);
499-
self.try_define(parent, name, TypeNS, (def, DUMMY_SP, modifiers, vis));
487+
self.try_define(parent, name, TypeNS, (def, DUMMY_SP, vis));
500488
}
501489
Def::Struct(def_id)
502490
if self.session.cstore.tuple_struct_definition_if_ctor(def_id).is_none() => {
503491
debug!("(building reduced graph for external crate) building type and value for {}",
504492
name);
505-
self.try_define(parent, name, TypeNS, (def, DUMMY_SP, modifiers, vis));
493+
self.try_define(parent, name, TypeNS, (def, DUMMY_SP, vis));
506494
if let Some(ctor_def_id) = self.session.cstore.struct_ctor_def_id(def_id) {
507495
let def = Def::Struct(ctor_def_id);
508-
self.try_define(parent, name, ValueNS, (def, DUMMY_SP, modifiers, vis));
496+
self.try_define(parent, name, ValueNS, (def, DUMMY_SP, vis));
509497
}
510498

511499
// Record the def ID and fields of this struct.

src/librustc_resolve/lib.rs

+22-24
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ extern crate log;
2929
extern crate syntax;
3030
extern crate arena;
3131
#[macro_use]
32-
#[no_link]
33-
extern crate rustc_bitflags;
34-
#[macro_use]
3532
extern crate rustc;
3633

3734
use self::PatternBindingMode::*;
@@ -915,18 +912,9 @@ impl<'a> fmt::Debug for ModuleS<'a> {
915912
}
916913
}
917914

918-
bitflags! {
919-
#[derive(Debug)]
920-
flags DefModifiers: u8 {
921-
const IMPORTABLE = 1 << 1,
922-
const GLOB_IMPORTED = 1 << 3,
923-
}
924-
}
925-
926915
// Records a possibly-private value, type, or module definition.
927916
#[derive(Clone, Debug)]
928917
pub struct NameBinding<'a> {
929-
modifiers: DefModifiers,
930918
kind: NameBindingKind<'a>,
931919
span: Option<Span>,
932920
vis: ty::Visibility,
@@ -938,7 +926,7 @@ enum NameBindingKind<'a> {
938926
Module(Module<'a>),
939927
Import {
940928
binding: &'a NameBinding<'a>,
941-
id: NodeId,
929+
directive: &'a ImportDirective<'a>,
942930
// Some(error) if using this imported name causes the import to be a privacy error
943931
privacy_error: Option<Box<PrivacyError<'a>>>,
944932
},
@@ -950,7 +938,6 @@ struct PrivacyError<'a>(Span, Name, &'a NameBinding<'a>);
950938
impl<'a> NameBinding<'a> {
951939
fn create_from_module(module: Module<'a>, span: Option<Span>) -> Self {
952940
NameBinding {
953-
modifiers: DefModifiers::IMPORTABLE,
954941
kind: NameBindingKind::Module(module),
955942
span: span,
956943
vis: module.vis,
@@ -973,10 +960,6 @@ impl<'a> NameBinding<'a> {
973960
}
974961
}
975962

976-
fn defined_with(&self, modifiers: DefModifiers) -> bool {
977-
self.modifiers.contains(modifiers)
978-
}
979-
980963
fn is_pseudo_public(&self) -> bool {
981964
self.pseudo_vis() == ty::Visibility::Public
982965
}
@@ -1003,6 +986,20 @@ impl<'a> NameBinding<'a> {
1003986
_ => false,
1004987
}
1005988
}
989+
990+
fn is_glob_import(&self) -> bool {
991+
match self.kind {
992+
NameBindingKind::Import { directive, .. } => directive.is_glob(),
993+
_ => false,
994+
}
995+
}
996+
997+
fn is_importable(&self) -> bool {
998+
match self.def().unwrap() {
999+
Def::AssociatedConst(..) | Def::Method(..) | Def::AssociatedTy(..) => false,
1000+
_ => true,
1001+
}
1002+
}
10061003
}
10071004

10081005
/// Interns the names of the primitive types.
@@ -1228,27 +1225,28 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
12281225
self.used_crates.insert(krate);
12291226
}
12301227

1231-
let (import_id, privacy_error) = match binding.kind {
1232-
NameBindingKind::Import { id, ref privacy_error, .. } => (id, privacy_error),
1228+
let (directive, privacy_error) = match binding.kind {
1229+
NameBindingKind::Import { directive, ref privacy_error, .. } =>
1230+
(directive, privacy_error),
12331231
_ => return,
12341232
};
12351233

1236-
self.used_imports.insert((import_id, ns));
1234+
self.used_imports.insert((directive.id, ns));
12371235
if let Some(error) = privacy_error.as_ref() {
12381236
self.privacy_errors.push((**error).clone());
12391237
}
12401238

12411239
if !self.make_glob_map {
12421240
return;
12431241
}
1244-
if self.glob_map.contains_key(&import_id) {
1245-
self.glob_map.get_mut(&import_id).unwrap().insert(name);
1242+
if self.glob_map.contains_key(&directive.id) {
1243+
self.glob_map.get_mut(&directive.id).unwrap().insert(name);
12461244
return;
12471245
}
12481246

12491247
let mut new_set = FnvHashSet();
12501248
new_set.insert(name);
1251-
self.glob_map.insert(import_id, new_set);
1249+
self.glob_map.insert(directive.id, new_set);
12521250
}
12531251

12541252
fn get_trait_name(&self, did: DefId) -> Name {

0 commit comments

Comments
 (0)