@@ -31,25 +31,19 @@ class ResolveToplevelImplItem : public ResolverBase
31
31
using Rust::Resolver::ResolverBase::visit;
32
32
33
33
public:
34
- static void go (AST::InherentImplItem *item, AST::Type *base )
34
+ static void go (AST::InherentImplItem *item, const CanonicalPath &prefix )
35
35
{
36
- ResolveToplevelImplItem resolver (base);
37
- if (resolver.base_path .is_empty ())
38
- {
39
- rust_error_at (base->get_locus_slow (),
40
- " failed to resolve simple path" );
41
- return ;
42
- }
36
+ ResolveToplevelImplItem resolver (prefix);
43
37
item->accept_vis (resolver);
44
38
}
45
39
46
40
void visit (AST::ConstantItem &constant) override
47
41
{
48
- std::string identifier
49
- = base_path. as_string () + " :: " + constant. get_identifier ( );
42
+ auto path
43
+ = prefix. append ( ResolveConstantItemToCanonicalPath::resolve (constant) );
50
44
resolver->get_name_scope ().insert (
51
- identifier , constant.get_node_id (), constant.get_locus (), false ,
52
- [&] (std::string , NodeId, Location locus) -> void {
45
+ path , constant.get_node_id (), constant.get_locus (), false ,
46
+ [&] (const CanonicalPath & , NodeId, Location locus) -> void {
53
47
rust_error_at (constant.get_locus (), " redefined multiple times" );
54
48
rust_error_at (locus, " was defined here" );
55
49
});
@@ -60,11 +54,11 @@ class ResolveToplevelImplItem : public ResolverBase
60
54
61
55
void visit (AST::Function &function) override
62
56
{
63
- std::string identifier
64
- = base_path. as_string () + " :: " + function. get_function_name ( );
57
+ auto path
58
+ = prefix. append ( ResolveFunctionItemToCanonicalPath::resolve (function) );
65
59
resolver->get_name_scope ().insert (
66
- identifier , function.get_node_id (), function.get_locus (), false ,
67
- [&] (std::string , NodeId, Location locus) -> void {
60
+ path , function.get_node_id (), function.get_locus (), false ,
61
+ [&] (const CanonicalPath & , NodeId, Location locus) -> void {
68
62
rust_error_at (function.get_locus (), " redefined multiple times" );
69
63
rust_error_at (locus, " was defined here" );
70
64
});
@@ -75,11 +69,11 @@ class ResolveToplevelImplItem : public ResolverBase
75
69
76
70
void visit (AST::Method &method) override
77
71
{
78
- std::string identifier
79
- = base_path. as_string () + " :: " + method. get_method_name ( );
72
+ auto path
73
+ = prefix. append ( ResolveMethodItemToCanonicalPath::resolve (method) );
80
74
resolver->get_name_scope ().insert (
81
- identifier , method.get_node_id (), method.get_locus (), false ,
82
- [&] (std::string , NodeId, Location locus) -> void {
75
+ path , method.get_node_id (), method.get_locus (), false ,
76
+ [&] (const CanonicalPath & , NodeId, Location locus) -> void {
83
77
rust_error_at (method.get_locus (), " redefined multiple times" );
84
78
rust_error_at (locus, " was defined here" );
85
79
});
@@ -89,15 +83,13 @@ class ResolveToplevelImplItem : public ResolverBase
89
83
}
90
84
91
85
private:
92
- ResolveToplevelImplItem (AST::Type *base)
93
- : ResolverBase (UNKNOWN_NODEID), base (base),
94
- base_path (AST::SimplePath::create_empty ())
86
+ ResolveToplevelImplItem (const CanonicalPath &prefix)
87
+ : ResolverBase (UNKNOWN_NODEID), prefix (prefix)
95
88
{
96
- ResolveTypeToSimplePath::go (base, base_path, true );
89
+ rust_assert (!prefix. is_error () );
97
90
}
98
91
99
- AST::Type *base;
100
- AST::SimplePath base_path;
92
+ const CanonicalPath &prefix;
101
93
};
102
94
103
95
} // namespace Resolver
0 commit comments