Provide a suggestion to replace quoted raw identifier

This commit is contained in:
David Tolnay 2022-11-08 00:50:54 -08:00
parent dc5a920deb
commit 33432a868d
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 6 additions and 6 deletions

View File

@ -36,15 +36,15 @@ fn parse_unquoted(input: ParseStream, allow_raw: bool) -> Result<QualifiedName>
let leading_colons: Option<Token![::]> = input.parse()?;
while trailing_punct && input.peek(Ident::peek_any) {
let mut ident = Ident::parse_any(input)?;
if ident.to_string().starts_with("r#") {
if let Some(unraw) = ident.to_string().strip_prefix("r#") {
if !allow_raw {
let msg = format!(
"raw identifier `{}` is not allowed in a quoted namespace",
ident,
"raw identifier `{}` is not allowed in a quoted namespace; use `{}`, or remove quotes",
ident, unraw,
);
return Err(Error::new(ident.span(), msg));
}
ident = ident.unraw();
ident = Ident::new(unraw, ident.span());
}
segments.push(ident);
let colons: Option<Token![::]> = input.parse()?;

View File

@ -1,10 +1,10 @@
error: raw identifier `r#box` is not allowed in a quoted namespace
error: raw identifier `r#box` is not allowed in a quoted namespace; use `box`, or remove quotes
--> tests/ui/raw_ident_namespace.rs:7:24
|
7 | type Id = type_id!("org::r#box::implementation::QuotedRaw");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: raw identifier `r#box` is not allowed in a quoted namespace
error: raw identifier `r#box` is not allowed in a quoted namespace; use `box`, or remove quotes
--> tests/ui/raw_ident_namespace.rs:38:23
|
38 | #[namespace = "org::r#box::implementation"]