aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-05-20 08:35:16 +0000
committerGitHub <noreply@github.com>2021-05-20 08:35:16 +0000
commit05f9e179a86ffe24a080a5e1de2b67e9164bd8c6 (patch)
tree2c2de3c22368ec2cc89165caf0c4baf5d37b22a8 /gcc/rust
parent4d71539414ca4e5edb51556b136b0b5eaee9a084 (diff)
parentf33f618e35e8d321270d978cf17037cc1be98ae9 (diff)
downloadgcc-05f9e179a86ffe24a080a5e1de2b67e9164bd8c6.zip
gcc-05f9e179a86ffe24a080a5e1de2b67e9164bd8c6.tar.gz
gcc-05f9e179a86ffe24a080a5e1de2b67e9164bd8c6.tar.bz2
Merge #433
433: Allow unused underscore identifiers r=philberty a=CohenArthur This fixes #361 Co-authored-by: CohenArthur <arthur.cohen@epita.fr>
Diffstat (limited to 'gcc/rust')
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-unused.h8
-rw-r--r--gcc/rust/resolve/rust-name-resolver.h14
2 files changed, 21 insertions, 1 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-unused.h b/gcc/rust/resolve/rust-ast-resolve-unused.h
index 748f972..bd71110 100644
--- a/gcc/rust/resolve/rust-ast-resolve-unused.h
+++ b/gcc/rust/resolve/rust-ast-resolve-unused.h
@@ -30,7 +30,13 @@ public:
static void ScanRib (Rib *r)
{
r->iterate_decls ([&] (NodeId decl_node_id, Location locus) -> bool {
- if (!r->have_references_for_node (decl_node_id))
+ CanonicalPath ident = CanonicalPath::create_empty ();
+
+ bool ok = r->lookup_canonical_path (decl_node_id, &ident);
+ rust_assert (ok);
+
+ if (!r->have_references_for_node (decl_node_id)
+ && ident.get ().at (0) != '_')
{
rust_warning_at (locus, 0, "unused name");
}
diff --git a/gcc/rust/resolve/rust-name-resolver.h b/gcc/rust/resolve/rust-name-resolver.h
index 205c877..e45847e 100644
--- a/gcc/rust/resolve/rust-name-resolver.h
+++ b/gcc/rust/resolve/rust-name-resolver.h
@@ -114,6 +114,7 @@ public:
}
mappings[path] = id;
+ reverse_mappings.insert (std::pair<NodeId, CanonicalPath> (id, path));
decls_within_rib.insert (std::pair<NodeId, Location> (id, locus));
references[id] = {};
}
@@ -128,9 +129,21 @@ public:
return true;
}
+ bool lookup_canonical_path (const NodeId &id, CanonicalPath *ident)
+ {
+ auto it = reverse_mappings.find (id);
+ if (it == reverse_mappings.end ())
+ return false;
+
+ *ident = it->second;
+ return true;
+ }
+
void clear_name (const CanonicalPath &ident, NodeId id)
{
mappings.erase (ident);
+ reverse_mappings.erase (id);
+
for (auto &it : decls_within_rib)
{
if (it.first == id)
@@ -194,6 +207,7 @@ private:
CrateNum crate_num;
NodeId node_id;
std::map<CanonicalPath, NodeId> mappings;
+ std::map<NodeId, CanonicalPath> reverse_mappings;
std::set<std::pair<NodeId, Location> > decls_within_rib;
std::map<NodeId, std::set<NodeId> > references;
};