Skip to content

Commit bf41c85

Browse files
committed
Cleanup.
1 parent b4d3df6 commit bf41c85

File tree

4 files changed

+22
-60
lines changed

4 files changed

+22
-60
lines changed

src/librustc_resolve/build_reduced_graph.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ impl<'b> Resolver<'b> {
582582
});
583583
} else {
584584
for (name, span) in legacy_imports.imports {
585-
let result = self.resolve_name_in_module(module, name, MacroNS, false, false, None);
585+
let result = self.resolve_name_in_module(module, name, MacroNS, false, None);
586586
if let Success(binding) = result {
587587
self.legacy_import_macro(name, binding, span, allow_shadowing);
588588
} else {
@@ -592,7 +592,7 @@ impl<'b> Resolver<'b> {
592592
}
593593
for (name, span) in legacy_imports.reexports {
594594
self.used_crates.insert(module.def_id().unwrap().krate);
595-
let result = self.resolve_name_in_module(module, name, MacroNS, false, false, None);
595+
let result = self.resolve_name_in_module(module, name, MacroNS, false, None);
596596
if let Success(binding) = result {
597597
self.macro_exports.push(Export { name: name, def: binding.def() });
598598
} else {

src/librustc_resolve/lib.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,6 @@ pub struct Resolver<'a> {
11311131

11321132
arenas: &'a ResolverArenas<'a>,
11331133
dummy_binding: &'a NameBinding<'a>,
1134-
new_import_semantics: bool, // true if `#![feature(item_like_imports)]`
11351134
use_extern_macros: bool, // true if `#![feature(use_extern_macros)]`
11361135

11371136
pub exported_macros: Vec<ast::MacroDef>,
@@ -1333,7 +1332,6 @@ impl<'a> Resolver<'a> {
13331332
span: DUMMY_SP,
13341333
vis: ty::Visibility::Public,
13351334
}),
1336-
new_import_semantics: true,
13371335
use_extern_macros: session.features.borrow().use_extern_macros,
13381336

13391337
exported_macros: Vec::new(),
@@ -1442,7 +1440,7 @@ impl<'a> Resolver<'a> {
14421440
-> ResolveResult<Module<'a>> {
14431441
fn search_parent_externals<'a>(this: &mut Resolver<'a>, needle: Name, module: Module<'a>)
14441442
-> Option<Module<'a>> {
1445-
match this.resolve_name_in_module(module, needle, TypeNS, false, false, None) {
1443+
match this.resolve_name_in_module(module, needle, TypeNS, false, None) {
14461444
Success(binding) if binding.is_extern_crate() => Some(module),
14471445
_ => if let (&ModuleKind::Def(..), Some(parent)) = (&module.kind, module.parent) {
14481446
search_parent_externals(this, needle, parent)
@@ -1460,7 +1458,7 @@ impl<'a> Resolver<'a> {
14601458
// modules as we go.
14611459
while index < module_path_len {
14621460
let name = module_path[index].name;
1463-
match self.resolve_name_in_module(search_module, name, TypeNS, false, false, span) {
1461+
match self.resolve_name_in_module(search_module, name, TypeNS, false, span) {
14641462
Failed(_) => {
14651463
let segment_name = name.as_str();
14661464
let module_name = module_to_string(search_module);
@@ -1617,7 +1615,7 @@ impl<'a> Resolver<'a> {
16171615

16181616
if let ModuleRibKind(module) = self.ribs[ns][i].kind {
16191617
let name = ident.name;
1620-
let item = self.resolve_name_in_module(module, name, ns, true, false, record_used);
1618+
let item = self.resolve_name_in_module(module, name, ns, false, record_used);
16211619
if let Success(binding) = item {
16221620
// The ident resolves to an item.
16231621
return Some(LexicalScopeBinding::Item(binding));
@@ -1626,7 +1624,7 @@ impl<'a> Resolver<'a> {
16261624
if let ModuleKind::Block(..) = module.kind { // We can see through blocks
16271625
} else if !module.no_implicit_prelude {
16281626
return self.prelude.and_then(|prelude| {
1629-
self.resolve_name_in_module(prelude, name, ns, false, false, None).success()
1627+
self.resolve_name_in_module(prelude, name, ns, false, None).success()
16301628
}).map(LexicalScopeBinding::Item)
16311629
} else {
16321630
return None;
@@ -2772,7 +2770,7 @@ impl<'a> Resolver<'a> {
27722770
};
27732771

27742772
let name = segments.last().unwrap().identifier.name;
2775-
let result = self.resolve_name_in_module(module, name, namespace, false, false, Some(span));
2773+
let result = self.resolve_name_in_module(module, name, namespace, false, Some(span));
27762774
result.success().ok_or(false)
27772775
}
27782776

@@ -2800,7 +2798,7 @@ impl<'a> Resolver<'a> {
28002798
};
28012799

28022800
let name = segments.last().unwrap().ident().name;
2803-
let result = self.resolve_name_in_module(module, name, namespace, false, false, Some(span));
2801+
let result = self.resolve_name_in_module(module, name, namespace, false, Some(span));
28042802
result.success().ok_or(false)
28052803
}
28062804

src/librustc_resolve/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ impl<'a> Resolver<'a> {
272272
loop {
273273
// Since expanded macros may not shadow the lexical scope (enforced below),
274274
// we can ignore unresolved invocations (indicated by the penultimate argument).
275-
match self.resolve_name_in_module(module, name, ns, true, true, record_used) {
275+
match self.resolve_name_in_module(module, name, ns, true, record_used) {
276276
Success(binding) => {
277277
let span = match record_used {
278278
Some(span) => span,

src/librustc_resolve/resolve_imports.rs

+13-49
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ pub struct NameResolution<'a> {
7575
single_imports: SingleImports<'a>,
7676
/// The least shadowable known binding for this name, or None if there are no known bindings.
7777
pub binding: Option<&'a NameBinding<'a>>,
78-
duplicate_globs: Vec<&'a NameBinding<'a>>,
7978
}
8079

8180
#[derive(Clone, Debug)]
@@ -141,7 +140,6 @@ impl<'a> Resolver<'a> {
141140
module: Module<'a>,
142141
name: Name,
143142
ns: Namespace,
144-
allow_private_imports: bool,
145143
ignore_unresolved_invocations: bool,
146144
record_used: Option<Span>)
147145
-> ResolveResult<&'a NameBinding<'a>> {
@@ -153,18 +151,8 @@ impl<'a> Resolver<'a> {
153151
_ => return Failed(None), // This happens when there is a cycle of imports
154152
};
155153

156-
let new_import_semantics = self.new_import_semantics;
157-
let is_disallowed_private_import = |binding: &NameBinding| {
158-
!new_import_semantics && !allow_private_imports && // disallowed
159-
binding.vis != ty::Visibility::Public && binding.is_import() && // non-`pub` import
160-
!binding.is_extern_crate() // not an `extern crate`
161-
};
162-
163154
if let Some(span) = record_used {
164155
if let Some(binding) = resolution.binding {
165-
if is_disallowed_private_import(binding) {
166-
return Failed(None);
167-
}
168156
if self.record_use(name, ns, binding, span) {
169157
return Success(self.dummy_binding);
170158
}
@@ -177,9 +165,8 @@ impl<'a> Resolver<'a> {
177165
}
178166

179167
let check_usable = |this: &mut Self, binding: &'a NameBinding<'a>| {
180-
let usable =
181-
this.is_accessible(binding.vis) && !is_disallowed_private_import(binding) ||
182-
binding.is_extern_crate(); // c.f. issue #37020
168+
// `extern crate` are always usable for backwards compatability, see issue #37020.
169+
let usable = this.is_accessible(binding.vis) || binding.is_extern_crate();
183170
if usable { Success(binding) } else { Failed(None) }
184171
};
185172

@@ -202,7 +189,7 @@ impl<'a> Resolver<'a> {
202189
SingleImport { source, .. } => source,
203190
_ => unreachable!(),
204191
};
205-
match self.resolve_name_in_module(module, name, ns, true, false, None) {
192+
match self.resolve_name_in_module(module, name, ns, false, None) {
206193
Failed(_) => {}
207194
_ => return Indeterminate,
208195
}
@@ -224,7 +211,7 @@ impl<'a> Resolver<'a> {
224211
for directive in module.globs.borrow().iter() {
225212
if self.is_accessible(directive.vis.get()) {
226213
if let Some(module) = directive.imported_module.get() {
227-
let result = self.resolve_name_in_module(module, name, ns, true, false, None);
214+
let result = self.resolve_name_in_module(module, name, ns, false, None);
228215
if let Indeterminate = result {
229216
return Indeterminate;
230217
}
@@ -311,22 +298,17 @@ impl<'a> Resolver<'a> {
311298
self.update_resolution(module, name, ns, |this, resolution| {
312299
if let Some(old_binding) = resolution.binding {
313300
if binding.is_glob_import() {
314-
if !this.new_import_semantics {
315-
resolution.duplicate_globs.push(binding);
316-
} else if !old_binding.is_glob_import() &&
317-
!(ns == MacroNS && old_binding.expansion != Mark::root()) {
301+
if !old_binding.is_glob_import() &&
302+
!(ns == MacroNS && old_binding.expansion != Mark::root()) {
318303
} else if binding.def() != old_binding.def() {
319304
resolution.binding = Some(this.ambiguity(old_binding, binding));
320305
} else if !old_binding.vis.is_at_least(binding.vis, this) {
321306
// We are glob-importing the same item but with greater visibility.
322307
resolution.binding = Some(binding);
323308
}
324309
} else if old_binding.is_glob_import() {
325-
if !this.new_import_semantics {
326-
resolution.duplicate_globs.push(old_binding);
327-
resolution.binding = Some(binding);
328-
} else if ns == MacroNS && binding.expansion != Mark::root() &&
329-
binding.def() != old_binding.def() {
310+
if ns == MacroNS && binding.expansion != Mark::root() &&
311+
binding.def() != old_binding.def() {
330312
resolution.binding = Some(this.ambiguity(binding, old_binding));
331313
} else {
332314
resolution.binding = Some(binding);
@@ -366,7 +348,7 @@ impl<'a> Resolver<'a> {
366348
let t = f(self, resolution);
367349

368350
match resolution.binding() {
369-
_ if !self.new_import_semantics && old_binding.is_some() => return t,
351+
_ if old_binding.is_some() => return t,
370352
None => return t,
371353
Some(binding) => match old_binding {
372354
Some(old_binding) if old_binding as *const _ == binding as *const _ => return t,
@@ -377,10 +359,7 @@ impl<'a> Resolver<'a> {
377359

378360
// Define `binding` in `module`s glob importers.
379361
for directive in module.glob_importers.borrow_mut().iter() {
380-
if match self.new_import_semantics {
381-
true => self.is_accessible_from(binding.vis, directive.parent),
382-
false => binding.vis == ty::Visibility::Public,
383-
} {
362+
if self.is_accessible_from(binding.vis, directive.parent) {
384363
let imported_binding = self.import(binding, directive);
385364
let _ = self.try_define(directive.parent, name, ns, imported_binding);
386365
}
@@ -528,7 +507,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
528507
self.per_ns(|this, ns| {
529508
if let Err(Undetermined) = result[ns].get() {
530509
result[ns].set({
531-
match this.resolve_name_in_module(module, source, ns, false, false, None) {
510+
match this.resolve_name_in_module(module, source, ns, false, None) {
532511
Success(binding) => Ok(binding),
533512
Indeterminate => Err(Undetermined),
534513
Failed(_) => Err(Determined),
@@ -624,7 +603,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
624603
if all_ns_err {
625604
let mut all_ns_failed = true;
626605
self.per_ns(|this, ns| {
627-
match this.resolve_name_in_module(module, name, ns, false, false, Some(span)) {
606+
match this.resolve_name_in_module(module, name, ns, false, Some(span)) {
628607
Success(_) => all_ns_failed = false,
629608
_ => {}
630609
}
@@ -729,8 +708,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
729708
resolution.borrow().binding().map(|binding| (*name, binding))
730709
}).collect::<Vec<_>>();
731710
for ((name, ns), binding) in bindings {
732-
if binding.pseudo_vis() == ty::Visibility::Public ||
733-
self.new_import_semantics && self.is_accessible(binding.vis) {
711+
if binding.pseudo_vis() == ty::Visibility::Public || self.is_accessible(binding.vis) {
734712
let imported_binding = self.import(binding, directive);
735713
let _ = self.try_define(directive.parent, name, ns, imported_binding);
736714
}
@@ -761,20 +739,6 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
761739
None => continue,
762740
};
763741

764-
// Report conflicts
765-
if !self.new_import_semantics {
766-
for duplicate_glob in resolution.duplicate_globs.iter() {
767-
// FIXME #31337: We currently allow items to shadow glob-imported re-exports.
768-
if !binding.is_import() {
769-
if let NameBindingKind::Import { binding, .. } = duplicate_glob.kind {
770-
if binding.is_import() { continue }
771-
}
772-
}
773-
774-
self.report_conflict(module, name, ns, duplicate_glob, binding);
775-
}
776-
}
777-
778742
if binding.vis == ty::Visibility::Public &&
779743
(binding.is_import() || binding.is_extern_crate()) {
780744
let def = binding.def();

0 commit comments

Comments
 (0)