Skip to content

Commit cd4d7a7

Browse files
powerboat9CohenArthur
authored andcommitted
Remove Parser::parse_tuple_index_expr_float
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 <[email protected]>
1 parent 85be45d commit cd4d7a7

File tree

2 files changed

+3
-35
lines changed

2 files changed

+3
-35
lines changed

gcc/rust/parse/rust-parse-impl.h

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13032,12 +13032,6 @@ Parser<ManagedTokenSource>::left_denotation (const_TokenPtr tok,
1303213032
// array or slice index expression (pseudo binary infix)
1303313033
return parse_index_expr (tok, std::move (left), std::move (outer_attrs),
1303413034
restrictions);
13035-
case FLOAT_LITERAL:
13036-
/* HACK: get around lexer mis-identifying '.0' or '.1' or whatever as a
13037-
* float literal - TODO does this happen anymore? It shouldn't. */
13038-
return parse_tuple_index_expr_float (tok, std::move (left),
13039-
std::move (outer_attrs),
13040-
restrictions);
1304113035
default:
1304213036
add_error (Error (tok->get_locus (),
1304313037
"found unexpected token %qs in left denotation",
@@ -14570,35 +14564,6 @@ Parser<ManagedTokenSource>::parse_closure_expr_pratt (const_TokenPtr tok,
1457014564
}
1457114565
}
1457214566

14573-
/* Parses a tuple index expression (pratt-parsed) from a 'float' token as a
14574-
* result of lexer misidentification. */
14575-
template <typename ManagedTokenSource>
14576-
std::unique_ptr<AST::TupleIndexExpr>
14577-
Parser<ManagedTokenSource>::parse_tuple_index_expr_float (
14578-
const_TokenPtr tok, std::unique_ptr<AST::Expr> tuple_expr,
14579-
AST::AttrVec outer_attrs, ParseRestrictions restrictions ATTRIBUTE_UNUSED)
14580-
{
14581-
// only works on float literals
14582-
if (tok->get_id () != FLOAT_LITERAL)
14583-
return nullptr;
14584-
14585-
// DEBUG:
14586-
rust_debug ("exact string form of float: '%s'", tok->get_str ().c_str ());
14587-
14588-
// get float string and remove dot and initial 0
14589-
std::string index_str = tok->get_str ();
14590-
index_str.erase (index_str.begin ());
14591-
14592-
// get int from string
14593-
int index = atoi (index_str.c_str ());
14594-
14595-
location_t locus = tuple_expr->get_locus ();
14596-
14597-
return std::unique_ptr<AST::TupleIndexExpr> (
14598-
new AST::TupleIndexExpr (std::move (tuple_expr), index,
14599-
std::move (outer_attrs), locus));
14600-
}
14601-
1460214567
// Returns true if the next token is END, ELSE, or EOF;
1460314568
template <typename ManagedTokenSource>
1460414569
bool
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// floating point literals can't start with a '.'
2+
// TODO: improve the error message emitted here
3+
const X: f32 = .5; // { dg-error ".*" }

0 commit comments

Comments
 (0)