diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-09-15 13:14:56 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-08-01 16:52:25 +0200 |
commit | a3b96f6b74728d0e35ca38327603929d9c4eb678 (patch) | |
tree | 533a300c40a775afa1a2a0762b8faa3be03353c4 /gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | |
parent | d61973e4dd48259577dbc3f2cb4f9b2a489a7950 (diff) | |
download | gcc-a3b96f6b74728d0e35ca38327603929d9c4eb678.zip gcc-a3b96f6b74728d0e35ca38327603929d9c4eb678.tar.gz gcc-a3b96f6b74728d0e35ca38327603929d9c4eb678.tar.bz2 |
gccrs: Emit error on identical use declarations
The compiler did not emit any warning when a same target was declared
from different sources.
gcc/rust/ChangeLog:
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::handle_use_dec):
Use the new dict to track down already resolved use declarations.
* resolve/rust-toplevel-name-resolver-2.0.h: Add new dict to store
previous use declarations.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc')
-rw-r--r-- | gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 76 |
1 files changed, 42 insertions, 34 deletions
diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc index 407892b..94cc3cb 100644 --- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc @@ -319,40 +319,48 @@ TopLevel::handle_use_dec (AST::SimplePath path) auto found = false; - auto resolve_and_insert = [this, &found, &declared_name, - locus] (Namespace ns, - const AST::SimplePath &path) { - tl::optional<NodeId> resolved = tl::nullopt; - - // FIXME: resolve_path needs to return an `expected<NodeId, Error>` so - // that we can improve it with hints or location or w/ever. and maybe - // only emit it the first time. - switch (ns) - { - case Namespace::Values: - resolved = ctx.values.resolve_path (path.get_segments ()); - break; - case Namespace::Types: - resolved = ctx.types.resolve_path (path.get_segments ()); - break; - case Namespace::Macros: - resolved = ctx.macros.resolve_path (path.get_segments ()); - break; - case Namespace::Labels: - // TODO: Is that okay? - rust_unreachable (); - } - - // FIXME: Ugly - (void) resolved.map ([this, &found, &declared_name, locus, ns] (NodeId id) { - found = true; - - // what do we do with the id? - insert_or_error_out (declared_name, locus, id, ns); - - return id; - }); - }; + auto resolve_and_insert + = [this, &found, &declared_name, locus] (Namespace ns, + const AST::SimplePath &path) { + tl::optional<NodeId> resolved = tl::nullopt; + + // FIXME: resolve_path needs to return an `expected<NodeId, Error>` so + // that we can improve it with hints or location or w/ever. and maybe + // only emit it the first time. + switch (ns) + { + case Namespace::Values: + resolved = ctx.values.resolve_path (path.get_segments ()); + break; + case Namespace::Types: + resolved = ctx.types.resolve_path (path.get_segments ()); + break; + case Namespace::Macros: + resolved = ctx.macros.resolve_path (path.get_segments ()); + break; + case Namespace::Labels: + // TODO: Is that okay? + rust_unreachable (); + } + + // FIXME: Ugly + (void) resolved.map ( + [this, &found, &declared_name, locus, ns, path] (NodeId id) { + found = true; + + // what do we do with the id? + insert_or_error_out (declared_name, locus, id, ns); + auto result = node_forwarding.find (id); + if (result != node_forwarding.cend () + && result->second != path.get_node_id ()) + rust_error_at (path.get_locus (), "%<%s%> defined multiple times", + declared_name.c_str ()); + else // No previous thing has inserted this into our scope + node_forwarding.insert ({id, path.get_node_id ()}); + + return id; + }); + }; // do this for all namespaces (even Labels?) |