]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix FnParam pattern location ternary logic
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Wed, 20 Nov 2024 00:28:04 +0000 (01:28 +0100)
committerP-E-P <32375388+P-E-P@users.noreply.github.com>
Wed, 20 Nov 2024 13:36:42 +0000 (13:36 +0000)
Condition was inverted, we should retrieve the locus only if we have a
pattern.

gcc/rust/ChangeLog:

* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Do not
get a reference if the pattern does not exist.
(TypeCheckMethodCallExpr::check): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/typecheck/rust-tyty-call.cc

index da1c383b2ca27a3be12f29f1d06c8b5af03f91d5..dbb0379ebbfce919152d5b4429de6cb6882e3d0c 100644 (file)
@@ -152,12 +152,11 @@ TypeCheckCallExpr::visit (FnType &type)
       if (i < type.num_params ())
        {
          auto &fnparam = type.param_at (i);
-         auto &fn_param_pattern = fnparam.get_pattern ();
          BaseType *param_ty = fnparam.get_type ();
          location_t param_locus
            = fnparam.has_pattern ()
-               ? mappings.lookup_location (param_ty->get_ref ())
-               : fn_param_pattern.get_locus ();
+               ? fnparam.get_pattern ().get_locus ()
+               : mappings.lookup_location (param_ty->get_ref ());
 
          HirId coercion_side_id = argument->get_mappings ().get_hirid ();
          auto resolved_argument_type
@@ -375,12 +374,11 @@ TypeCheckMethodCallExpr::check (FnType &type)
       location_t arg_locus = argument.get_locus ();
 
       auto &fnparam = type.param_at (i);
-      HIR::Pattern &fn_param_pattern = fnparam.get_pattern ();
       BaseType *param_ty = fnparam.get_type ();
       location_t param_locus
        = fnparam.has_pattern ()
-           ? mappings.lookup_location (param_ty->get_ref ())
-           : fn_param_pattern.get_locus ();
+           ? fnparam.get_pattern ().get_locus ()
+           : mappings.lookup_location (param_ty->get_ref ());
 
       auto argument_expr_tyty = argument.get_argument_type ();
       HirId coercion_side_id = argument.get_mappings ().get_hirid ();