Skip to content

Commit 90ce504

Browse files
committed
Address comments.
1 parent 4f5616e commit 90ce504

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

src/librustc_resolve/build_reduced_graph.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use syntax::ast::Name;
3232
use syntax::attr;
3333
use syntax::parse::token;
3434

35-
use syntax::ast::{Block, Crate, DUMMY_NODE_ID};
35+
use syntax::ast::{Block, Crate};
3636
use syntax::ast::{ForeignItem, ForeignItemKind, Item, ItemKind};
3737
use syntax::ast::{Mutability, StmtKind, TraitItemKind};
3838
use syntax::ast::{Variant, ViewPathGlob, ViewPathList, ViewPathSimple};
@@ -208,7 +208,7 @@ impl<'b> Resolver<'b> {
208208
ItemKind::Mod(..) => {
209209
let parent_link = ModuleParentLink(parent, name);
210210
let def = Def::Mod(self.definitions.local_def_id(item.id));
211-
let module = self.new_module(parent_link, Some(def), item.id);
211+
let module = self.new_module(parent_link, Some(def), Some(item.id));
212212
module.no_implicit_prelude.set({
213213
parent.no_implicit_prelude.get() ||
214214
attr::contains_name(&item.attrs, "no_implicit_prelude")
@@ -398,7 +398,7 @@ impl<'b> Resolver<'b> {
398398
debug!("(building reduced graph for external crate) building module {} {:?}",
399399
name, vis);
400400
let parent_link = ModuleParentLink(parent, name);
401-
let module = self.new_module(parent_link, Some(def), DUMMY_NODE_ID);
401+
let module = self.new_module(parent_link, Some(def), None);
402402
let _ = self.try_define(parent, name, TypeNS, (module, DUMMY_SP, vis));
403403
}
404404
Def::Variant(_, variant_id) => {
@@ -440,7 +440,7 @@ impl<'b> Resolver<'b> {
440440
}
441441

442442
let parent_link = ModuleParentLink(parent, name);
443-
let module = self.new_module(parent_link, Some(def), DUMMY_NODE_ID);
443+
let module = self.new_module(parent_link, Some(def), None);
444444
let _ = self.try_define(parent, name, TypeNS, (module, DUMMY_SP, vis));
445445
}
446446
Def::TyAlias(..) | Def::AssociatedTy(..) => {

src/librustc_resolve/lib.rs

+20-14
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use rustc::util::nodemap::{NodeMap, NodeSet, FnvHashMap, FnvHashSet};
5454

5555
use syntax::ext::hygiene::Mark;
5656
use syntax::ast::{self, FloatTy};
57-
use syntax::ast::{CRATE_NODE_ID, DUMMY_NODE_ID, Name, NodeId, CrateNum, IntTy, UintTy};
57+
use syntax::ast::{CRATE_NODE_ID, Name, NodeId, CrateNum, IntTy, UintTy};
5858
use syntax::parse::token::{self, keywords};
5959
use syntax::util::lev_distance::find_best_match_for_name;
6060

@@ -765,7 +765,7 @@ pub struct ModuleS<'a> {
765765
def: Option<Def>,
766766

767767
// The node id of the closest normal module (`mod`) ancestor (including this module).
768-
normal_ancestor_id: NodeId,
768+
normal_ancestor_id: Option<NodeId>,
769769

770770
// If the module is an extern crate, `def` is root of the external crate and `extern_crate_id`
771771
// is the NodeId of the local `extern crate` item (otherwise, `extern_crate_id` is None).
@@ -790,7 +790,8 @@ pub struct ModuleS<'a> {
790790
pub type Module<'a> = &'a ModuleS<'a>;
791791

792792
impl<'a> ModuleS<'a> {
793-
fn new(parent_link: ParentLink<'a>, def: Option<Def>, normal_ancestor_id: NodeId) -> Self {
793+
fn new(parent_link: ParentLink<'a>, def: Option<Def>, normal_ancestor_id: Option<NodeId>)
794+
-> Self {
794795
ModuleS {
795796
parent_link: parent_link,
796797
def: def,
@@ -801,7 +802,7 @@ impl<'a> ModuleS<'a> {
801802
glob_importers: RefCell::new(Vec::new()),
802803
globs: RefCell::new((Vec::new())),
803804
traits: RefCell::new(None),
804-
populated: Cell::new(normal_ancestor_id != DUMMY_NODE_ID),
805+
populated: Cell::new(normal_ancestor_id.is_some()),
805806
}
806807
}
807808

@@ -1104,7 +1105,7 @@ impl<'a> ty::NodeIdTree for Resolver<'a> {
11041105
fn is_descendant_of(&self, mut node: NodeId, ancestor: NodeId) -> bool {
11051106
while node != ancestor {
11061107
node = match self.module_map[&node].parent() {
1107-
Some(parent) => parent.normal_ancestor_id,
1108+
Some(parent) => parent.normal_ancestor_id.unwrap(),
11081109
None => return false,
11091110
}
11101111
}
@@ -1168,7 +1169,8 @@ impl<'a> Resolver<'a> {
11681169
pub fn new(session: &'a Session, make_glob_map: MakeGlobMap, arenas: &'a ResolverArenas<'a>)
11691170
-> Resolver<'a> {
11701171
let root_def_id = DefId::local(CRATE_DEF_INDEX);
1171-
let graph_root = ModuleS::new(NoParentLink, Some(Def::Mod(root_def_id)), CRATE_NODE_ID);
1172+
let graph_root =
1173+
ModuleS::new(NoParentLink, Some(Def::Mod(root_def_id)), Some(CRATE_NODE_ID));
11721174
let graph_root = arenas.alloc_module(graph_root);
11731175
let mut module_map = NodeMap();
11741176
module_map.insert(CRATE_NODE_ID, graph_root);
@@ -1247,14 +1249,17 @@ impl<'a> Resolver<'a> {
12471249
self.report_errors();
12481250
}
12491251

1250-
fn new_module(&self, parent_link: ParentLink<'a>, def: Option<Def>, normal_ancestor_id: NodeId)
1252+
fn new_module(&self,
1253+
parent_link: ParentLink<'a>,
1254+
def: Option<Def>,
1255+
normal_ancestor_id: Option<NodeId>)
12511256
-> Module<'a> {
12521257
self.arenas.alloc_module(ModuleS::new(parent_link, def, normal_ancestor_id))
12531258
}
12541259

12551260
fn new_extern_crate_module(&self, parent_link: ParentLink<'a>, def: Def, local_node_id: NodeId)
12561261
-> Module<'a> {
1257-
let mut module = ModuleS::new(parent_link, Some(def), local_node_id);
1262+
let mut module = ModuleS::new(parent_link, Some(def), Some(local_node_id));
12581263
module.extern_crate_id = Some(local_node_id);
12591264
self.arenas.modules.alloc(module)
12601265
}
@@ -1530,14 +1535,15 @@ impl<'a> Resolver<'a> {
15301535
_ => return Success(NoPrefixFound),
15311536
};
15321537

1533-
let mut containing_module = self.module_map[&self.current_module.normal_ancestor_id];
1538+
let mut containing_module =
1539+
self.module_map[&self.current_module.normal_ancestor_id.unwrap()];
15341540

15351541
// Now loop through all the `super`s we find.
15361542
while i < module_path.len() && "super" == module_path[i].as_str() {
15371543
debug!("(resolving module prefix) resolving `super` at {}",
15381544
module_to_string(&containing_module));
15391545
if let Some(parent) = containing_module.parent() {
1540-
containing_module = self.module_map[&parent.normal_ancestor_id];
1546+
containing_module = self.module_map[&parent.normal_ancestor_id.unwrap()];
15411547
i += 1;
15421548
} else {
15431549
let msg = "There are too many initial `super`s.".into();
@@ -3260,7 +3266,7 @@ impl<'a> Resolver<'a> {
32603266
ast::Visibility::Crate(_) => return ty::Visibility::Restricted(ast::CRATE_NODE_ID),
32613267
ast::Visibility::Restricted { ref path, id } => (path, id),
32623268
ast::Visibility::Inherited => {
3263-
return ty::Visibility::Restricted(self.current_module.normal_ancestor_id);
3269+
return ty::Visibility::Restricted(self.current_module.normal_ancestor_id.unwrap());
32643270
}
32653271
};
32663272

@@ -3269,7 +3275,7 @@ impl<'a> Resolver<'a> {
32693275
let vis = match self.resolve_module_path(&segments, DontUseLexicalScope, Some(path.span)) {
32703276
Success(module) => {
32713277
path_resolution = PathResolution::new(module.def.unwrap());
3272-
ty::Visibility::Restricted(module.normal_ancestor_id)
3278+
ty::Visibility::Restricted(module.normal_ancestor_id.unwrap())
32733279
}
32743280
Indeterminate => unreachable!(),
32753281
Failed(err) => {
@@ -3288,11 +3294,11 @@ impl<'a> Resolver<'a> {
32883294
}
32893295

32903296
fn is_accessible(&self, vis: ty::Visibility) -> bool {
3291-
vis.is_accessible_from(self.current_module.normal_ancestor_id, self)
3297+
vis.is_accessible_from(self.current_module.normal_ancestor_id.unwrap(), self)
32923298
}
32933299

32943300
fn is_accessible_from(&self, vis: ty::Visibility, module: Module<'a>) -> bool {
3295-
vis.is_accessible_from(module.normal_ancestor_id, self)
3301+
vis.is_accessible_from(module.normal_ancestor_id.unwrap(), self)
32963302
}
32973303

32983304
fn report_errors(&self) {

src/librustc_resolve/resolve_imports.rs

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pub enum ImportDirectiveSubclass<'a> {
5555
GlobImport {
5656
is_prelude: bool,
5757
max_vis: Cell<ty::Visibility>, // The visibility of the greatest reexport.
58+
// n.b. `max_vis` is only used in `finalize_import` to check for reexport errors.
5859
},
5960
}
6061

src/test/run-pass/imports.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// ignore-pretty : (#23623) problems when ending with // comments
12+
1113
#![feature(item_like_imports)]
1214
#![allow(unused)]
1315

0 commit comments

Comments
 (0)