Skip to content

Commit

Permalink
Allow identifiers and paths to reference types during nr2.0
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* resolve/rust-late-name-resolver-2.0.cc
	(Late::visit): Allow IdentifierExpr and PathInExpression to
	reference types as well as values, remove ability for
	IdentifierExpr to reference labels.

gcc/testsuite/ChangeLog:

	* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <[email protected]>
  • Loading branch information
powerboat9 authored and P-E-P committed Oct 16, 2024
1 parent ab15db3 commit eb863f6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
35 changes: 24 additions & 11 deletions gcc/rust/resolve/rust-late-name-resolver-2.0.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,14 @@ Late::visit (AST::IdentifierExpr &expr)
// TODO: same thing as visit(PathInExpression) here?

tl::optional<Rib::Definition> resolved = tl::nullopt;
auto label = ctx.labels.get (expr.get_ident ());
auto value = ctx.values.get (expr.get_ident ());

if (label)
if (auto value = ctx.values.get (expr.get_ident ()))
{
resolved = label;
resolved = value;
}
else if (value)
else if (auto type = ctx.types.get (expr.get_ident ()))
{
resolved = value;
resolved = type;
}
else
{
Expand Down Expand Up @@ -202,18 +200,33 @@ Late::visit (AST::PathInExpression &expr)
// do we emit it in `get<Namespace::Labels>`?

rust_debug ("[ARTHUR]: %s", expr.as_simple_path ().as_string ().c_str ());
auto value = ctx.values.resolve_path (expr.get_segments ());
if (!value.has_value ())
rust_unreachable (); // Should have been resolved earlier

if (value->is_ambiguous ())
tl::optional<Rib::Definition> resolved = tl::nullopt;

if (auto value = ctx.values.resolve_path (expr.get_segments ()))
{
resolved = value;
}
else if (auto type = ctx.types.resolve_path (expr.get_segments ()))
{
resolved = type;
}
else
{
rust_error_at (expr.get_locus (),
"could not resolve path expression: %qs",
expr.as_simple_path ().as_string ().c_str ());
return;
}

if (resolved->is_ambiguous ())
{
rust_error_at (expr.get_locus (), ErrorCode::E0659, "%qs is ambiguous",
expr.as_string ().c_str ());
return;
}
ctx.map_usage (Usage (expr.get_node_id ()),
Definition (value->get_node_id ()));
Definition (resolved->get_node_id ()));
}

void
Expand Down
4 changes: 0 additions & 4 deletions gcc/testsuite/rust/compile/nr2/exclude
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ feature_rust_attri0.rs
feature_rust_attri1.rs
for_lifetimes.rs
format_args_basic_expansion.rs
found_struct.rs
generic-default1.rs
generics1.rs
generics10.rs
Expand Down Expand Up @@ -145,10 +144,8 @@ match2.rs
match3.rs
match4.rs
match5.rs
match8.rs
match9.rs
method2.rs
missing_constructor_fields.rs
multi_reference_type.rs
multiple_bindings1.rs
multiple_bindings2.rs
Expand Down Expand Up @@ -203,7 +200,6 @@ traits6.rs
traits7.rs
traits8.rs
traits9.rs
tuple_struct1.rs
type-bindings1.rs
unconstrained_type_param.rs
undeclared_label.rs
Expand Down

0 comments on commit eb863f6

Please sign in to comment.