]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Remove Parser::parse_tuple_index_expr_float
authorOwen Avery <powerboat9.gamer@gmail.com>
Sat, 23 Aug 2025 19:32:13 +0000 (15:32 -0400)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 30 Oct 2025 19:58:50 +0000 (20:58 +0100)
Unlike in C, floating point literals can't start with a '.', and
therefore could never be split into a '.' followed by an integer.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::left_denotation): Remove
usage of parse_tuple_index_expr_float.
(Parser::parse_closure_expr_pratt): Remove function.

gcc/testsuite/ChangeLog:

* rust/compile/parse_float_dot.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/parse/rust-parse-impl.h
gcc/testsuite/rust/compile/parse_float_dot.rs [new file with mode: 0644]

index 9b38396e95c2a0cf1162681cc83c706e7c549895..bd12c384c3ac1ac2857fafc3ef92f0b1d1c9c5b9 100644 (file)
@@ -13032,12 +13032,6 @@ Parser<ManagedTokenSource>::left_denotation (const_TokenPtr tok,
       // array or slice index expression (pseudo binary infix)
       return parse_index_expr (tok, std::move (left), std::move (outer_attrs),
                               restrictions);
-    case FLOAT_LITERAL:
-      /* HACK: get around lexer mis-identifying '.0' or '.1' or whatever as a
-       * float literal - TODO does this happen anymore? It shouldn't. */
-      return parse_tuple_index_expr_float (tok, std::move (left),
-                                          std::move (outer_attrs),
-                                          restrictions);
     default:
       add_error (Error (tok->get_locus (),
                        "found unexpected token %qs in left denotation",
@@ -14570,35 +14564,6 @@ Parser<ManagedTokenSource>::parse_closure_expr_pratt (const_TokenPtr tok,
     }
 }
 
-/* Parses a tuple index expression (pratt-parsed) from a 'float' token as a
- * result of lexer misidentification. */
-template <typename ManagedTokenSource>
-std::unique_ptr<AST::TupleIndexExpr>
-Parser<ManagedTokenSource>::parse_tuple_index_expr_float (
-  const_TokenPtr tok, std::unique_ptr<AST::Expr> tuple_expr,
-  AST::AttrVec outer_attrs, ParseRestrictions restrictions ATTRIBUTE_UNUSED)
-{
-  // only works on float literals
-  if (tok->get_id () != FLOAT_LITERAL)
-    return nullptr;
-
-  // DEBUG:
-  rust_debug ("exact string form of float: '%s'", tok->get_str ().c_str ());
-
-  // get float string and remove dot and initial 0
-  std::string index_str = tok->get_str ();
-  index_str.erase (index_str.begin ());
-
-  // get int from string
-  int index = atoi (index_str.c_str ());
-
-  location_t locus = tuple_expr->get_locus ();
-
-  return std::unique_ptr<AST::TupleIndexExpr> (
-    new AST::TupleIndexExpr (std::move (tuple_expr), index,
-                            std::move (outer_attrs), locus));
-}
-
 // Returns true if the next token is END, ELSE, or EOF;
 template <typename ManagedTokenSource>
 bool
diff --git a/gcc/testsuite/rust/compile/parse_float_dot.rs b/gcc/testsuite/rust/compile/parse_float_dot.rs
new file mode 100644 (file)
index 0000000..bfe3da2
--- /dev/null
@@ -0,0 +1,3 @@
+// floating point literals can't start with a '.'
+// TODO: improve the error message emitted here
+const X: f32 = .5; // { dg-error ".*" }