Skip to content

Commit

Permalink
fix raw string issue in diagnostics macro
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Nov 19, 2023
1 parent 1a3dc67 commit d5ece88
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions compiler/rustc_macros/src/diagnostics/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@ pub(crate) fn new_code_ident() -> syn::Ident {
}

pub(crate) fn convert_to_litstr(lit: &proc_macro2::Literal) -> LitStr {
let lit_content = format!("{}", lit);
LitStr::new(&lit_content[1..lit_content.len() - 1], lit.span())
let s = format!("{}", lit);
let s = if s.starts_with("r#\"") && s.ends_with("\"#") && s.len() >= 5 {
s[3..s.len() - 2].to_string()
} else {
s[1..s.len() - 1].to_string()
};

LitStr::new(&s, lit.span())
}

/// Checks whether the type name of `ty` matches `name`.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ pub(crate) struct ExpectedEqForLetExpr {
}

#[derive(Diagnostic)]
#[diag(label = r#"expected `{"{"}`, found {$first_tok}"#)]
#[diag(r#"expected `{"{"}`, found {$first_tok}"#)]
pub(crate) struct ExpectedElseBlock {
#[primary_span]
pub first_tok_span: Span,
Expand Down

0 comments on commit d5ece88

Please sign in to comment.