Skip to content

Commit ada87fa

Browse files
committed
Rename (Ns)ImportResolution
1 parent 27c4f9e commit ada87fa

File tree

3 files changed

+42
-43
lines changed

3 files changed

+42
-43
lines changed

src/librustc_resolve/build_reduced_graph.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use DefModifiers;
1717
use resolve_imports::ImportDirective;
1818
use resolve_imports::ImportDirectiveSubclass::{self, SingleImport, GlobImport};
19-
use resolve_imports::{ImportResolution, NsImportResolution};
19+
use resolve_imports::{ImportResolution, ImportResolutionPerNamespace};
2020
use Module;
2121
use Namespace::{TypeNS, ValueNS};
2222
use NameBindings;
@@ -822,23 +822,23 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
822822

823823
let mut import_resolutions = module_.import_resolutions.borrow_mut();
824824
match import_resolutions.get_mut(&target) {
825-
Some(resolution) => {
825+
Some(resolution_per_ns) => {
826826
debug!("(building import directive) bumping reference");
827-
resolution.outstanding_references += 1;
827+
resolution_per_ns.outstanding_references += 1;
828828

829829
// the source of this name is different now
830-
let ns_resolution =
831-
NsImportResolution { id: id, is_public: is_public, target: None };
832-
resolution[TypeNS] = ns_resolution.clone();
833-
resolution[ValueNS] = ns_resolution;
830+
let resolution =
831+
ImportResolution { id: id, is_public: is_public, target: None };
832+
resolution_per_ns[TypeNS] = resolution.clone();
833+
resolution_per_ns[ValueNS] = resolution;
834834
return;
835835
}
836836
None => {}
837837
}
838838
debug!("(building import directive) creating new");
839-
let mut resolution = ImportResolution::new(id, is_public);
840-
resolution.outstanding_references = 1;
841-
import_resolutions.insert(target, resolution);
839+
let mut import_resolution_per_ns = ImportResolutionPerNamespace::new(id, is_public);
840+
import_resolution_per_ns.outstanding_references = 1;
841+
import_resolutions.insert(target, import_resolution_per_ns);
842842
}
843843
GlobImport => {
844844
// Set the glob flag. This tells us that we don't know the

src/librustc_resolve/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ use std::mem::replace;
9696
use std::rc::{Rc, Weak};
9797
use std::usize;
9898

99-
use resolve_imports::{Target, ImportDirective, ImportResolution};
99+
use resolve_imports::{Target, ImportDirective, ImportResolutionPerNamespace};
100100
use resolve_imports::Shadowable;
101101

102102
// NB: This module needs to be declared first so diagnostics are
@@ -793,7 +793,7 @@ pub struct Module {
793793
anonymous_children: RefCell<NodeMap<Rc<Module>>>,
794794

795795
// The status of resolving each import in this module.
796-
import_resolutions: RefCell<HashMap<Name, ImportResolution>>,
796+
import_resolutions: RefCell<HashMap<Name, ImportResolutionPerNamespace>>,
797797

798798
// The number of unresolved globs that this module exports.
799799
glob_count: Cell<usize>,
@@ -912,7 +912,7 @@ bitflags! {
912912
// Records a possibly-private value, type, or module definition.
913913
#[derive(Debug)]
914914
struct NsDef {
915-
modifiers: DefModifiers, // see note in ImportResolution about how to use this
915+
modifiers: DefModifiers, // see note in ImportResolutionPerNamespace about how to use this
916916
def_or_module: DefOrModule,
917917
span: Option<Span>,
918918
}

src/librustc_resolve/resolve_imports.rs

+29-30
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub struct ImportDirective {
5858
pub subclass: ImportDirectiveSubclass,
5959
pub span: Span,
6060
pub id: NodeId,
61-
pub is_public: bool, // see note in ImportResolution about how to use this
61+
pub is_public: bool, // see note in ImportResolutionPerNamespace about how to use this
6262
pub shadowable: Shadowable,
6363
}
6464

@@ -103,25 +103,25 @@ impl Target {
103103
}
104104

105105
#[derive(Debug)]
106-
/// An ImportResolution records what we know about an imported name.
106+
/// An ImportResolutionPerNamespace records what we know about an imported name.
107107
/// More specifically, it records the number of unresolved `use` directives that import the name,
108108
/// and for each namespace, it records the `use` directive importing the name in the namespace
109109
/// and the `Target` to which the name in the namespace resolves (if applicable).
110110
/// Different `use` directives may import the same name in different namespaces.
111-
pub struct ImportResolution {
111+
pub struct ImportResolutionPerNamespace {
112112
// When outstanding_references reaches zero, outside modules can count on the targets being
113113
// correct. Before then, all bets are off; future `use` directives could override the name.
114114
// Since shadowing is forbidden, the only way outstanding_references > 1 in a legal program
115115
// is if the name is imported by exactly two `use` directives, one of which resolves to a
116116
// value and the other of which resolves to a type.
117117
pub outstanding_references: usize,
118-
pub type_ns: NsImportResolution,
119-
pub value_ns: NsImportResolution,
118+
pub type_ns: ImportResolution,
119+
pub value_ns: ImportResolution,
120120
}
121121

122-
/// Records what we know about an imported name in a namespace (see `ImportResolution`).
122+
/// Records what we know about an imported name in a namespace (see `ImportResolutionPerNamespace`).
123123
#[derive(Clone,Debug)]
124-
pub struct NsImportResolution {
124+
pub struct ImportResolution {
125125
/// Whether the name in the namespace was imported with a `use` or a `pub use`.
126126
pub is_public: bool,
127127

@@ -132,23 +132,23 @@ pub struct NsImportResolution {
132132
pub id: NodeId,
133133
}
134134

135-
impl ::std::ops::Index<Namespace> for ImportResolution {
136-
type Output = NsImportResolution;
137-
fn index(&self, ns: Namespace) -> &NsImportResolution {
135+
impl ::std::ops::Index<Namespace> for ImportResolutionPerNamespace {
136+
type Output = ImportResolution;
137+
fn index(&self, ns: Namespace) -> &ImportResolution {
138138
match ns { TypeNS => &self.type_ns, ValueNS => &self.value_ns }
139139
}
140140
}
141141

142-
impl ::std::ops::IndexMut<Namespace> for ImportResolution {
143-
fn index_mut(&mut self, ns: Namespace) -> &mut NsImportResolution {
142+
impl ::std::ops::IndexMut<Namespace> for ImportResolutionPerNamespace {
143+
fn index_mut(&mut self, ns: Namespace) -> &mut ImportResolution {
144144
match ns { TypeNS => &mut self.type_ns, ValueNS => &mut self.value_ns }
145145
}
146146
}
147147

148-
impl ImportResolution {
149-
pub fn new(id: NodeId, is_public: bool) -> ImportResolution {
150-
let resolution = NsImportResolution { id: id, is_public: is_public, target: None };
151-
ImportResolution {
148+
impl ImportResolutionPerNamespace {
149+
pub fn new(id: NodeId, is_public: bool) -> Self {
150+
let resolution = ImportResolution { id: id, is_public: is_public, target: None };
151+
ImportResolutionPerNamespace {
152152
outstanding_references: 0, type_ns: resolution.clone(), value_ns: resolution,
153153
}
154154
}
@@ -504,7 +504,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
504504
Some(import_resolution) if import_resolution.outstanding_references == 0 => {
505505

506506
fn get_binding(this: &mut Resolver,
507-
import_resolution: &ImportResolution,
507+
import_resolution: &ImportResolutionPerNamespace,
508508
namespace: Namespace,
509509
source: Name)
510510
-> NamespaceResult {
@@ -644,7 +644,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
644644
directive.span,
645645
target);
646646

647-
import_resolution[namespace] = NsImportResolution {
647+
import_resolution[namespace] = ImportResolution {
648648
target: Some(Target::new(target_module.clone(),
649649
name_binding.clone(),
650650
directive.shadowable)),
@@ -777,7 +777,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
777777
// Here we merge two import resolutions.
778778
let mut import_resolutions = module_.import_resolutions.borrow_mut();
779779
let mut dest_import_resolution = import_resolutions.entry(*name).or_insert_with(|| {
780-
ImportResolution::new(id, is_public)
780+
ImportResolutionPerNamespace::new(id, is_public)
781781
});
782782

783783
for &ns in [TypeNS, ValueNS].iter() {
@@ -787,7 +787,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
787787
import_directive.span,
788788
*name,
789789
ns);
790-
dest_import_resolution[ns] = NsImportResolution {
790+
dest_import_resolution[ns] = ImportResolution {
791791
id: id, is_public: is_public, target: Some(target.clone())
792792
};
793793
}
@@ -832,10 +832,9 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
832832
let is_public = import_directive.is_public;
833833

834834
let mut import_resolutions = module_.import_resolutions.borrow_mut();
835-
let dest_import_resolution = import_resolutions.entry(name)
836-
.or_insert_with(|| {
837-
ImportResolution::new(id, is_public)
838-
});
835+
let dest_import_resolution = import_resolutions.entry(name).or_insert_with(|| {
836+
ImportResolutionPerNamespace::new(id, is_public)
837+
});
839838

840839
debug!("(resolving glob import) writing resolution `{}` in `{}` to `{}`",
841840
name,
@@ -864,7 +863,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
864863
"{}",
865864
msg);
866865
} else {
867-
dest_import_resolution[namespace] = NsImportResolution {
866+
dest_import_resolution[namespace] = ImportResolution {
868867
target: Some(Target::new(containing_module.clone(),
869868
name_bindings[namespace].clone(),
870869
import_directive.shadowable)),
@@ -886,7 +885,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
886885

887886
/// Checks that imported names and items don't have the same name.
888887
fn check_for_conflicting_import(&mut self,
889-
import_resolution: &ImportResolution,
888+
import_resolution: &ImportResolutionPerNamespace,
890889
import_span: Span,
891890
name: Name,
892891
namespace: Namespace) {
@@ -939,14 +938,14 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
939938
/// Checks that imported names and items don't have the same name.
940939
fn check_for_conflicts_between_imports_and_items(&mut self,
941940
module: &Module,
942-
import_resolution: &ImportResolution,
941+
import: &ImportResolutionPerNamespace,
943942
import_span: Span,
944943
name: Name) {
945944
// First, check for conflicts between imports and `extern crate`s.
946945
if module.external_module_children
947946
.borrow()
948947
.contains_key(&name) {
949-
match import_resolution.type_ns.target {
948+
match import.type_ns.target {
950949
Some(ref target) if target.shadowable != Shadowable::Always => {
951950
let msg = format!("import `{0}` conflicts with imported crate in this module \
952951
(maybe you meant `use {0}::*`?)",
@@ -967,7 +966,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
967966
Some(ref name_bindings) => (*name_bindings).clone(),
968967
};
969968

970-
match import_resolution.value_ns.target {
969+
match import.value_ns.target {
971970
Some(ref target) if target.shadowable != Shadowable::Always => {
972971
if let Some(ref value) = *name_bindings.value_ns.borrow() {
973972
span_err!(self.resolver.session,
@@ -983,7 +982,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
983982
Some(_) | None => {}
984983
}
985984

986-
match import_resolution.type_ns.target {
985+
match import.type_ns.target {
987986
Some(ref target) if target.shadowable != Shadowable::Always => {
988987
if let Some(ref ty) = *name_bindings.type_ns.borrow() {
989988
let (what, note) = match ty.module() {

0 commit comments

Comments
 (0)