aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/resolve
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-02-05 11:43:44 +0000
committerPhilip Herron <herron.philip@googlemail.com>2021-02-06 15:29:01 +0000
commit75b6fc46bd64599e565582b46bf6f2197b2bc53f (patch)
tree1eecacbddf9c31f91c000cb76939c483234974e6 /gcc/rust/resolve
parent599b04aa7d928a305029d8e8cf5d6f5c5a683da8 (diff)
downloadgcc-75b6fc46bd64599e565582b46bf6f2197b2bc53f.zip
gcc-75b6fc46bd64599e565582b46bf6f2197b2bc53f.tar.gz
gcc-75b6fc46bd64599e565582b46bf6f2197b2bc53f.tar.bz2
Move scan for unused names to be after type resolution
Methods are resolved as part of type resolution so scanning ribs early on will results in false warnings about unused methods.
Diffstat (limited to 'gcc/rust/resolve')
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-item.h4
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-unused.h11
-rw-r--r--gcc/rust/resolve/rust-ast-resolve.cc7
-rw-r--r--gcc/rust/resolve/rust-name-resolver.h17
4 files changed, 26 insertions, 13 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-item.h b/gcc/rust/resolve/rust-ast-resolve-item.h
index 74b5f8d..cc8e451 100644
--- a/gcc/rust/resolve/rust-ast-resolve-item.h
+++ b/gcc/rust/resolve/rust-ast-resolve-item.h
@@ -24,7 +24,6 @@
#include "rust-ast-resolve-type.h"
#include "rust-ast-resolve-pattern.h"
#include "rust-ast-resolve-stmt.h"
-#include "rust-ast-resolve-unused.h"
namespace Rust {
namespace Resolver {
@@ -110,9 +109,6 @@ public:
ResolveExpr::go (function.get_definition ().get (),
function.get_node_id ());
- ScanUnused::Scan (resolver->get_name_scope ().peek ());
- ScanUnused::Scan (resolver->get_type_scope ().peek ());
-
resolver->get_name_scope ().pop ();
resolver->get_type_scope ().pop ();
}
diff --git a/gcc/rust/resolve/rust-ast-resolve-unused.h b/gcc/rust/resolve/rust-ast-resolve-unused.h
index 08b2db1..928cf11 100644
--- a/gcc/rust/resolve/rust-ast-resolve-unused.h
+++ b/gcc/rust/resolve/rust-ast-resolve-unused.h
@@ -24,10 +24,10 @@
namespace Rust {
namespace Resolver {
-class ScanUnused : public ResolverBase
+class ScanUnused
{
public:
- static void Scan (Rib *r)
+ static void ScanRib (Rib *r)
{
r->iterate_decls ([&] (NodeId decl_node_id, Location locus) -> bool {
if (!r->have_references_for_node (decl_node_id))
@@ -37,6 +37,13 @@ public:
return true;
});
}
+
+ static void Scan ()
+ {
+ auto resolver = Resolver::get ();
+ resolver->iterate_name_ribs ([&] (Rib *r) -> void { ScanRib (r); });
+ resolver->iterate_type_ribs ([&] (Rib *r) -> void { ScanRib (r); });
+ }
};
} // namespace Resolver
diff --git a/gcc/rust/resolve/rust-ast-resolve.cc b/gcc/rust/resolve/rust-ast-resolve.cc
index fd49720..593a732 100644
--- a/gcc/rust/resolve/rust-ast-resolve.cc
+++ b/gcc/rust/resolve/rust-ast-resolve.cc
@@ -22,7 +22,6 @@
#include "rust-ast-resolve-toplevel.h"
#include "rust-ast-resolve-item.h"
#include "rust-ast-resolve-expr.h"
-#include "rust-ast-resolve-unused.h"
#define MKBUILTIN_TYPE(_X, _R, _TY) \
do \
@@ -284,9 +283,6 @@ NameResolution::go (AST::Crate &crate)
// next we can drill down into the items and their scopes
for (auto it = crate.items.begin (); it != crate.items.end (); it++)
ResolveItem::go (it->get ());
-
- ScanUnused::Scan (resolver->get_name_scope ().peek ());
- ScanUnused::Scan (resolver->get_type_scope ().peek ());
}
// rust-ast-resolve-expr.h
@@ -308,9 +304,6 @@ ResolveExpr::visit (AST::BlockExpr &expr)
if (expr.has_tail_expr ())
ResolveExpr::go (expr.get_tail_expr ().get (), expr.get_node_id ());
- ScanUnused::Scan (resolver->get_name_scope ().peek ());
- ScanUnused::Scan (resolver->get_type_scope ().peek ());
-
resolver->get_name_scope ().pop ();
resolver->get_type_scope ().pop ();
}
diff --git a/gcc/rust/resolve/rust-name-resolver.h b/gcc/rust/resolve/rust-name-resolver.h
index f22eba7..5544f30 100644
--- a/gcc/rust/resolve/rust-name-resolver.h
+++ b/gcc/rust/resolve/rust-name-resolver.h
@@ -290,6 +290,23 @@ public:
return it->second.size ();
}
+ void iterate_name_ribs (std::function<void (Rib *)> cb)
+ {
+ for (auto it = name_ribs.begin (); it != name_ribs.end (); it++)
+ cb (it->second);
+ }
+
+ void iterate_type_ribs (std::function<void (Rib *)> cb)
+ {
+ for (auto it = type_ribs.begin (); it != type_ribs.end (); it++)
+ {
+ if (it->first == global_type_node_id)
+ continue;
+
+ cb (it->second);
+ }
+ }
+
private:
Resolver ();