Skip to content

Commit d5ece88

Browse files
committed
fix raw string issue in diagnostics macro
1 parent 1a3dc67 commit d5ece88

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Diff for: compiler/rustc_macros/src/diagnostics/utils.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,14 @@ pub(crate) fn new_code_ident() -> syn::Ident {
3030
}
3131

3232
pub(crate) fn convert_to_litstr(lit: &proc_macro2::Literal) -> LitStr {
33-
let lit_content = format!("{}", lit);
34-
LitStr::new(&lit_content[1..lit_content.len() - 1], lit.span())
33+
let s = format!("{}", lit);
34+
let s = if s.starts_with("r#\"") && s.ends_with("\"#") && s.len() >= 5 {
35+
s[3..s.len() - 2].to_string()
36+
} else {
37+
s[1..s.len() - 1].to_string()
38+
};
39+
40+
LitStr::new(&s, lit.span())
3541
}
3642

3743
/// Checks whether the type name of `ty` matches `name`.

Diff for: compiler/rustc_parse/src/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ pub(crate) struct ExpectedEqForLetExpr {
498498
}
499499

500500
#[derive(Diagnostic)]
501-
#[diag(label = r#"expected `{"{"}`, found {$first_tok}"#)]
501+
#[diag(r#"expected `{"{"}`, found {$first_tok}"#)]
502502
pub(crate) struct ExpectedElseBlock {
503503
#[primary_span]
504504
pub first_tok_span: Span,

0 commit comments

Comments
 (0)