Skip to content

fix: Fix builtin includes rejecting raw string literals #17741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/hir-def/src/macro_expansion_tests/builtin_fn_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ macro_rules! include_bytes {
($file:expr,) => {{ /* compiler built-in */ }};
}

fn main() { include_bytes("foo"); }
fn main() { include_bytes("foo");include_bytes(r"foo"); }
"#,
expect![[r##"
#[rustc_builtin_macro]
Expand All @@ -448,7 +448,7 @@ macro_rules! include_bytes {
($file:expr,) => {{ /* compiler built-in */ }};
}

fn main() { include_bytes("foo"); }
fn main() { include_bytes("foo");include_bytes(r"foo"); }
"##]],
);
}
Expand Down
12 changes: 12 additions & 0 deletions crates/hir-expand/src/builtin/fn_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,12 @@ fn parse_string(tt: &tt::Subtree) -> Result<(Symbol, Span), ExpandError> {
kind: tt::LitKind::Str,
suffix: _,
})) => Ok((unescape_str(text), *span)),
tt::TokenTree::Leaf(tt::Leaf::Literal(tt::Literal {
symbol: text,
span,
kind: tt::LitKind::StrRaw(_),
suffix: _,
})) => Ok((text.clone(), *span)),
// FIXME: We wrap expression fragments in parentheses which can break this expectation
// here
// Remove this once we handle none delims correctly
Expand All @@ -725,6 +731,12 @@ fn parse_string(tt: &tt::Subtree) -> Result<(Symbol, Span), ExpandError> {
kind: tt::LitKind::Str,
suffix: _,
})) => Some((unescape_str(text), *span)),
tt::TokenTree::Leaf(tt::Leaf::Literal(tt::Literal {
symbol: text,
span,
kind: tt::LitKind::StrRaw(_),
suffix: _,
})) => Some((text.clone(), *span)),
_ => None,
})
}
Expand Down