Skip to content

Commit

Permalink
Rollup merge of rust-lang#47705 - pietroalbini:fix-47673, r=petrochenkov
Browse files Browse the repository at this point in the history
Fix ICE when use trees have multiple empty nested groups

The issue was caused by an oversight of mine in the original use_nested_groups PR, where different paths were resolved with the same `NodeId` in some cases (such as in `use {{}, {}};`).

Fixes rust-lang#47673
r? @petrochenkov
  • Loading branch information
alexcrichton committed Jan 25, 2018
2 parents b335b10 + 5faba28 commit f7706d5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2045,7 +2045,7 @@ impl<'a> Resolver<'a> {
segments: vec![],
span: use_tree.span,
};
self.resolve_use_tree(item, use_tree, &path);
self.resolve_use_tree(item.id, use_tree, &path);
}

ItemKind::ExternCrate(_) | ItemKind::MacroDef(..) | ItemKind::GlobalAsm(_) => {
Expand All @@ -2056,7 +2056,7 @@ impl<'a> Resolver<'a> {
}
}

fn resolve_use_tree(&mut self, item: &Item, use_tree: &ast::UseTree, prefix: &Path) {
fn resolve_use_tree(&mut self, id: NodeId, use_tree: &ast::UseTree, prefix: &Path) {
match use_tree.kind {
ast::UseTreeKind::Nested(ref items) => {
let path = Path {
Expand All @@ -2070,10 +2070,10 @@ impl<'a> Resolver<'a> {

if items.len() == 0 {
// Resolve prefix of an import with empty braces (issue #28388).
self.smart_resolve_path(item.id, None, &path, PathSource::ImportPrefix);
self.smart_resolve_path(id, None, &path, PathSource::ImportPrefix);
} else {
for &(ref tree, _) in items {
self.resolve_use_tree(item, tree, &path);
for &(ref tree, nested_id) in items {
self.resolve_use_tree(nested_id, tree, &path);
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/test/run-pass/issue-47673.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2018 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.

#![feature(use_nested_groups)]
#![allow(unused_import)]

use {{}, {}};

fn main() {}

0 comments on commit f7706d5

Please sign in to comment.