Skip to content

Commit 319f0de

Browse files
committed
resolve: Address FIXME from the previous commit
Make the `is_import` flag in `ScopeSet` independent from namespace Fix rebase
1 parent 8cc8133 commit 319f0de

File tree

4 files changed

+17
-19
lines changed

4 files changed

+17
-19
lines changed

src/librustc_resolve/lib.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc::hir::{self, PrimTy, Bool, Char, Float, Int, Uint, Str};
1717
use rustc::middle::cstore::CrateStore;
1818
use rustc::session::Session;
1919
use rustc::lint;
20-
use rustc::hir::def::{self, DefKind, PartialRes, CtorOf, NonMacroAttrKind, ExportMap};
20+
use rustc::hir::def::{self, DefKind, PartialRes, CtorKind, CtorOf, NonMacroAttrKind, ExportMap};
2121
use rustc::hir::def::Namespace::*;
2222
use rustc::hir::def_id::{CRATE_DEF_INDEX, LOCAL_CRATE, DefId};
2323
use rustc::hir::{TraitMap, GlobMap};
@@ -37,7 +37,7 @@ use syntax::visit::{self, Visitor};
3737
use syntax::attr;
3838
use syntax::ast::{CRATE_NODE_ID, Crate};
3939
use syntax::ast::{ItemKind, Path};
40-
use syntax::{span_err, struct_span_err, unwrap_or};
40+
use syntax::{struct_span_err, unwrap_or};
4141

4242
use syntax_pos::{Span, DUMMY_SP};
4343
use errors::{Applicability, DiagnosticBuilder};
@@ -110,10 +110,12 @@ enum Scope<'a> {
110110
/// This enum is currently used only for early resolution (imports and macros),
111111
/// but not for late resolution yet.
112112
enum ScopeSet {
113-
Import(Namespace),
113+
/// All scopes with the given namespace.
114+
All(Namespace, /*is_import*/ bool),
115+
/// Crate root, then extern prelude (used for mixed 2015-2018 mode in macros).
114116
AbsolutePath(Namespace),
117+
/// All scopes with macro namespace and the given macro kind restriction.
115118
Macro(MacroKind),
116-
Module,
117119
}
118120

119121
/// Everything you need to know about a name's location to resolve it.
@@ -1330,10 +1332,9 @@ impl<'a> Resolver<'a> {
13301332

13311333
let rust_2015 = ident.span.rust_2015();
13321334
let (ns, is_absolute_path) = match scope_set {
1333-
ScopeSet::Import(ns) => (ns, false),
1335+
ScopeSet::All(ns, _) => (ns, false),
13341336
ScopeSet::AbsolutePath(ns) => (ns, true),
13351337
ScopeSet::Macro(_) => (MacroNS, false),
1336-
ScopeSet::Module => (TypeNS, false),
13371338
};
13381339
let mut scope = match ns {
13391340
_ if is_absolute_path => Scope::CrateRoot,
@@ -1858,9 +1859,7 @@ impl<'a> Resolver<'a> {
18581859
module, ident, ns, parent_scope, record_used, path_span
18591860
)
18601861
} else if ribs.is_none() || opt_ns.is_none() || opt_ns == Some(MacroNS) {
1861-
// FIXME: Decouple the import property from `ScopeSet`.
1862-
let is_import = opt_ns.is_none() || ns != TypeNS;
1863-
let scopes = if is_import { ScopeSet::Import(ns) } else { ScopeSet::Module };
1862+
let scopes = ScopeSet::All(ns, opt_ns.is_none());
18641863
self.early_resolve_ident_in_lexical_scope(ident, scopes, parent_scope, record_used,
18651864
record_used, path_span)
18661865
} else {

src/librustc_resolve/macros.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,7 @@ impl<'a> Resolver<'a> {
374374
self.prohibit_imported_non_macro_attrs(None, res.ok(), path_span);
375375
res
376376
} else {
377-
// Macro without a specific kind restriction is equvalent to a macro import.
378-
let scope_set = kind.map_or(ScopeSet::Import(MacroNS), ScopeSet::Macro);
377+
let scope_set = kind.map_or(ScopeSet::All(MacroNS, false), ScopeSet::Macro);
379378
let binding = self.early_resolve_ident_in_lexical_scope(
380379
path[0].ident, scope_set, parent_scope, false, force, path_span
381380
);
@@ -430,10 +429,9 @@ impl<'a> Resolver<'a> {
430429
}
431430

432431
let (ns, macro_kind, is_import) = match scope_set {
433-
ScopeSet::Import(ns) => (ns, None, true),
432+
ScopeSet::All(ns, is_import) => (ns, None, is_import),
434433
ScopeSet::AbsolutePath(ns) => (ns, None, false),
435434
ScopeSet::Macro(macro_kind) => (MacroNS, Some(macro_kind), false),
436-
ScopeSet::Module => (TypeNS, None, false),
437435
};
438436

439437
// This is *the* result, resolution from the scope closest to the resolved identifier.

src/librustc_resolve/resolve_imports.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,9 @@ impl<'a> Resolver<'a> {
232232
}
233233
}
234234

235+
let scopes = ScopeSet::All(ns, true);
235236
let binding = self.early_resolve_ident_in_lexical_scope(
236-
ident, ScopeSet::Import(ns), parent_scope, record_used, record_used, path_span
237+
ident, scopes, parent_scope, record_used, record_used, path_span
237238
);
238239
return binding.map_err(|determinacy| (determinacy, Weak::No));
239240
}
@@ -1217,7 +1218,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
12171218

12181219
match this.early_resolve_ident_in_lexical_scope(
12191220
target,
1220-
ScopeSet::Import(ns),
1221+
ScopeSet::All(ns, false),
12211222
&directive.parent_scope,
12221223
false,
12231224
false,

src/test/ui/resolve/resolve-bad-visibility.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ error: visibilities can only be restricted to ancestor modules
1616
LL | pub(in std::vec) struct F;
1717
| ^^^^^^^^
1818

19-
error[E0433]: failed to resolve: maybe a missing `extern crate nonexistent;`?
19+
error[E0433]: failed to resolve: maybe a missing crate `nonexistent`?
2020
--> $DIR/resolve-bad-visibility.rs:7:8
2121
|
2222
LL | pub(in nonexistent) struct G;
23-
| ^^^^^^^^^^^ maybe a missing `extern crate nonexistent;`?
23+
| ^^^^^^^^^^^ maybe a missing crate `nonexistent`?
2424

25-
error[E0433]: failed to resolve: maybe a missing `extern crate too_soon;`?
25+
error[E0433]: failed to resolve: maybe a missing crate `too_soon`?
2626
--> $DIR/resolve-bad-visibility.rs:8:8
2727
|
2828
LL | pub(in too_soon) struct H;
29-
| ^^^^^^^^ maybe a missing `extern crate too_soon;`?
29+
| ^^^^^^^^ maybe a missing crate `too_soon`?
3030

3131
error: aborting due to 5 previous errors
3232

0 commit comments

Comments
 (0)