Skip to content

Commit 9554470

Browse files
sriganeshresphilberty
authored andcommitted
gccrs: refactoring rust_error_at "redefined multiple times"
gcc/rust/ChangeLog: * resolve/rust-ast-resolve-base.h (redefined_error): created a function for rust_error_at for redefined at multiple times. * resolve/rust-ast-resolve-implitem.h: changed rust_error_at to redefined_error. * resolve/rust-ast-resolve-stmt.cc (ResolveStmt::visit): changed rust_error_at to redefined_error. * resolve/rust-ast-resolve-stmt.h: changed rust_error_at to redefined_error. * resolve/rust-ast-resolve-toplevel.h: changed rust_error_at to redefined_error. Signed-off-by: Sri Ganesh Thota <[email protected]>
1 parent b9aaa61 commit 9554470

5 files changed

+41
-37
lines changed

gcc/rust/resolve/rust-ast-resolve-base.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727

2828
namespace Rust {
2929
namespace Resolver {
30+
inline void
31+
redefined_error (const rich_location &loc)
32+
{
33+
rust_error_at (loc, "redefined multiple times");
34+
}
3035

3136
class ResolverBase : public AST::ASTVisitor
3237
{

gcc/rust/resolve/rust-ast-resolve-implitem.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class ResolveToplevelImplItem : public ResolverBase
5151
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
5252
rich_location r (line_table, type.get_locus ());
5353
r.add_range (locus);
54-
rust_error_at (r, "defined multiple times");
54+
redefined_error (r);
5555
});
5656
}
5757

@@ -67,7 +67,7 @@ class ResolveToplevelImplItem : public ResolverBase
6767
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
6868
rich_location r (line_table, constant.get_locus ());
6969
r.add_range (locus);
70-
rust_error_at (r, "defined multiple times");
70+
redefined_error (r);
7171
});
7272
}
7373

@@ -84,7 +84,7 @@ class ResolveToplevelImplItem : public ResolverBase
8484
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
8585
rich_location r (line_table, function.get_locus ());
8686
r.add_range (locus);
87-
rust_error_at (r, "defined multiple times");
87+
redefined_error (r);
8888
});
8989
}
9090

@@ -124,7 +124,7 @@ class ResolveTopLevelTraitItems : public ResolverBase
124124
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
125125
rich_location r (line_table, function.get_locus ());
126126
r.add_range (locus);
127-
rust_error_at (r, "defined multiple times");
127+
redefined_error (r);
128128
});
129129

130130
mappings.insert_canonical_path (function.get_node_id (), cpath);
@@ -144,7 +144,7 @@ class ResolveTopLevelTraitItems : public ResolverBase
144144
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
145145
rich_location r (line_table, constant.get_locus ());
146146
r.add_range (locus);
147-
rust_error_at (r, "defined multiple times");
147+
redefined_error (r);
148148
});
149149

150150
mappings.insert_canonical_path (constant.get_node_id (), cpath);
@@ -162,7 +162,7 @@ class ResolveTopLevelTraitItems : public ResolverBase
162162
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
163163
rich_location r (line_table, type.get_locus ());
164164
r.add_range (locus);
165-
rust_error_at (r, "defined multiple times");
165+
redefined_error (r);
166166
});
167167

168168
mappings.insert_canonical_path (type.get_node_id (), cpath);
@@ -202,7 +202,7 @@ class ResolveToplevelExternItem : public ResolverBase
202202
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
203203
rich_location r (line_table, function.get_locus ());
204204
r.add_range (locus);
205-
rust_error_at (r, "defined multiple times");
205+
redefined_error (r);
206206
});
207207

208208
NodeId current_module = resolver->peek_current_module_scope ();
@@ -221,7 +221,7 @@ class ResolveToplevelExternItem : public ResolverBase
221221
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
222222
rich_location r (line_table, item.get_locus ());
223223
r.add_range (locus);
224-
rust_error_at (r, "defined multiple times");
224+
redefined_error (r);
225225
});
226226

227227
NodeId current_module = resolver->peek_current_module_scope ();
@@ -239,8 +239,7 @@ class ResolveToplevelExternItem : public ResolverBase
239239
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
240240
rich_location r (line_table, type.get_locus ());
241241
r.add_range (locus);
242-
243-
rust_error_at (r, "defined multiple times");
242+
redefined_error (r);
244243
});
245244

246245
NodeId current_module = resolver->peek_current_module_scope ();

gcc/rust/resolve/rust-ast-resolve-stmt.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ ResolveStmt::visit (AST::StaticItem &var)
7070
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
7171
rich_location r (line_table, var.get_locus ());
7272
r.add_range (locus);
73-
rust_error_at (r, "defined multiple times");
73+
redefined_error (r);
7474
});
7575

7676
ResolveType::go (var.get_type ());

gcc/rust/resolve/rust-ast-resolve-stmt.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class ResolveStmt : public ResolverBase
6363
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
6464
rich_location r (line_table, constant.get_locus ());
6565
r.add_range (locus);
66-
rust_error_at (r, "defined multiple times");
66+
redefined_error (r);
6767
});
6868

6969
ResolveType::go (constant.get_type ());
@@ -98,7 +98,7 @@ class ResolveStmt : public ResolverBase
9898
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
9999
rich_location r (line_table, struct_decl.get_locus ());
100100
r.add_range (locus);
101-
rust_error_at (r, "defined multiple times");
101+
redefined_error (r);
102102
});
103103

104104
NodeId scope_node_id = struct_decl.get_node_id ();
@@ -129,7 +129,7 @@ class ResolveStmt : public ResolverBase
129129
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
130130
rich_location r (line_table, enum_decl.get_locus ());
131131
r.add_range (locus);
132-
rust_error_at (r, "defined multiple times");
132+
redefined_error (r);
133133
});
134134

135135
NodeId scope_node_id = enum_decl.get_node_id ();
@@ -159,7 +159,7 @@ class ResolveStmt : public ResolverBase
159159
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
160160
rich_location r (line_table, item.get_locus ());
161161
r.add_range (locus);
162-
rust_error_at (r, "defined multiple times");
162+
redefined_error (r);
163163
});
164164

165165
// Done, no fields.
@@ -179,7 +179,7 @@ class ResolveStmt : public ResolverBase
179179
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
180180
rich_location r (line_table, item.get_locus ());
181181
r.add_range (locus);
182-
rust_error_at (r, "defined multiple times");
182+
redefined_error (r);
183183
});
184184

185185
for (auto &field : item.get_tuple_fields ())
@@ -205,7 +205,7 @@ class ResolveStmt : public ResolverBase
205205
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
206206
rich_location r (line_table, item.get_locus ());
207207
r.add_range (locus);
208-
rust_error_at (r, "defined multiple times");
208+
redefined_error (r);
209209
});
210210

211211
for (auto &field : item.get_struct_fields ())
@@ -231,7 +231,7 @@ class ResolveStmt : public ResolverBase
231231
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
232232
rich_location r (line_table, item.get_locus ());
233233
r.add_range (locus);
234-
rust_error_at (r, "defined multiple times");
234+
redefined_error (r);
235235
});
236236

237237
// Done, no fields.
@@ -252,7 +252,7 @@ class ResolveStmt : public ResolverBase
252252
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
253253
rich_location r (line_table, struct_decl.get_locus ());
254254
r.add_range (locus);
255-
rust_error_at (r, "defined multiple times");
255+
redefined_error (r);
256256
});
257257

258258
NodeId scope_node_id = struct_decl.get_node_id ();
@@ -288,7 +288,7 @@ class ResolveStmt : public ResolverBase
288288
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
289289
rich_location r (line_table, union_decl.get_locus ());
290290
r.add_range (locus);
291-
rust_error_at (r, "defined multiple times");
291+
redefined_error (r);
292292
});
293293

294294
NodeId scope_node_id = union_decl.get_node_id ();
@@ -324,7 +324,7 @@ class ResolveStmt : public ResolverBase
324324
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
325325
rich_location r (line_table, function.get_locus ());
326326
r.add_range (locus);
327-
rust_error_at (r, "defined multiple times");
327+
redefined_error (r);
328328
});
329329

330330
NodeId scope_node_id = function.get_node_id ();

gcc/rust/resolve/rust-ast-resolve-toplevel.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class ResolveTopLevel : public ResolverBase
5858
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
5959
rich_location r (line_table, module.get_locus ());
6060
r.add_range (locus);
61-
rust_error_at (r, "defined multiple times");
61+
redefined_error (r);
6262
});
6363

6464
NodeId current_module = resolver->peek_current_module_scope ();
@@ -88,7 +88,7 @@ class ResolveTopLevel : public ResolverBase
8888
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
8989
rich_location r (line_table, alias.get_locus ());
9090
r.add_range (locus);
91-
rust_error_at (r, "defined multiple times");
91+
redefined_error (r);
9292
});
9393

9494
NodeId current_module = resolver->peek_current_module_scope ();
@@ -110,7 +110,7 @@ class ResolveTopLevel : public ResolverBase
110110
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
111111
rich_location r (line_table, struct_decl.get_locus ());
112112
r.add_range (locus);
113-
rust_error_at (r, "defined multiple times");
113+
redefined_error (r);
114114
});
115115

116116
NodeId current_module = resolver->peek_current_module_scope ();
@@ -132,7 +132,7 @@ class ResolveTopLevel : public ResolverBase
132132
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
133133
rich_location r (line_table, enum_decl.get_locus ());
134134
r.add_range (locus);
135-
rust_error_at (r, "defined multiple times");
135+
redefined_error (r);
136136
});
137137

138138
resolver->push_new_module_scope (enum_decl.get_node_id ());
@@ -158,7 +158,7 @@ class ResolveTopLevel : public ResolverBase
158158
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
159159
rich_location r (line_table, item.get_locus ());
160160
r.add_range (locus);
161-
rust_error_at (r, "defined multiple times");
161+
redefined_error (r);
162162
});
163163

164164
mappings.insert_canonical_path (item.get_node_id (), cpath);
@@ -180,7 +180,7 @@ class ResolveTopLevel : public ResolverBase
180180
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
181181
rich_location r (line_table, item.get_locus ());
182182
r.add_range (locus);
183-
rust_error_at (r, "defined multiple times");
183+
redefined_error (r);
184184
});
185185

186186
mappings.insert_canonical_path (item.get_node_id (), cpath);
@@ -202,7 +202,7 @@ class ResolveTopLevel : public ResolverBase
202202
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
203203
rich_location r (line_table, item.get_locus ());
204204
r.add_range (locus);
205-
rust_error_at (r, "defined multiple times");
205+
redefined_error (r);
206206
});
207207

208208
mappings.insert_canonical_path (item.get_node_id (), cpath);
@@ -224,7 +224,7 @@ class ResolveTopLevel : public ResolverBase
224224
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
225225
rich_location r (line_table, item.get_locus ());
226226
r.add_range (locus);
227-
rust_error_at (r, "defined multiple times");
227+
redefined_error (r);
228228
});
229229

230230
mappings.insert_canonical_path (item.get_node_id (), cpath);
@@ -246,7 +246,7 @@ class ResolveTopLevel : public ResolverBase
246246
= [&] (const CanonicalPath &, NodeId, location_t locus) -> void {
247247
rich_location r (line_table, struct_decl.get_locus ());
248248
r.add_range (locus);
249-
rust_error_at (r, "defined multiple times");
249+
redefined_error (r);
250250
};
251251

252252
resolver->get_type_scope ().insert (path, struct_decl.get_node_id (),
@@ -277,7 +277,7 @@ class ResolveTopLevel : public ResolverBase
277277
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
278278
rich_location r (line_table, union_decl.get_locus ());
279279
r.add_range (locus);
280-
rust_error_at (r, "defined multiple times");
280+
redefined_error (r);
281281
});
282282

283283
NodeId current_module = resolver->peek_current_module_scope ();
@@ -297,7 +297,7 @@ class ResolveTopLevel : public ResolverBase
297297
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
298298
rich_location r (line_table, var.get_locus ());
299299
r.add_range (locus);
300-
rust_error_at (r, "defined multiple times");
300+
redefined_error (r);
301301
});
302302

303303
NodeId current_module = resolver->peek_current_module_scope ();
@@ -318,7 +318,7 @@ class ResolveTopLevel : public ResolverBase
318318
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
319319
rich_location r (line_table, constant.get_locus ());
320320
r.add_range (locus);
321-
rust_error_at (r, "defined multiple times");
321+
redefined_error (r);
322322
});
323323

324324
NodeId current_module = resolver->peek_current_module_scope ();
@@ -340,7 +340,7 @@ class ResolveTopLevel : public ResolverBase
340340
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
341341
rich_location r (line_table, function.get_locus ());
342342
r.add_range (locus);
343-
rust_error_at (r, "defined multiple times");
343+
redefined_error (r);
344344
});
345345

346346
NodeId current_module = resolver->peek_current_module_scope ();
@@ -388,7 +388,7 @@ class ResolveTopLevel : public ResolverBase
388388
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
389389
rich_location r (line_table, impl_block.get_locus ());
390390
r.add_range (locus);
391-
rust_error_at (r, "defined multiple times");
391+
redefined_error (r);
392392
});
393393

394394
for (auto &impl_item : impl_block.get_impl_items ())
@@ -408,7 +408,7 @@ class ResolveTopLevel : public ResolverBase
408408
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
409409
rich_location r (line_table, trait.get_locus ());
410410
r.add_range (locus);
411-
rust_error_at (r, "defined multiple times");
411+
redefined_error (r);
412412
});
413413

414414
for (auto &item : trait.get_trait_items ())
@@ -480,7 +480,7 @@ class ResolveTopLevel : public ResolverBase
480480
[&] (const CanonicalPath &, NodeId, location_t locus) -> void {
481481
rich_location r (line_table, extern_crate.get_locus ());
482482
r.add_range (locus);
483-
rust_error_at (r, "defined multiple times");
483+
redefined_error (r);
484484
});
485485
}
486486

0 commit comments

Comments
 (0)