Skip to content

Commit df15b6f

Browse files
committed
fix: Fix includes not working with expr fragment inputs
1 parent d32e604 commit df15b6f

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

crates/hir-expand/src/builtin_fn_macro.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use base_db::AnchoredPath;
44
use cfg::CfgExpr;
55
use either::Either;
66
use intern::{sym, Symbol};
7-
use mbe::{parse_exprs_with_sep, parse_to_token_tree};
7+
use mbe::{parse_exprs_with_sep, parse_to_token_tree, DelimiterKind};
88
use span::{Edition, EditionedFileId, Span, SpanAnchor, SyntaxContextId, ROOT_ERASED_FILE_AST_ID};
99
use stdx::format_to;
1010
use syntax::{
@@ -34,15 +34,15 @@ macro_rules! register_builtin {
3434
}
3535

3636
impl BuiltinFnLikeExpander {
37-
pub fn expander(&self) -> fn (&dyn ExpandDatabase, MacroCallId, &tt::Subtree, Span) -> ExpandResult<tt::Subtree> {
37+
fn expander(&self) -> fn (&dyn ExpandDatabase, MacroCallId, &tt::Subtree, Span) -> ExpandResult<tt::Subtree> {
3838
match *self {
3939
$( BuiltinFnLikeExpander::$kind => $expand, )*
4040
}
4141
}
4242
}
4343

4444
impl EagerExpander {
45-
pub fn expander(&self) -> fn (&dyn ExpandDatabase, MacroCallId, &tt::Subtree, Span) -> ExpandResult<tt::Subtree> {
45+
fn expander(&self) -> fn (&dyn ExpandDatabase, MacroCallId, &tt::Subtree, Span) -> ExpandResult<tt::Subtree> {
4646
match *self {
4747
$( EagerExpander::$e_kind => $e_expand, )*
4848
}
@@ -711,6 +711,20 @@ fn parse_string(tt: &tt::Subtree) -> Result<(Symbol, Span), ExpandError> {
711711
kind: tt::LitKind::Str,
712712
suffix: _,
713713
})) => Some((unescape_str(text), *span)),
714+
// FIXME: We wrap expression fragments in parentheses which can break this expectation
715+
// here
716+
// Remove this once we handle none delims correctly
717+
tt::TokenTree::Subtree(t) if t.delimiter.kind == DelimiterKind::Parenthesis => {
718+
t.token_trees.first().and_then(|tt| match tt {
719+
tt::TokenTree::Leaf(tt::Leaf::Literal(tt::Literal {
720+
symbol: text,
721+
span,
722+
kind: tt::LitKind::Str,
723+
suffix: _,
724+
})) => Some((unescape_str(text), *span)),
725+
_ => None,
726+
})
727+
}
714728
_ => None,
715729
})
716730
.ok_or(mbe::ExpandError::ConversionError.into())

crates/hir-expand/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub mod span_map;
2424

2525
mod cfg_process;
2626
mod fixup;
27+
2728
use attrs::collect_attrs;
2829
use rustc_hash::FxHashMap;
2930
use triomphe::Arc;

0 commit comments

Comments
 (0)