aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/ast/rust-pattern.h
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/rust/ast/rust-pattern.h')
-rw-r--r--gcc/rust/ast/rust-pattern.h46
1 files changed, 23 insertions, 23 deletions
diff --git a/gcc/rust/ast/rust-pattern.h b/gcc/rust/ast/rust-pattern.h
index 6a90b53..96f0935 100644
--- a/gcc/rust/ast/rust-pattern.h
+++ b/gcc/rust/ast/rust-pattern.h
@@ -1123,22 +1123,22 @@ class TupleStructPattern : public Pattern
public:
std::string as_string () const override;
- // Returns whether the pattern has tuple struct items.
- bool has_items () const { return items != nullptr; }
-
TupleStructPattern (PathInExpression tuple_struct_path,
std::unique_ptr<TupleStructItems> items)
: path (std::move (tuple_struct_path)), items (std::move (items)),
node_id (Analysis::Mappings::get ()->get_next_node_id ())
- {}
+ {
+ rust_assert (this->items != nullptr);
+ }
// Copy constructor required to clone
TupleStructPattern (TupleStructPattern const &other) : path (other.path)
{
// guard to protect from null dereference
+ rust_assert (other.items != nullptr);
+
node_id = other.node_id;
- if (other.items != nullptr)
- items = other.items->clone_tuple_struct_items ();
+ items = other.items->clone_tuple_struct_items ();
}
// Operator overload assignment operator to clone
@@ -1148,10 +1148,9 @@ public:
node_id = other.node_id;
// guard to protect from null dereference
- if (other.items != nullptr)
- items = other.items->clone_tuple_struct_items ();
- else
- items = nullptr;
+ rust_assert (other.items != nullptr);
+
+ items = other.items->clone_tuple_struct_items ();
return *this;
}
@@ -1164,7 +1163,11 @@ public:
void accept_vis (ASTVisitor &vis) override;
- std::unique_ptr<TupleStructItems> &get_items () { return items; }
+ std::unique_ptr<TupleStructItems> &get_items ()
+ {
+ rust_assert (items != nullptr);
+ return items;
+ }
PathInExpression &get_path () { return path; }
const PathInExpression &get_path () const { return path; }
@@ -1358,7 +1361,6 @@ protected:
// AST node representing a tuple pattern
class TuplePattern : public Pattern
{
- // bool has_tuple_pattern_items;
std::unique_ptr<TuplePatternItems> items;
location_t locus;
NodeId node_id;
@@ -1366,21 +1368,21 @@ class TuplePattern : public Pattern
public:
std::string as_string () const override;
- // Returns true if the tuple pattern has items
- bool has_tuple_pattern_items () const { return items != nullptr; }
-
TuplePattern (std::unique_ptr<TuplePatternItems> items, location_t locus)
: items (std::move (items)), locus (locus),
node_id (Analysis::Mappings::get ()->get_next_node_id ())
- {}
+ {
+ rust_assert (this->items != nullptr);
+ }
// Copy constructor requires clone
TuplePattern (TuplePattern const &other) : locus (other.locus)
{
// guard to prevent null dereference
+ rust_assert (other.items != nullptr);
+
node_id = other.node_id;
- if (other.items != nullptr)
- items = other.items->clone_tuple_pattern_items ();
+ items = other.items->clone_tuple_pattern_items ();
}
// Overload assignment operator to clone
@@ -1390,11 +1392,9 @@ public:
node_id = other.node_id;
// guard to prevent null dereference
- if (other.items != nullptr)
- items = other.items->clone_tuple_pattern_items ();
- else
- items = nullptr;
+ rust_assert (other.items != nullptr);
+ items = other.items->clone_tuple_pattern_items ();
return *this;
}
@@ -1405,7 +1405,7 @@ public:
// TODO: seems kinda dodgy. Think of better way.
std::unique_ptr<TuplePatternItems> &get_items ()
{
- rust_assert (has_tuple_pattern_items ());
+ rust_assert (items != nullptr);
return items;
}