aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorThomas Young <wenzhang5800@gmail.com>2021-07-07 13:20:48 +0800
committerThomas Young <wenzhang5800@gmail.com>2021-07-07 13:20:48 +0800
commit1e0b4e71a1e1d9d87c57d9bf72107fc0eca6befd (patch)
treebb855bc94c4000f7edd8862b45d05ab1d701ff9e /gcc
parent3670b0ef05041b8a1defb755804ef36e029d20db (diff)
downloadgcc-1e0b4e71a1e1d9d87c57d9bf72107fc0eca6befd.zip
gcc-1e0b4e71a1e1d9d87c57d9bf72107fc0eca6befd.tar.gz
gcc-1e0b4e71a1e1d9d87c57d9bf72107fc0eca6befd.tar.bz2
use rust_assert in dead code pass instead of rust_error_at
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/lint/rust-lint-marklive.cc58
-rw-r--r--gcc/rust/lint/rust-lint-marklive.h3
2 files changed, 21 insertions, 40 deletions
diff --git a/gcc/rust/lint/rust-lint-marklive.cc b/gcc/rust/lint/rust-lint-marklive.cc
index 8210b65..dd7e05d 100644
--- a/gcc/rust/lint/rust-lint-marklive.cc
+++ b/gcc/rust/lint/rust-lint-marklive.cc
@@ -92,7 +92,8 @@ void
MarkLive::visit (HIR::PathInExpression &expr)
{
expr.iterate_path_segments ([&] (HIR::PathExprSegment &seg) -> bool {
- return visit_path_segment (seg);
+ visit_path_segment (seg);
+ return true;
});
}
@@ -113,12 +114,13 @@ MarkLive::visit (HIR::MethodCallExpr &expr)
// node back to HIR
HirId ref;
- node_id_to_hir_id (expr.get_mappings ().get_crate_num (), ref_node_id, ref,
- expr.get_locus ());
+ rust_assert (
+ mappings->lookup_node_to_hir (expr.get_mappings ().get_crate_num (),
+ ref_node_id, &ref));
mark_hir_id (ref);
}
-bool
+void
MarkLive::visit_path_segment (HIR::PathExprSegment seg)
{
NodeId ast_node_id = seg.get_mappings ().get_nodeid ();
@@ -127,23 +129,18 @@ MarkLive::visit_path_segment (HIR::PathExprSegment seg)
if (resolver->lookup_resolved_name (ast_node_id, &ref_node_id))
{
Resolver::Definition def;
- if (!resolver->lookup_definition (ref_node_id, &def))
- {
- rust_error_at (seg.get_locus (),
- "unknown reference for resolved name");
- return false;
- }
+ rust_assert (resolver->lookup_definition (ref_node_id, &def));
ref_node_id = def.parent;
}
else if (!resolver->lookup_resolved_type (ast_node_id, &ref_node_id))
{
- return false;
+ return;
}
HirId ref;
- node_id_to_hir_id (seg.get_mappings ().get_crate_num (), ref_node_id, ref,
- seg.get_locus ());
+ rust_assert (
+ mappings->lookup_node_to_hir (seg.get_mappings ().get_crate_num (),
+ ref_node_id, &ref));
mark_hir_id (ref);
- return true;
}
void
@@ -195,8 +192,9 @@ MarkLive::visit (HIR::IdentifierExpr &expr)
// node back to HIR
HirId ref;
- node_id_to_hir_id (expr.get_mappings ().get_crate_num (), ref_node_id, ref,
- expr.get_locus ());
+ rust_assert (
+ mappings->lookup_node_to_hir (expr.get_mappings ().get_crate_num (),
+ ref_node_id, &ref));
mark_hir_id (ref);
}
@@ -207,8 +205,9 @@ MarkLive::visit (HIR::TypeAlias &alias)
resolver->lookup_resolved_type (
alias.get_type_aliased ()->get_mappings ().get_nodeid (), &ast_node_id);
HirId hir_id;
- node_id_to_hir_id (alias.get_mappings ().get_crate_num (), ast_node_id,
- hir_id, alias.get_locus ());
+ rust_assert (
+ mappings->lookup_node_to_hir (alias.get_mappings ().get_crate_num (),
+ ast_node_id, &hir_id));
mark_hir_id (hir_id);
}
@@ -231,29 +230,12 @@ MarkLive::find_ref_node_id (NodeId ast_node_id, NodeId &ref_node_id,
// these ref_node_ids will resolve to a pattern declaration but we are
// interested in the definition that this refers to get the parent id
Resolver::Definition def;
- if (!resolver->lookup_definition (ref_node_id, &def))
- {
- rust_error_at (locus, "unknown reference for resolved name");
- return;
- }
+ rust_assert (resolver->lookup_definition (ref_node_id, &def));
ref_node_id = def.parent;
}
- else if (!resolver->lookup_resolved_type (ast_node_id, &ref_node_id))
- {
- rust_error_at (locus, "Failed to lookup type reference for node: %s",
- node_name.c_str ());
- return;
- }
-}
-
-void
-MarkLive::node_id_to_hir_id (CrateNum crateNum, NodeId ref_node_id, HirId &ref,
- Location locus)
-{
- if (!mappings->lookup_node_to_hir (crateNum, ref_node_id, &ref))
+ else
{
- rust_error_at (locus, "reverse lookup failure");
- return;
+ rust_assert (resolver->lookup_resolved_type (ast_node_id, &ref_node_id));
}
}
diff --git a/gcc/rust/lint/rust-lint-marklive.h b/gcc/rust/lint/rust-lint-marklive.h
index 083d7b5..6a25779 100644
--- a/gcc/rust/lint/rust-lint-marklive.h
+++ b/gcc/rust/lint/rust-lint-marklive.h
@@ -266,10 +266,9 @@ private:
tyctx (Resolver::TypeCheckContext::get ()){};
void mark_hir_id (HirId);
- bool visit_path_segment (HIR::PathExprSegment);
+ void visit_path_segment (HIR::PathExprSegment);
void find_ref_node_id (NodeId ast_node_id, NodeId &ref_node_id,
Location locus, const std::string &node_name);
- void node_id_to_hir_id (CrateNum, NodeId, HirId &, Location);
};
} // namespace Analysis