diff --git a/src/ty/path.rs b/src/ty/path.rs index d18be62b..f19f57dc 100644 --- a/src/ty/path.rs +++ b/src/ty/path.rs @@ -205,6 +205,16 @@ mod tests { ); } + #[test] + fn path_with_raw_identifers_ok() { + assert_eq!( + Path::from_segments(vec!["r#mod", "r#Struct"]), + Ok(Path { + segments: vec!["r#mod", "r#Struct"] + }) + ); + } + #[test] fn path_err() { assert_eq!(Path::from_segments(vec![]), Err(PathError::MissingSegments)); diff --git a/src/utils.rs b/src/utils.rs index 63a93e23..88f76cf2 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -19,7 +19,9 @@ pub fn is_rust_identifier(s: &str) -> bool { if !s.is_ascii() { return false } - if let Some((&head, tail)) = s.as_bytes().split_first() { + // Trim valid raw identifier prefix + let trimmed = s.trim_start_matches("r#"); + if let Some((&head, tail)) = trimmed.as_bytes().split_first() { // Check if head and tail make up a proper Rust identifier. let head_ok = head == b'_' || (b'a'..=b'z').contains(&head) diff --git a/test_suite/tests/ui/fail_missing_derive.stderr b/test_suite/tests/ui/fail_missing_derive.stderr index 74ba2095..801764b4 100644 --- a/test_suite/tests/ui/fail_missing_derive.stderr +++ b/test_suite/tests/ui/fail_missing_derive.stderr @@ -4,6 +4,16 @@ error[E0277]: the trait bound `PawType: TypeInfo` is not satisfied 19 | assert_type_info::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TypeInfo` is not implemented for `PawType` | + = help: the following other types implement trait `TypeInfo`: + &T + &mut T + () + (A, B) + (A, B, C) + (A, B, C, D) + (A, B, C, D, E) + (A, B, C, D, E, F) + and 54 others note: required because of the requirements on the impl of `TypeInfo` for `Cat` --> tests/ui/fail_missing_derive.rs:8:10 | diff --git a/test_suite/tests/ui/fail_unions.stderr b/test_suite/tests/ui/fail_unions.stderr index 609a3220..3b0248d1 100644 --- a/test_suite/tests/ui/fail_unions.stderr +++ b/test_suite/tests/ui/fail_unions.stderr @@ -14,6 +14,16 @@ error[E0277]: the trait bound `Commonwealth: TypeInfo` is not satisfied 14 | assert_type_info::(); | ^^^^^^^^^^^^ the trait `TypeInfo` is not implemented for `Commonwealth` | + = help: the following other types implement trait `TypeInfo`: + &T + &mut T + () + (A, B) + (A, B, C) + (A, B, C, D) + (A, B, C, D, E) + (A, B, C, D, E, F) + and 53 others note: required by a bound in `assert_type_info` --> tests/ui/fail_unions.rs:11:24 | diff --git a/test_suite/tests/ui/pass_raw_identifers.rs b/test_suite/tests/ui/pass_raw_identifers.rs new file mode 100644 index 00000000..9e28649c --- /dev/null +++ b/test_suite/tests/ui/pass_raw_identifers.rs @@ -0,0 +1,21 @@ +use info::{self as scale_info}; +use scale_info::TypeInfo; + +#[allow(dead_code, non_camel_case_types)] +mod r#mod { + use super::*; + #[derive(TypeInfo)] + pub enum r#enum { + r#true, + } + #[derive(TypeInfo)] + pub struct r#struct { + r#try: r#enum, + } +} + +fn assert_type_info() {} + +fn main() { + assert_type_info::(); +}