Skip to content

Commit b4895da

Browse files
powerboat9CohenArthur
authored andcommitted
nr2.0: Fix StructExprFieldIdentifier handling
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add visitor for StructExprFieldIdentifier. * resolve/rust-late-name-resolver-2.0.h (Late::visit): Likewise. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <[email protected]>
1 parent 30ff37a commit b4895da

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

gcc/rust/resolve/rust-late-name-resolver-2.0.cc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,34 @@ Late::visit (AST::IdentifierExpr &expr)
259259
// toplevel instead insert a name in ctx.values? (like it currently does)
260260
}
261261

262+
void
263+
Late::visit (AST::StructExprFieldIdentifier &expr)
264+
{
265+
tl::optional<Rib::Definition> resolved = tl::nullopt;
266+
267+
if (auto value = ctx.values.get (expr.get_field_name ()))
268+
{
269+
resolved = value;
270+
}
271+
// seems like we don't need a type namespace lookup
272+
else
273+
{
274+
rust_error_at (expr.get_locus (), "could not resolve struct field: %qs",
275+
expr.get_field_name ().as_string ().c_str ());
276+
return;
277+
}
278+
279+
if (resolved->is_ambiguous ())
280+
{
281+
rust_error_at (expr.get_locus (), ErrorCode::E0659, "%qs is ambiguous",
282+
expr.as_string ().c_str ());
283+
return;
284+
}
285+
286+
ctx.map_usage (Usage (expr.get_node_id ()),
287+
Definition (resolved->get_node_id ()));
288+
}
289+
262290
void
263291
Late::visit (AST::PathInExpression &expr)
264292
{

gcc/rust/resolve/rust-late-name-resolver-2.0.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class Late : public DefaultResolver
4646

4747
// resolutions
4848
void visit (AST::IdentifierExpr &) override;
49+
void visit (AST::StructExprFieldIdentifier &) override;
4950
void visit (AST::BreakExpr &) override;
5051
void visit (AST::PathInExpression &) override;
5152
void visit (AST::TypePath &) override;

gcc/testsuite/rust/compile/nr2/exclude

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ pub_restricted_1.rs
2323
pub_restricted_2.rs
2424
pub_restricted_3.rs
2525
sizeof-stray-infer-var-bug.rs
26-
struct-expr-parse.rs
2726
undeclared_label.rs
2827
use_1.rs
2928
while_break_expr.rs
@@ -40,15 +39,8 @@ derive-eq-invalid.rs
4039
derive-hash1.rs
4140
torture/alt_patterns1.rs
4241
torture/builtin_abort.rs
43-
torture/impl_block3.rs
44-
torture/issue-1434.rs
4542
torture/loop4.rs
4643
torture/loop8.rs
47-
torture/methods1.rs
48-
torture/methods2.rs
49-
torture/methods3.rs
5044
torture/name_resolve1.rs
51-
torture/nested_struct1.rs
52-
torture/struct_init_3.rs
5345
torture/uninit-intrinsic-1.rs
5446
# please don't delete the trailing newline

0 commit comments

Comments
 (0)