Skip to content

Commit

Permalink
Auto merge of rust-lang#17706 - Veykril:fragment-include-fix, r=Veykril
Browse files Browse the repository at this point in the history
fix: Fix includes not working with expr fragment inputs

Temporary workaround for rust-lang/rust-analyzer#17701
  • Loading branch information
bors committed Jul 26, 2024
2 parents d0bd31c + d956450 commit 716c7cc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/tools/rust-analyzer/crates/hir-expand/src/builtin_fn_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use base_db::AnchoredPath;
use cfg::CfgExpr;
use either::Either;
use intern::{sym, Symbol};
use mbe::{parse_exprs_with_sep, parse_to_token_tree};
use mbe::{parse_exprs_with_sep, parse_to_token_tree, DelimiterKind};
use span::{Edition, EditionedFileId, Span, SpanAnchor, SyntaxContextId, ROOT_ERASED_FILE_AST_ID};
use stdx::format_to;
use syntax::{
Expand Down Expand Up @@ -34,15 +34,15 @@ macro_rules! register_builtin {
}

impl BuiltinFnLikeExpander {
pub fn expander(&self) -> fn (&dyn ExpandDatabase, MacroCallId, &tt::Subtree, Span) -> ExpandResult<tt::Subtree> {
fn expander(&self) -> fn (&dyn ExpandDatabase, MacroCallId, &tt::Subtree, Span) -> ExpandResult<tt::Subtree> {
match *self {
$( BuiltinFnLikeExpander::$kind => $expand, )*
}
}
}

impl EagerExpander {
pub fn expander(&self) -> fn (&dyn ExpandDatabase, MacroCallId, &tt::Subtree, Span) -> ExpandResult<tt::Subtree> {
fn expander(&self) -> fn (&dyn ExpandDatabase, MacroCallId, &tt::Subtree, Span) -> ExpandResult<tt::Subtree> {
match *self {
$( EagerExpander::$e_kind => $e_expand, )*
}
Expand Down Expand Up @@ -711,6 +711,20 @@ fn parse_string(tt: &tt::Subtree) -> Result<(Symbol, Span), ExpandError> {
kind: tt::LitKind::Str,
suffix: _,
})) => Some((unescape_str(text), *span)),
// FIXME: We wrap expression fragments in parentheses which can break this expectation
// here
// Remove this once we handle none delims correctly
tt::TokenTree::Subtree(t) if t.delimiter.kind == DelimiterKind::Parenthesis => {
t.token_trees.first().and_then(|tt| match tt {
tt::TokenTree::Leaf(tt::Leaf::Literal(tt::Literal {
symbol: text,
span,
kind: tt::LitKind::Str,
suffix: _,
})) => Some((unescape_str(text), *span)),
_ => None,
})
}
_ => None,
})
.ok_or(mbe::ExpandError::ConversionError.into())
Expand Down
1 change: 1 addition & 0 deletions src/tools/rust-analyzer/crates/hir-expand/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub mod span_map;

mod cfg_process;
mod fixup;

use attrs::collect_attrs;
use rustc_hash::FxHashMap;
use triomphe::Arc;
Expand Down

0 comments on commit 716c7cc

Please sign in to comment.