Skip to content

Commit a44a03f

Browse files
authored
Merge pull request #34 from mrkkrp/fix-as-import
Fix handling of alias imports in use groups
2 parents c765b73 + 131c8b0 commit a44a03f

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

gazelle_rust_parser/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,14 @@ fn is_test_attribute(path: &syn::Path) -> bool {
551551
impl<'ast> Visit<'ast> for AstVisitor<'ast> {
552552
fn visit_use_tree(&mut self, node: &'ast syn::UseTree) {
553553
let prev_inside_use_tree = self.inside_use_tree;
554-
self.inside_use_tree = true;
554+
555+
// Only set inside_use_tree for Path nodes, as these represent nested paths
556+
// like `a::b::c`. For other variants (Name, Rename, Group, Glob), we don't
557+
// want to set this flag as it would prevent detecting top-level renames
558+
// in use groups like `pub use { foo as bar }`.
559+
if matches!(node, syn::UseTree::Path(_)) {
560+
self.inside_use_tree = true;
561+
}
555562

556563
if !prev_inside_use_tree {
557564
if let syn::UseTree::Rename(rename) = node {

gazelle_rust_parser/test_data/simple.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ use test_use_4 as outer_alias_1;
88
use test_use_5::self_use::{self, x};
99
use test_use_6::some_mod::foo as outer_alias_2;
1010

11+
pub use {
12+
test_use_7 as outer_alias_3,
13+
};
14+
1115
#[gazelle::ignore]
1216
use ignored_dep::ignored_mod;
1317
use ignored_mod::foobar;

gazelle_rust_parser/tests/parse_test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ lazy_static::lazy_static! {
2525
"test_use_4",
2626
"test_use_5",
2727
"test_use_6",
28+
"test_use_7",
2829
"test_duplicate",
2930
"test_inner_1",
3031
"test_args_1",

0 commit comments

Comments
 (0)