Skip to content

Commit

Permalink
Auto merge of #38566 - jseyfried:fix_import_resolution_bug, r=eddyb
Browse files Browse the repository at this point in the history
Fix bug in import resolution

Fixes #38535 and fixes #38556.
r? @nrc
  • Loading branch information
bors committed Dec 25, 2016
2 parents e60aa62 + 31d9cc3 commit c74ac6c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 17 deletions.
3 changes: 1 addition & 2 deletions src/librustc_resolve/resolve_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ impl<'a> NameResolution<'a> {
impl<'a> Resolver<'a> {
fn resolution(&self, module: Module<'a>, ident: Ident, ns: Namespace)
-> &'a RefCell<NameResolution<'a>> {
let ident = ident.unhygienize();
*module.resolutions.borrow_mut().entry((ident, ns))
.or_insert_with(|| self.arenas.alloc_name_resolution())
}
Expand All @@ -142,7 +143,6 @@ impl<'a> Resolver<'a> {
ignore_unresolved_invocations: bool,
record_used: Option<Span>)
-> Result<&'a NameBinding<'a>, Determinacy> {
let ident = ident.unhygienize();
self.populate_module_if_necessary(module);

let resolution = self.resolution(module, ident, ns)
Expand Down Expand Up @@ -308,7 +308,6 @@ impl<'a> Resolver<'a> {
ns: Namespace,
binding: &'a NameBinding<'a>)
-> Result<(), &'a NameBinding<'a>> {
let ident = ident.unhygienize();
self.update_resolution(module, ident, ns, |this, resolution| {
if let Some(old_binding) = resolution.binding {
if binding.is_glob_import() {
Expand Down
29 changes: 14 additions & 15 deletions src/libsyntax/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,23 +302,22 @@ pub fn noop_fold_view_path<T: Folder>(view_path: P<ViewPath>, fld: &mut T) -> P<
view_path.map(|Spanned {node, span}| Spanned {
node: match node {
ViewPathSimple(ident, path) => {
ViewPathSimple(ident, fld.fold_path(path))
ViewPathSimple(fld.fold_ident(ident), fld.fold_path(path))
}
ViewPathGlob(path) => {
ViewPathGlob(fld.fold_path(path))
}
ViewPathList(path, path_list_idents) => {
ViewPathList(fld.fold_path(path),
path_list_idents.move_map(|path_list_ident| {
Spanned {
node: PathListItem_ {
id: fld.new_id(path_list_ident.node.id),
rename: path_list_ident.node.rename,
name: path_list_ident.node.name,
},
span: fld.new_span(path_list_ident.span)
}
}))
let path = fld.fold_path(path);
let path_list_idents = path_list_idents.move_map(|path_list_ident| Spanned {
node: PathListItem_ {
id: fld.new_id(path_list_ident.node.id),
rename: path_list_ident.node.rename.map(|ident| fld.fold_ident(ident)),
name: fld.fold_ident(path_list_ident.node.name),
},
span: fld.new_span(path_list_ident.span)
});
ViewPathList(path, path_list_idents)
}
},
span: fld.new_span(span)
Expand All @@ -345,7 +344,7 @@ pub fn noop_fold_arm<T: Folder>(Arm {attrs, pats, guard, body}: Arm, fld: &mut T
pub fn noop_fold_ty_binding<T: Folder>(b: TypeBinding, fld: &mut T) -> TypeBinding {
TypeBinding {
id: fld.new_id(b.id),
ident: b.ident,
ident: fld.fold_ident(b.ident),
ty: fld.fold_ty(b.ty),
span: fld.new_span(b.span),
}
Expand Down Expand Up @@ -672,7 +671,7 @@ pub fn noop_fold_ty_param<T: Folder>(tp: TyParam, fld: &mut T) -> TyParam {
.collect::<Vec<_>>()
.into(),
id: fld.new_id(id),
ident: ident,
ident: fld.fold_ident(ident),
bounds: fld.fold_bounds(bounds),
default: default.map(|x| fld.fold_ty(x)),
span: span
Expand Down Expand Up @@ -1087,7 +1086,7 @@ pub fn noop_fold_pat<T: Folder>(p: P<Pat>, folder: &mut T) -> P<Pat> {
let fs = fields.move_map(|f| {
Spanned { span: folder.new_span(f.span),
node: ast::FieldPat {
ident: f.node.ident,
ident: folder.fold_ident(f.node.ident),
pat: folder.fold_pat(f.node.pat),
is_shorthand: f.node.is_shorthand,
}}
Expand Down
22 changes: 22 additions & 0 deletions src/test/run-pass/issue-38556.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

pub struct Foo;

macro_rules! reexport {
() => { use Foo as Bar; }
}

reexport!();

fn main() {
use Bar;
fn f(_: Bar) {}
}

0 comments on commit c74ac6c

Please sign in to comment.