Skip to content

Commit

Permalink
Use keyword const values instead of raw values
Browse files Browse the repository at this point in the history
Change the keyword values from a raw string value to their matching const
value in utils.

gcc/rust/ChangeLog:

	* lex/rust-lex.cc (Lexer::parse_raw_identifier): Use const value.
	* parse/rust-parse-impl.h (Parser::parse_simple_path_segment):
	Likewise.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
  • Loading branch information
P-E-P committed Nov 8, 2023
1 parent 4549e34 commit c904e25
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 7 additions & 2 deletions gcc/rust/lex/rust-lex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1938,8 +1938,13 @@ Lexer::parse_raw_identifier (location_t loc)
rust_error_at (get_current_location (),
"%<_%> is not a valid raw identifier");

if (str == "crate" || str == "extern" || str == "self" || str == "super"
|| str == "Self")
using namespace Rust::Values;
std::set<std::string> invalid{
Keywords::CRATE, Keywords::EXTERN_TOK, Keywords::SELF,
Keywords::SUPER, Keywords::SELF_ALIAS,
};

if (invalid.find (str) != invalid.end ())
{
rust_error_at (get_current_location (),
"%qs is a forbidden raw identifier", str.c_str ());
Expand Down
8 changes: 5 additions & 3 deletions gcc/rust/parse/rust-parse-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "rust-make-unique.h"
#include "rust-dir-owner.h"
#include "rust-attribute-values.h"
#include "rust-keyword-values.h"

namespace Rust {
// Left binding powers of operations.
Expand Down Expand Up @@ -680,6 +681,7 @@ template <typename ManagedTokenSource>
AST::SimplePathSegment
Parser<ManagedTokenSource>::parse_simple_path_segment ()
{
using namespace Values;
const_TokenPtr t = lexer.peek_token ();
switch (t->get_id ())
{
Expand All @@ -690,15 +692,15 @@ Parser<ManagedTokenSource>::parse_simple_path_segment ()
case SUPER:
lexer.skip_token ();

return AST::SimplePathSegment ("super", t->get_locus ());
return AST::SimplePathSegment (Keywords::SUPER, t->get_locus ());
case SELF:
lexer.skip_token ();

return AST::SimplePathSegment ("self", t->get_locus ());
return AST::SimplePathSegment (Keywords::SELF, t->get_locus ());
case CRATE:
lexer.skip_token ();

return AST::SimplePathSegment ("crate", t->get_locus ());
return AST::SimplePathSegment (Keywords::CRATE, t->get_locus ());
case DOLLAR_SIGN:
if (lexer.peek_token (1)->get_id () == CRATE)
{
Expand Down

0 comments on commit c904e25

Please sign in to comment.