aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/resolve
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2024-02-21 16:45:18 +0100
committerP-E-P <32375388+P-E-P@users.noreply.github.com>2024-03-13 11:58:12 +0000
commit843d7d7b46133fc471ed51d165a979c5af059aea (patch)
tree759553dc571b0f2c9522601d213af5e9f3378d8c /gcc/rust/resolve
parent444d1a98e77bb725e43267e9e93ddbf351bb2ef4 (diff)
downloadgcc-843d7d7b46133fc471ed51d165a979c5af059aea.zip
gcc-843d7d7b46133fc471ed51d165a979c5af059aea.tar.gz
gcc-843d7d7b46133fc471ed51d165a979c5af059aea.tar.bz2
Replace reference to unique pointer with reference
Reference to unique pointers are a known anti pattern, only the element shall be taken by reference instead of the whole wrapper. gcc/rust/ChangeLog: * ast/rust-item.h: Change getter function prototype to return a reference directly instead of a reference to the wrapper type. * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Fix the code to accept references instead. * hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_self): Change function implementation to return a reference. * hir/rust-ast-lower-base.h: Accept a reference instead of a unique pointer reference. * resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Adapt the code to a reference instead of a unique pointer. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust/resolve')
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-item.cc19
1 files changed, 9 insertions, 10 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc
index a3f27b3..c65f112 100644
--- a/gcc/rust/resolve/rust-ast-resolve-item.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-item.cc
@@ -489,32 +489,31 @@ ResolveItem::visit (AST::Function &function)
if (function.has_self_param ())
{
// self turns into (self: Self) as a function param
- std::unique_ptr<AST::Param> &s_param = function.get_self_param ();
- auto self_param = static_cast<AST::SelfParam *> (s_param.get ());
+ AST::Param &s_param = function.get_self_param ();
+ auto &self_param = static_cast<AST::SelfParam &> (s_param);
// FIXME: which location should be used for Rust::Identifier `self`?
AST::IdentifierPattern self_pattern (
- self_param->get_node_id (), {"self"}, self_param->get_locus (),
- self_param->get_has_ref (), self_param->get_is_mut (),
+ self_param.get_node_id (), {"self"}, self_param.get_locus (),
+ self_param.get_has_ref (), self_param.get_is_mut (),
std::unique_ptr<AST::Pattern> (nullptr));
PatternDeclaration::go (&self_pattern, Rib::ItemType::Param);
- if (self_param->has_type ())
+ if (self_param.has_type ())
{
// This shouldn't happen the parser should already error for this
- rust_assert (!self_param->get_has_ref ());
- ResolveType::go (self_param->get_type ().get ());
+ rust_assert (!self_param.get_has_ref ());
+ ResolveType::go (self_param.get_type ().get ());
}
else
{
// here we implicitly make self have a type path of Self
std::vector<std::unique_ptr<AST::TypePathSegment>> segments;
segments.push_back (std::unique_ptr<AST::TypePathSegment> (
- new AST::TypePathSegment ("Self", false,
- self_param->get_locus ())));
+ new AST::TypePathSegment ("Self", false, self_param.get_locus ())));
AST::TypePath self_type_path (std::move (segments),
- self_param->get_locus ());
+ self_param.get_locus ());
ResolveType::go (&self_type_path);
}
}