Skip to content

Commit c3f53d1

Browse files
committed
Resolve prefix in imports with empty braces
1 parent 357982f commit c3f53d1

File tree

6 files changed

+74
-10
lines changed

6 files changed

+74
-10
lines changed

src/librustc_front/visit.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
218218
visitor.visit_path_list_item(prefix, item)
219219
}
220220
} else {
221-
// FIXME(#28388) visit_path should be used instead of walk_path
222-
walk_path(visitor, prefix);
221+
visitor.visit_path(prefix, item.id);
223222
}
224223
}
225224
}

src/librustc_resolve/lib.rs

+22-6
Original file line numberDiff line numberDiff line change
@@ -2210,23 +2210,39 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
22102210

22112211
ItemUse(ref view_path) => {
22122212
// check for imports shadowing primitive types
2213-
let check_rename = |id, ident: Ident| {
2214-
match self.def_map.borrow().get(&id).map(|d| d.full_def()) {
2213+
let check_rename = |this: &Self, id, ident: Ident| {
2214+
match this.def_map.borrow().get(&id).map(|d| d.full_def()) {
22152215
Some(DefTy(..)) | Some(DefStruct(..)) | Some(DefTrait(..)) | None => {
2216-
self.check_if_primitive_type_name(ident.name, item.span);
2216+
this.check_if_primitive_type_name(ident.name, item.span);
22172217
}
22182218
_ => {}
22192219
}
22202220
};
22212221

22222222
match view_path.node {
22232223
hir::ViewPathSimple(ident, _) => {
2224-
check_rename(item.id, ident);
2224+
check_rename(self, item.id, ident);
22252225
}
2226-
hir::ViewPathList(_, ref items) => {
2226+
hir::ViewPathList(ref prefix, ref items) => {
22272227
for item in items {
22282228
if let Some(ident) = item.node.rename() {
2229-
check_rename(item.node.id(), ident);
2229+
check_rename(self, item.node.id(), ident);
2230+
}
2231+
}
2232+
2233+
// Resolve prefix of an import with empty braces (issue #28388)
2234+
if items.is_empty() && !prefix.segments.is_empty() {
2235+
match self.resolve_crate_relative_path(prefix.span,
2236+
&prefix.segments,
2237+
TypeNS) {
2238+
Some((def, lp)) => self.record_def(item.id,
2239+
PathResolution::new(def, lp, 0)),
2240+
None => {
2241+
resolve_error(self,
2242+
prefix.span,
2243+
ResolutionError::FailedToResolve(
2244+
&path_names_to_string(prefix, 0)));
2245+
}
22302246
}
22312247
}
22322248
}

src/libsyntax/visit.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
224224
visitor.visit_path_list_item(prefix, item)
225225
}
226226
} else {
227-
// FIXME(#28388) visit_path should be used instead of walk_path
228-
walk_path(visitor, prefix);
227+
visitor.visit_path(prefix, item.id);
229228
}
230229
}
231230
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Prefix in imports with empty braces should be resolved and checked privacy, stability, etc.
12+
13+
use foo::{}; //~ ERROR failed to resolve. foo
14+
15+
fn main() {}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Prefix in imports with empty braces should be resolved and checked privacy, stability, etc.
12+
13+
mod m {
14+
mod n {}
15+
}
16+
17+
use m::n::{}; //~ ERROR module `n` is private
18+
19+
fn main() {}
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Prefix in imports with empty braces should be resolved and checked privacy, stability, etc.
12+
13+
use std::rt::{}; //~ ERROR use of unstable library feature 'rt'
14+
use std::{}; // OK
15+
16+
fn main() {}

0 commit comments

Comments
 (0)