Skip to content

Commit cd9103f

Browse files
powerboat9CohenArthur
authored andcommitted
Limit globbing visitor
The globbing visitor would previously descend into some kinds of rust item, instead of registering them as glob imports or ignoring them. This would cause items nested in those items to be glob imported, despite them not being top level items inside the glob container. gcc/rust/ChangeLog: * resolve/rust-finalize-imports-2.0.cc (GlobbingVisitor::visit): Add overrides for more items. * resolve/rust-finalize-imports-2.0.h (GlobbingVisitor::visit): Likewise. gcc/testsuite/ChangeLog: * rust/compile/name_resolution27.rs: New test. Reported-by: Arthur Cohen <arthur.cohen@embecosm.com> Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
1 parent b203e0f commit cd9103f

3 files changed

Lines changed: 46 additions & 0 deletions

File tree

gcc/rust/resolve/rust-finalize-imports-2.0.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,28 @@ GlobbingVisitor::visit (AST::ConstantItem &const_item)
142142
Namespace::Values);
143143
}
144144

145+
void
146+
GlobbingVisitor::visit (AST::TypeAlias &type)
147+
{
148+
ctx.insert_globbed (type.get_new_type_name (), type.get_node_id (),
149+
Namespace::Types);
150+
}
151+
152+
void
153+
GlobbingVisitor::visit (AST::Trait &trait)
154+
{
155+
ctx.insert_globbed (trait.get_identifier (), trait.get_node_id (),
156+
Namespace::Types);
157+
}
158+
159+
void
160+
GlobbingVisitor::visit (AST::InherentImpl &impl)
161+
{}
162+
163+
void
164+
GlobbingVisitor::visit (AST::TraitImpl &impl)
165+
{}
166+
145167
void
146168
GlobbingVisitor::visit (AST::ExternCrate &crate)
147169
{}

gcc/rust/resolve/rust-finalize-imports-2.0.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ class GlobbingVisitor : public AST::DefaultASTVisitor
4848
void visit (AST::Enum &enum_item) override;
4949
void visit (AST::Union &union_item) override;
5050
void visit (AST::ConstantItem &const_item) override;
51+
void visit (AST::TypeAlias &type) override;
52+
void visit (AST::Trait &trait) override;
53+
void visit (AST::InherentImpl &impl) override;
54+
void visit (AST::TraitImpl &impl) override;
5155
void visit (AST::ExternCrate &crate) override;
5256
void visit (AST::UseDeclaration &use) override;
5357

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![feature(no_core)]
2+
#![no_core]
3+
4+
mod a {
5+
trait A {
6+
fn foo();
7+
}
8+
9+
struct B;
10+
11+
impl A for B {
12+
fn foo() {}
13+
}
14+
}
15+
16+
use a::*;
17+
18+
pub fn bar() {
19+
foo() // { dg-error "Cannot find path" }
20+
}

0 commit comments

Comments
 (0)