Skip to content

Commit 1576de0

Browse files
authoredAug 21, 2016
Auto merge of #35776 - jseyfried:more_groundwork, r=nrc
resolve: More groundwork for `item_like_imports` (RFC 1560) r? @nrc
2 parents 4901896 + a6e8f3b commit 1576de0

File tree

5 files changed

+379
-405
lines changed

5 files changed

+379
-405
lines changed
 

‎src/librustc_resolve/build_reduced_graph.rs

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,7 @@ impl<'b> Resolver<'b> {
5656
pub fn build_reduced_graph(&mut self, krate: &Crate) {
5757
let no_implicit_prelude = attr::contains_name(&krate.attrs, "no_implicit_prelude");
5858
self.graph_root.no_implicit_prelude.set(no_implicit_prelude);
59-
60-
let mut visitor = BuildReducedGraphVisitor {
61-
parent: self.graph_root,
62-
resolver: self,
63-
};
64-
visit::walk_crate(&mut visitor, krate);
59+
visit::walk_crate(&mut BuildReducedGraphVisitor { resolver: self }, krate);
6560
}
6661

6762
/// Defines `name` in namespace `ns` of module `parent` to be `def` if it is not yet defined;
@@ -84,11 +79,11 @@ impl<'b> Resolver<'b> {
8479
}
8580

8681
/// Constructs the reduced graph for one item.
87-
fn build_reduced_graph_for_item(&mut self, item: &Item, parent_ref: &mut Module<'b>) {
88-
let parent = *parent_ref;
82+
fn build_reduced_graph_for_item(&mut self, item: &Item) {
83+
let parent = self.current_module;
84+
let parent_vis = self.current_vis;
8985
let name = item.ident.name;
9086
let sp = item.span;
91-
self.current_module = parent;
9287
let vis = self.resolve_visibility(&item.vis);
9388

9489
match item.node {
@@ -130,8 +125,7 @@ impl<'b> Resolver<'b> {
130125

131126
let subclass = ImportDirectiveSubclass::single(binding.name, source_name);
132127
let span = view_path.span;
133-
parent.add_import_directive(module_path, subclass, span, item.id, vis);
134-
self.unresolved_imports += 1;
128+
self.add_import_directive(module_path, subclass, span, item.id, vis);
135129
}
136130
ViewPathList(_, ref source_items) => {
137131
// Make sure there's at most one `mod` import in the list.
@@ -176,15 +170,13 @@ impl<'b> Resolver<'b> {
176170
};
177171
let subclass = ImportDirectiveSubclass::single(rename, name);
178172
let (span, id) = (source_item.span, source_item.node.id());
179-
parent.add_import_directive(module_path, subclass, span, id, vis);
180-
self.unresolved_imports += 1;
173+
self.add_import_directive(module_path, subclass, span, id, vis);
181174
}
182175
}
183176
ViewPathGlob(_) => {
184177
let subclass = GlobImport { is_prelude: is_prelude };
185178
let span = view_path.span;
186-
parent.add_import_directive(module_path, subclass, span, item.id, vis);
187-
self.unresolved_imports += 1;
179+
self.add_import_directive(module_path, subclass, span, item.id, vis);
188180
}
189181
}
190182
}
@@ -216,7 +208,10 @@ impl<'b> Resolver<'b> {
216208
});
217209
self.define(parent, name, TypeNS, (module, sp, vis));
218210
self.module_map.insert(item.id, module);
219-
*parent_ref = module;
211+
212+
// Descend into the module.
213+
self.current_module = module;
214+
self.current_vis = ty::Visibility::Restricted(item.id);
220215
}
221216

222217
ItemKind::ForeignMod(..) => {}
@@ -309,6 +304,10 @@ impl<'b> Resolver<'b> {
309304
}
310305
ItemKind::Mac(_) => panic!("unexpanded macro in resolve!"),
311306
}
307+
308+
visit::walk_item(&mut BuildReducedGraphVisitor { resolver: self }, item);
309+
self.current_module = parent;
310+
self.current_vis = parent_vis;
312311
}
313312

314313
// Constructs the reduced graph for one variant. Variants exist in the
@@ -333,9 +332,8 @@ impl<'b> Resolver<'b> {
333332
}
334333

335334
/// Constructs the reduced graph for one foreign item.
336-
fn build_reduced_graph_for_foreign_item(&mut self,
337-
foreign_item: &ForeignItem,
338-
parent: Module<'b>) {
335+
fn build_reduced_graph_for_foreign_item(&mut self, foreign_item: &ForeignItem) {
336+
let parent = self.current_module;
339337
let name = foreign_item.ident.name;
340338

341339
let def = match foreign_item.node {
@@ -346,12 +344,12 @@ impl<'b> Resolver<'b> {
346344
Def::Static(self.definitions.local_def_id(foreign_item.id), m)
347345
}
348346
};
349-
self.current_module = parent;
350347
let vis = self.resolve_visibility(&foreign_item.vis);
351348
self.define(parent, name, ValueNS, (def, foreign_item.span, vis));
352349
}
353350

354-
fn build_reduced_graph_for_block(&mut self, block: &Block, parent: &mut Module<'b>) {
351+
fn build_reduced_graph_for_block(&mut self, block: &Block) {
352+
let parent = self.current_module;
355353
if self.block_needs_anonymous_module(block) {
356354
let block_id = block.id;
357355

@@ -362,8 +360,11 @@ impl<'b> Resolver<'b> {
362360
let parent_link = BlockParentLink(parent, block_id);
363361
let new_module = self.new_module(parent_link, None, false);
364362
self.module_map.insert(block_id, new_module);
365-
*parent = new_module;
363+
self.current_module = new_module; // Descend into the block.
366364
}
365+
366+
visit::walk_block(&mut BuildReducedGraphVisitor { resolver: self }, block);
367+
self.current_module = parent;
367368
}
368369

369370
/// Builds the reduced graph for a single item in an external crate.
@@ -487,25 +488,18 @@ impl<'b> Resolver<'b> {
487488

488489
struct BuildReducedGraphVisitor<'a, 'b: 'a> {
489490
resolver: &'a mut Resolver<'b>,
490-
parent: Module<'b>,
491491
}
492492

493493
impl<'a, 'b> Visitor for BuildReducedGraphVisitor<'a, 'b> {
494494
fn visit_item(&mut self, item: &Item) {
495-
let old_parent = self.parent;
496-
self.resolver.build_reduced_graph_for_item(item, &mut self.parent);
497-
visit::walk_item(self, item);
498-
self.parent = old_parent;
495+
self.resolver.build_reduced_graph_for_item(item);
499496
}
500497

501498
fn visit_foreign_item(&mut self, foreign_item: &ForeignItem) {
502-
self.resolver.build_reduced_graph_for_foreign_item(foreign_item, &self.parent);
499+
self.resolver.build_reduced_graph_for_foreign_item(foreign_item);
503500
}
504501

505502
fn visit_block(&mut self, block: &Block) {
506-
let old_parent = self.parent;
507-
self.resolver.build_reduced_graph_for_block(block, &mut self.parent);
508-
visit::walk_block(self, block);
509-
self.parent = old_parent;
503+
self.resolver.build_reduced_graph_for_block(block);
510504
}
511505
}

‎src/librustc_resolve/lib.rs

Lines changed: 56 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -758,11 +758,10 @@ pub struct ModuleS<'a> {
758758
extern_crate_id: Option<NodeId>,
759759

760760
resolutions: RefCell<HashMap<(Name, Namespace), &'a RefCell<NameResolution<'a>>>>,
761-
unresolved_imports: RefCell<Vec<&'a ImportDirective<'a>>>,
762761

763762
no_implicit_prelude: Cell<bool>,
764763

765-
glob_importers: RefCell<Vec<(Module<'a>, &'a ImportDirective<'a>)>>,
764+
glob_importers: RefCell<Vec<&'a ImportDirective<'a>>>,
766765
globs: RefCell<Vec<&'a ImportDirective<'a>>>,
767766

768767
// Used to memoize the traits in this module for faster searches through all traits in scope.
@@ -772,29 +771,22 @@ pub struct ModuleS<'a> {
772771
// access the children must be preceded with a
773772
// `populate_module_if_necessary` call.
774773
populated: Cell<bool>,
775-
776-
arenas: &'a ResolverArenas<'a>,
777774
}
778775

779776
pub type Module<'a> = &'a ModuleS<'a>;
780777

781778
impl<'a> ModuleS<'a> {
782-
fn new(parent_link: ParentLink<'a>,
783-
def: Option<Def>,
784-
external: bool,
785-
arenas: &'a ResolverArenas<'a>) -> Self {
779+
fn new(parent_link: ParentLink<'a>, def: Option<Def>, external: bool) -> Self {
786780
ModuleS {
787781
parent_link: parent_link,
788782
def: def,
789783
extern_crate_id: None,
790784
resolutions: RefCell::new(HashMap::new()),
791-
unresolved_imports: RefCell::new(Vec::new()),
792785
no_implicit_prelude: Cell::new(false),
793786
glob_importers: RefCell::new(Vec::new()),
794787
globs: RefCell::new((Vec::new())),
795788
traits: RefCell::new(None),
796789
populated: Cell::new(!external),
797-
arenas: arenas
798790
}
799791
}
800792

@@ -971,12 +963,19 @@ pub struct Resolver<'a> {
971963

972964
structs: FnvHashMap<DefId, Vec<Name>>,
973965

974-
// The number of imports that are currently unresolved.
975-
unresolved_imports: usize,
966+
// All imports known to succeed or fail.
967+
determined_imports: Vec<&'a ImportDirective<'a>>,
968+
969+
// All non-determined imports.
970+
indeterminate_imports: Vec<&'a ImportDirective<'a>>,
976971

977972
// The module that represents the current item scope.
978973
current_module: Module<'a>,
979974

975+
// The visibility of `pub(self)` items in the current scope.
976+
// Equivalently, the visibility required for an item to be accessible from the current scope.
977+
current_vis: ty::Visibility,
978+
980979
// The current set of local scopes, for values.
981980
// FIXME #4948: Reuse ribs to avoid allocation.
982981
value_ribs: Vec<Rib<'a>>,
@@ -1140,7 +1139,7 @@ impl<'a> Resolver<'a> {
11401139
-> Resolver<'a> {
11411140
let root_def_id = DefId::local(CRATE_DEF_INDEX);
11421141
let graph_root =
1143-
ModuleS::new(NoParentLink, Some(Def::Mod(root_def_id)), false, arenas);
1142+
ModuleS::new(NoParentLink, Some(Def::Mod(root_def_id)), false);
11441143
let graph_root = arenas.alloc_module(graph_root);
11451144
let mut module_map = NodeMap();
11461145
module_map.insert(CRATE_NODE_ID, graph_root);
@@ -1159,9 +1158,11 @@ impl<'a> Resolver<'a> {
11591158
trait_item_map: FnvHashMap(),
11601159
structs: FnvHashMap(),
11611160

1162-
unresolved_imports: 0,
1161+
determined_imports: Vec::new(),
1162+
indeterminate_imports: Vec::new(),
11631163

11641164
current_module: graph_root,
1165+
current_vis: ty::Visibility::Restricted(ast::CRATE_NODE_ID),
11651166
value_ribs: vec![Rib::new(ModuleRibKind(graph_root))],
11661167
type_ribs: vec![Rib::new(ModuleRibKind(graph_root))],
11671168
label_ribs: Vec::new(),
@@ -1205,6 +1206,7 @@ impl<'a> Resolver<'a> {
12051206
/// Entry point to crate resolution.
12061207
pub fn resolve_crate(&mut self, krate: &Crate) {
12071208
self.current_module = self.graph_root;
1209+
self.current_vis = ty::Visibility::Restricted(ast::CRATE_NODE_ID);
12081210
visit::walk_crate(self, krate);
12091211

12101212
check_unused::check_crate(self, krate);
@@ -1213,12 +1215,12 @@ impl<'a> Resolver<'a> {
12131215

12141216
fn new_module(&self, parent_link: ParentLink<'a>, def: Option<Def>, external: bool)
12151217
-> Module<'a> {
1216-
self.arenas.alloc_module(ModuleS::new(parent_link, def, external, self.arenas))
1218+
self.arenas.alloc_module(ModuleS::new(parent_link, def, external))
12171219
}
12181220

12191221
fn new_extern_crate_module(&self, parent_link: ParentLink<'a>, def: Def, local_node_id: NodeId)
12201222
-> Module<'a> {
1221-
let mut module = ModuleS::new(parent_link, Some(def), false, self.arenas);
1223+
let mut module = ModuleS::new(parent_link, Some(def), false);
12221224
module.extern_crate_id = Some(local_node_id);
12231225
self.arenas.modules.alloc(module)
12241226
}
@@ -1250,14 +1252,15 @@ impl<'a> Resolver<'a> {
12501252
mut search_module: Module<'a>,
12511253
module_path: &[Name],
12521254
index: usize,
1253-
span: Span)
1255+
span: Option<Span>)
12541256
-> ResolveResult<Module<'a>> {
1255-
fn search_parent_externals(needle: Name, module: Module) -> Option<Module> {
1256-
match module.resolve_name(needle, TypeNS, false) {
1257+
fn search_parent_externals<'a>(this: &mut Resolver<'a>, needle: Name, module: Module<'a>)
1258+
-> Option<Module<'a>> {
1259+
match this.resolve_name_in_module(module, needle, TypeNS, false, None) {
12571260
Success(binding) if binding.is_extern_crate() => Some(module),
12581261
_ => match module.parent_link {
12591262
ModuleParentLink(ref parent, _) => {
1260-
search_parent_externals(needle, parent)
1263+
search_parent_externals(this, needle, parent)
12611264
}
12621265
_ => None,
12631266
},
@@ -1272,16 +1275,17 @@ impl<'a> Resolver<'a> {
12721275
// modules as we go.
12731276
while index < module_path_len {
12741277
let name = module_path[index];
1275-
match self.resolve_name_in_module(search_module, name, TypeNS, false, true) {
1278+
match self.resolve_name_in_module(search_module, name, TypeNS, false, span) {
12761279
Failed(None) => {
12771280
let segment_name = name.as_str();
12781281
let module_name = module_to_string(search_module);
12791282
let msg = if "???" == &module_name {
1280-
match search_parent_externals(name, &self.current_module) {
1283+
let current_module = self.current_module;
1284+
match search_parent_externals(self, name, current_module) {
12811285
Some(module) => {
12821286
let path_str = names_to_string(module_path);
12831287
let target_mod_str = module_to_string(&module);
1284-
let current_mod_str = module_to_string(&self.current_module);
1288+
let current_mod_str = module_to_string(current_module);
12851289

12861290
let prefix = if target_mod_str == current_mod_str {
12871291
"self::".to_string()
@@ -1297,7 +1301,7 @@ impl<'a> Resolver<'a> {
12971301
format!("Could not find `{}` in `{}`", segment_name, module_name)
12981302
};
12991303

1300-
return Failed(Some((span, msg)));
1304+
return Failed(span.map(|span| (span, msg)));
13011305
}
13021306
Failed(err) => return Failed(err),
13031307
Indeterminate => {
@@ -1310,11 +1314,10 @@ impl<'a> Resolver<'a> {
13101314
// Check to see whether there are type bindings, and, if
13111315
// so, whether there is a module within.
13121316
if let Some(module_def) = binding.module() {
1313-
self.check_privacy(name, binding, span);
13141317
search_module = module_def;
13151318
} else {
13161319
let msg = format!("Not a module `{}`", name);
1317-
return Failed(Some((span, msg)));
1320+
return Failed(span.map(|span| (span, msg)));
13181321
}
13191322
}
13201323
}
@@ -1330,7 +1333,7 @@ impl<'a> Resolver<'a> {
13301333
fn resolve_module_path(&mut self,
13311334
module_path: &[Name],
13321335
use_lexical_scope: UseLexicalScopeFlag,
1333-
span: Span)
1336+
span: Option<Span>)
13341337
-> ResolveResult<Module<'a>> {
13351338
if module_path.len() == 0 {
13361339
return Success(self.graph_root) // Use the crate root
@@ -1367,7 +1370,7 @@ impl<'a> Resolver<'a> {
13671370
// first component of the path in the current lexical
13681371
// scope and then proceed to resolve below that.
13691372
let ident = ast::Ident::with_empty_ctxt(module_path[0]);
1370-
match self.resolve_ident_in_lexical_scope(ident, TypeNS, true)
1373+
match self.resolve_ident_in_lexical_scope(ident, TypeNS, span)
13711374
.and_then(LexicalScopeBinding::module) {
13721375
None => return Failed(None),
13731376
Some(containing_module) => {
@@ -1384,10 +1387,7 @@ impl<'a> Resolver<'a> {
13841387
}
13851388
}
13861389

1387-
self.resolve_module_path_from_root(search_module,
1388-
module_path,
1389-
start_index,
1390-
span)
1390+
self.resolve_module_path_from_root(search_module, module_path, start_index, span)
13911391
}
13921392

13931393
/// This resolves the identifier `ident` in the namespace `ns` in the current lexical scope.
@@ -1410,7 +1410,7 @@ impl<'a> Resolver<'a> {
14101410
fn resolve_ident_in_lexical_scope(&mut self,
14111411
mut ident: ast::Ident,
14121412
ns: Namespace,
1413-
record_used: bool)
1413+
record_used: Option<Span>)
14141414
-> Option<LexicalScopeBinding<'a>> {
14151415
if ns == TypeNS {
14161416
ident = ast::Ident::with_empty_ctxt(ident.name);
@@ -1438,8 +1438,8 @@ impl<'a> Resolver<'a> {
14381438
if module.def.is_some() {
14391439
return match self.prelude {
14401440
Some(prelude) if !module.no_implicit_prelude.get() => {
1441-
prelude.resolve_name(name, ns, false).success()
1442-
.map(LexicalScopeBinding::Item)
1441+
self.resolve_name_in_module(prelude, name, ns, false, None).success()
1442+
.map(LexicalScopeBinding::Item)
14431443
}
14441444
_ => None,
14451445
};
@@ -1491,7 +1491,7 @@ impl<'a> Resolver<'a> {
14911491
/// Resolves a "module prefix". A module prefix is one or both of (a) `self::`;
14921492
/// (b) some chain of `super::`.
14931493
/// grammar: (SELF MOD_SEP ) ? (SUPER MOD_SEP) *
1494-
fn resolve_module_prefix(&mut self, module_path: &[Name], span: Span)
1494+
fn resolve_module_prefix(&mut self, module_path: &[Name], span: Option<Span>)
14951495
-> ResolveResult<ModulePrefixResult<'a>> {
14961496
// Start at the current module if we see `self` or `super`, or at the
14971497
// top of the crate otherwise.
@@ -1510,7 +1510,7 @@ impl<'a> Resolver<'a> {
15101510
match self.get_nearest_normal_module_parent(containing_module) {
15111511
None => {
15121512
let msg = "There are too many initial `super`s.".into();
1513-
return Failed(Some((span, msg)));
1513+
return Failed(span.map(|span| (span, msg)));
15141514
}
15151515
Some(new_module) => {
15161516
containing_module = new_module;
@@ -1525,27 +1525,6 @@ impl<'a> Resolver<'a> {
15251525
return Success(PrefixFound(containing_module, i));
15261526
}
15271527

1528-
/// Attempts to resolve the supplied name in the given module for the
1529-
/// given namespace. If successful, returns the binding corresponding to
1530-
/// the name.
1531-
fn resolve_name_in_module(&mut self,
1532-
module: Module<'a>,
1533-
name: Name,
1534-
namespace: Namespace,
1535-
use_lexical_scope: bool,
1536-
record_used: bool)
1537-
-> ResolveResult<&'a NameBinding<'a>> {
1538-
debug!("(resolving name in module) resolving `{}` in `{}`", name, module_to_string(module));
1539-
1540-
self.populate_module_if_necessary(module);
1541-
module.resolve_name(name, namespace, use_lexical_scope).and_then(|binding| {
1542-
if record_used {
1543-
self.record_use(name, namespace, binding);
1544-
}
1545-
Success(binding)
1546-
})
1547-
}
1548-
15491528
// AST resolution
15501529
//
15511530
// We maintain a list of value ribs and type ribs.
@@ -1570,13 +1549,15 @@ impl<'a> Resolver<'a> {
15701549
let module = self.module_map.get(&id).cloned(); // clones a reference
15711550
if let Some(module) = module {
15721551
// Move down in the graph.
1573-
let orig_module = ::std::mem::replace(&mut self.current_module, module);
1552+
let orig_module = replace(&mut self.current_module, module);
1553+
let orig_vis = replace(&mut self.current_vis, ty::Visibility::Restricted(id));
15741554
self.value_ribs.push(Rib::new(ModuleRibKind(module)));
15751555
self.type_ribs.push(Rib::new(ModuleRibKind(module)));
15761556

15771557
f(self);
15781558

15791559
self.current_module = orig_module;
1560+
self.current_vis = orig_vis;
15801561
self.value_ribs.pop();
15811562
self.type_ribs.pop();
15821563
} else {
@@ -2314,7 +2295,7 @@ impl<'a> Resolver<'a> {
23142295
PatKind::Ident(bmode, ref ident, ref opt_pat) => {
23152296
// First try to resolve the identifier as some existing
23162297
// entity, then fall back to a fresh binding.
2317-
let binding = self.resolve_ident_in_lexical_scope(ident.node, ValueNS, false)
2298+
let binding = self.resolve_ident_in_lexical_scope(ident.node, ValueNS, None)
23182299
.and_then(LexicalScopeBinding::item);
23192300
let resolution = binding.and_then(NameBinding::def).and_then(|def| {
23202301
let always_binding = !pat_src.is_refutable() || opt_pat.is_some() ||
@@ -2481,11 +2462,11 @@ impl<'a> Resolver<'a> {
24812462
//
24822463
// Such behavior is required for backward compatibility.
24832464
// The same fallback is used when `a` resolves to nothing.
2484-
let def = resolve_identifier_with_fallback(self, true).ok_or(false);
2465+
let def = resolve_identifier_with_fallback(self, Some(span)).ok_or(false);
24852466
return def.and_then(|def| self.adjust_local_def(def, span).ok_or(true)).map(mk_res);
24862467
}
24872468

2488-
let unqualified_def = resolve_identifier_with_fallback(self, false);
2469+
let unqualified_def = resolve_identifier_with_fallback(self, None);
24892470
let qualified_binding = self.resolve_module_relative_path(span, segments, namespace);
24902471
match (qualified_binding, unqualified_def) {
24912472
(Ok(binding), Some(ref ud)) if binding.def().unwrap() == ud.def => {
@@ -2505,7 +2486,7 @@ impl<'a> Resolver<'a> {
25052486
fn resolve_identifier(&mut self,
25062487
identifier: ast::Ident,
25072488
namespace: Namespace,
2508-
record_used: bool)
2489+
record_used: Option<Span>)
25092490
-> Option<LocalDef> {
25102491
if identifier.name == keywords::Invalid.name() {
25112492
return None;
@@ -2619,7 +2600,7 @@ impl<'a> Resolver<'a> {
26192600
.collect::<Vec<_>>();
26202601

26212602
let containing_module;
2622-
match self.resolve_module_path(&module_path, UseLexicalScope, span) {
2603+
match self.resolve_module_path(&module_path, UseLexicalScope, Some(span)) {
26232604
Failed(err) => {
26242605
let (span, msg) = match err {
26252606
Some((span, msg)) => (span, msg),
@@ -2640,11 +2621,9 @@ impl<'a> Resolver<'a> {
26402621
}
26412622

26422623
let name = segments.last().unwrap().identifier.name;
2643-
let result = self.resolve_name_in_module(containing_module, name, namespace, false, true);
2644-
result.success().map(|binding| {
2645-
self.check_privacy(name, binding, span);
2646-
binding
2647-
}).ok_or(false)
2624+
let result =
2625+
self.resolve_name_in_module(containing_module, name, namespace, false, Some(span));
2626+
result.success().ok_or(false)
26482627
}
26492628

26502629
/// Invariant: This must be called only during main resolution, not during
@@ -2658,10 +2637,7 @@ impl<'a> Resolver<'a> {
26582637
let root_module = self.graph_root;
26592638

26602639
let containing_module;
2661-
match self.resolve_module_path_from_root(root_module,
2662-
&module_path,
2663-
0,
2664-
span) {
2640+
match self.resolve_module_path_from_root(root_module, &module_path, 0, Some(span)) {
26652641
Failed(err) => {
26662642
let (span, msg) = match err {
26672643
Some((span, msg)) => (span, msg),
@@ -2684,11 +2660,9 @@ impl<'a> Resolver<'a> {
26842660
}
26852661

26862662
let name = segments.last().unwrap().name();
2687-
let result = self.resolve_name_in_module(containing_module, name, namespace, false, true);
2688-
result.success().map(|binding| {
2689-
self.check_privacy(name, binding, span);
2690-
binding
2691-
}).ok_or(false)
2663+
let result =
2664+
self.resolve_name_in_module(containing_module, name, namespace, false, Some(span));
2665+
result.success().ok_or(false)
26922666
}
26932667

26942668
fn with_no_errors<T, F>(&mut self, f: F) -> T
@@ -2716,7 +2690,6 @@ impl<'a> Resolver<'a> {
27162690
fn with_empty_ribs<T, F>(&mut self, f: F) -> T
27172691
where F: FnOnce(&mut Resolver<'a>) -> T,
27182692
{
2719-
use ::std::mem::replace;
27202693
let value_ribs = replace(&mut self.value_ribs, Vec::new());
27212694
let type_ribs = replace(&mut self.type_ribs, Vec::new());
27222695
let label_ribs = replace(&mut self.label_ribs, Vec::new());
@@ -2941,7 +2914,7 @@ impl<'a> Resolver<'a> {
29412914

29422915
match self.resolve_module_path(&name_path[..],
29432916
UseLexicalScope,
2944-
expr.span) {
2917+
Some(expr.span)) {
29452918
Success(e) => {
29462919
if let Some(def_type) = e.def {
29472920
def = def_type;
@@ -3274,18 +3247,12 @@ impl<'a> Resolver<'a> {
32743247
ast::Visibility::Public => return ty::Visibility::Public,
32753248
ast::Visibility::Crate(_) => return ty::Visibility::Restricted(ast::CRATE_NODE_ID),
32763249
ast::Visibility::Restricted { ref path, id } => (path, id),
3277-
ast::Visibility::Inherited => {
3278-
let current_module =
3279-
self.get_nearest_normal_module_parent_or_self(self.current_module);
3280-
let id =
3281-
self.definitions.as_local_node_id(current_module.def_id().unwrap()).unwrap();
3282-
return ty::Visibility::Restricted(id);
3283-
}
3250+
ast::Visibility::Inherited => return self.current_vis,
32843251
};
32853252

32863253
let segments: Vec<_> = path.segments.iter().map(|seg| seg.identifier.name).collect();
32873254
let mut path_resolution = err_path_resolution();
3288-
let vis = match self.resolve_module_path(&segments, DontUseLexicalScope, path.span) {
3255+
let vis = match self.resolve_module_path(&segments, DontUseLexicalScope, Some(path.span)) {
32893256
Success(module) => {
32903257
let def = module.def.unwrap();
32913258
path_resolution = PathResolution::new(def);
@@ -3309,15 +3276,7 @@ impl<'a> Resolver<'a> {
33093276
}
33103277

33113278
fn is_accessible(&self, vis: ty::Visibility) -> bool {
3312-
let current_module = self.get_nearest_normal_module_parent_or_self(self.current_module);
3313-
let node_id = self.definitions.as_local_node_id(current_module.def_id().unwrap()).unwrap();
3314-
vis.is_accessible_from(node_id, self)
3315-
}
3316-
3317-
fn check_privacy(&mut self, name: Name, binding: &'a NameBinding<'a>, span: Span) {
3318-
if !self.is_accessible(binding.vis) {
3319-
self.privacy_errors.push(PrivacyError(span, name, binding));
3320-
}
3279+
vis.is_at_least(self.current_vis, self)
33213280
}
33223281

33233282
fn report_privacy_errors(&self) {

‎src/librustc_resolve/resolve_imports.rs

Lines changed: 295 additions & 273 deletions
Large diffs are not rendered by default.

‎src/test/compile-fail/task-rng-isnt-sendable.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@ fn test_send<S: Send>() {}
1616

1717
pub fn main() {
1818
test_send::<rand::ThreadRng>();
19-
//~^ ERROR : std::marker::Send` is not satisfied
2019
}

‎src/test/compile-fail/use-from-trait-xc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ use use_from_trait_xc::Trait::Assoc;
2121
use use_from_trait_xc::Trait::CONST;
2222
//~^ ERROR `CONST` is not directly importable
2323

24-
use use_from_trait_xc::Foo::new;
24+
use use_from_trait_xc::Foo::new; //~ ERROR struct `Foo` is private
2525
//~^ ERROR unresolved import `use_from_trait_xc::Foo::new`
2626

27-
use use_from_trait_xc::Foo::C;
27+
use use_from_trait_xc::Foo::C; //~ ERROR struct `Foo` is private
2828
//~^ ERROR unresolved import `use_from_trait_xc::Foo::C`
2929

3030
use use_from_trait_xc::Bar::new as bnew;

0 commit comments

Comments
 (0)
Please sign in to comment.