Skip to content

Commit f0ccf26

Browse files
kupiakoscopybara-github
authored andcommitted
Correct raw identifier terminology in rust_keywords
PiperOrigin-RevId: 599954613
1 parent f6812b7 commit f0ccf26

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

rust/test/shared/reserved_test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
/// Test covering proto compilation with reserved words.
99
use googletest::prelude::*;
1010
use reserved_proto::r#enum;
11-
use reserved_proto::Self__mangled_because_symbol_is_a_rust_raw_identifier;
11+
use reserved_proto::Self__mangled_because_ident_isnt_a_legal_raw_identifier;
1212

1313
#[test]
1414
fn test_reserved_keyword_in_accessors() {
15-
let msg = Self__mangled_because_symbol_is_a_rust_raw_identifier::new();
16-
let res = msg.self__mangled_because_symbol_is_a_rust_raw_identifier().r#for();
15+
let msg = Self__mangled_because_ident_isnt_a_legal_raw_identifier::new();
16+
let res = msg.self__mangled_because_ident_isnt_a_legal_raw_identifier().r#for();
1717
assert_that!(res, eq(0));
1818
}
1919

src/google/protobuf/compiler/rust/naming.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,9 @@ std::string FieldInfoComment(Context& ctx, const FieldDescriptor& field) {
246246
}
247247

248248
std::string RsSafeName(absl::string_view name) {
249-
if (IsNotLegalEvenWithRPoundPrefix(name)) {
249+
if (!IsLegalRawIdentifierName(name)) {
250250
return absl::StrCat(name,
251-
"__mangled_because_symbol_is_a_rust_raw_identifier");
251+
"__mangled_because_ident_isnt_a_legal_raw_identifier");
252252
}
253253
if (IsRustKeyword(name)) {
254254
return absl::StrCat("r#", name);

src/google/protobuf/compiler/rust/rust_keywords.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ namespace protobuf {
1717
namespace compiler {
1818
namespace rust {
1919

20-
bool IsNotLegalEvenWithRPoundPrefix(absl::string_view str) {
20+
bool IsLegalRawIdentifierName(absl::string_view str_without_r_prefix) {
2121
// These keywords cannot be used even with an r# prefix.
2222
// https://doc.rust-lang.org/reference/identifiers.html
23-
static const auto* rust_raw_identifiers =
23+
static const auto* illegal_raw_identifiers =
2424
new absl::flat_hash_set<std::string>{"crate", "self", "super", "Self"};
25-
return rust_raw_identifiers->contains(str);
25+
return !illegal_raw_identifiers->contains(str_without_r_prefix);
2626
}
2727

2828
bool IsRustKeyword(absl::string_view str) {

src/google/protobuf/compiler/rust/rust_keywords.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ namespace protobuf {
1515
namespace compiler {
1616
namespace rust {
1717

18-
// Returns true if the provided str is a 'Raw Identifier', which is a symbol
19-
// which cannot be used even with r# prefix.
20-
bool IsNotLegalEvenWithRPoundPrefix(absl::string_view str);
18+
// Returns true if the provided name is legal to use as a raw identifier name
19+
// by prefixing with r#
20+
// https://doc.rust-lang.org/reference/identifiers.html#raw-identifiers
21+
bool IsLegalRawIdentifierName(absl::string_view str_without_r_prefix);
2122

2223
// Returns true if the provided str is a Rust 2021 Edition keyword and cannot be
23-
// used as a symbol. These symbols can can be used with an r# prefix unless
24-
// IsNotLegalEvenWithRPoundPrefix is true. This function should always match the
24+
// used as an identifier. These symbols can be used with an r# prefix unless
25+
// IsLegalRawIdentifierName returns false. This function should always match the
2526
// behavior for the corresponding Edition that our emitted crates use.
2627
bool IsRustKeyword(absl::string_view str);
2728

0 commit comments

Comments
 (0)