Skip to content

Commit c74ac6c

Browse files
committed
Auto merge of #38566 - jseyfried:fix_import_resolution_bug, r=eddyb
Fix bug in import resolution Fixes #38535 and fixes #38556. r? @nrc
2 parents e60aa62 + 31d9cc3 commit c74ac6c

File tree

3 files changed

+37
-17
lines changed

3 files changed

+37
-17
lines changed

src/librustc_resolve/resolve_imports.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ impl<'a> NameResolution<'a> {
129129
impl<'a> Resolver<'a> {
130130
fn resolution(&self, module: Module<'a>, ident: Ident, ns: Namespace)
131131
-> &'a RefCell<NameResolution<'a>> {
132+
let ident = ident.unhygienize();
132133
*module.resolutions.borrow_mut().entry((ident, ns))
133134
.or_insert_with(|| self.arenas.alloc_name_resolution())
134135
}
@@ -142,7 +143,6 @@ impl<'a> Resolver<'a> {
142143
ignore_unresolved_invocations: bool,
143144
record_used: Option<Span>)
144145
-> Result<&'a NameBinding<'a>, Determinacy> {
145-
let ident = ident.unhygienize();
146146
self.populate_module_if_necessary(module);
147147

148148
let resolution = self.resolution(module, ident, ns)
@@ -308,7 +308,6 @@ impl<'a> Resolver<'a> {
308308
ns: Namespace,
309309
binding: &'a NameBinding<'a>)
310310
-> Result<(), &'a NameBinding<'a>> {
311-
let ident = ident.unhygienize();
312311
self.update_resolution(module, ident, ns, |this, resolution| {
313312
if let Some(old_binding) = resolution.binding {
314313
if binding.is_glob_import() {

src/libsyntax/fold.rs

+14-15
Original file line numberDiff line numberDiff line change
@@ -302,23 +302,22 @@ pub fn noop_fold_view_path<T: Folder>(view_path: P<ViewPath>, fld: &mut T) -> P<
302302
view_path.map(|Spanned {node, span}| Spanned {
303303
node: match node {
304304
ViewPathSimple(ident, path) => {
305-
ViewPathSimple(ident, fld.fold_path(path))
305+
ViewPathSimple(fld.fold_ident(ident), fld.fold_path(path))
306306
}
307307
ViewPathGlob(path) => {
308308
ViewPathGlob(fld.fold_path(path))
309309
}
310310
ViewPathList(path, path_list_idents) => {
311-
ViewPathList(fld.fold_path(path),
312-
path_list_idents.move_map(|path_list_ident| {
313-
Spanned {
314-
node: PathListItem_ {
315-
id: fld.new_id(path_list_ident.node.id),
316-
rename: path_list_ident.node.rename,
317-
name: path_list_ident.node.name,
318-
},
319-
span: fld.new_span(path_list_ident.span)
320-
}
321-
}))
311+
let path = fld.fold_path(path);
312+
let path_list_idents = path_list_idents.move_map(|path_list_ident| Spanned {
313+
node: PathListItem_ {
314+
id: fld.new_id(path_list_ident.node.id),
315+
rename: path_list_ident.node.rename.map(|ident| fld.fold_ident(ident)),
316+
name: fld.fold_ident(path_list_ident.node.name),
317+
},
318+
span: fld.new_span(path_list_ident.span)
319+
});
320+
ViewPathList(path, path_list_idents)
322321
}
323322
},
324323
span: fld.new_span(span)
@@ -345,7 +344,7 @@ pub fn noop_fold_arm<T: Folder>(Arm {attrs, pats, guard, body}: Arm, fld: &mut T
345344
pub fn noop_fold_ty_binding<T: Folder>(b: TypeBinding, fld: &mut T) -> TypeBinding {
346345
TypeBinding {
347346
id: fld.new_id(b.id),
348-
ident: b.ident,
347+
ident: fld.fold_ident(b.ident),
349348
ty: fld.fold_ty(b.ty),
350349
span: fld.new_span(b.span),
351350
}
@@ -672,7 +671,7 @@ pub fn noop_fold_ty_param<T: Folder>(tp: TyParam, fld: &mut T) -> TyParam {
672671
.collect::<Vec<_>>()
673672
.into(),
674673
id: fld.new_id(id),
675-
ident: ident,
674+
ident: fld.fold_ident(ident),
676675
bounds: fld.fold_bounds(bounds),
677676
default: default.map(|x| fld.fold_ty(x)),
678677
span: span
@@ -1087,7 +1086,7 @@ pub fn noop_fold_pat<T: Folder>(p: P<Pat>, folder: &mut T) -> P<Pat> {
10871086
let fs = fields.move_map(|f| {
10881087
Spanned { span: folder.new_span(f.span),
10891088
node: ast::FieldPat {
1090-
ident: f.node.ident,
1089+
ident: folder.fold_ident(f.node.ident),
10911090
pat: folder.fold_pat(f.node.pat),
10921091
is_shorthand: f.node.is_shorthand,
10931092
}}

src/test/run-pass/issue-38556.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2016 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+
pub struct Foo;
12+
13+
macro_rules! reexport {
14+
() => { use Foo as Bar; }
15+
}
16+
17+
reexport!();
18+
19+
fn main() {
20+
use Bar;
21+
fn f(_: Bar) {}
22+
}

0 commit comments

Comments
 (0)