mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Revert "Proper handling $crate and local_inner_macros"
This commit is contained in:
parent
354c1daedc
commit
85cc3cfec9
7 changed files with 55 additions and 179 deletions
|
@ -150,7 +150,7 @@ fn match_subtree(
|
|||
res.add_err(err!("leftover tokens"));
|
||||
}
|
||||
}
|
||||
Op::Var { name, kind, .. } => {
|
||||
Op::Var { name, kind } => {
|
||||
let kind = match kind {
|
||||
Some(k) => k,
|
||||
None => {
|
||||
|
|
|
@ -100,8 +100,8 @@ fn expand_subtree(
|
|||
err = err.or(e);
|
||||
arena.push(tt.into());
|
||||
}
|
||||
Op::Var { name, id, .. } => {
|
||||
let ExpandResult { value: fragment, err: e } = expand_var(ctx, &name, *id);
|
||||
Op::Var { name, .. } => {
|
||||
let ExpandResult { value: fragment, err: e } = expand_var(ctx, &name);
|
||||
err = err.or(e);
|
||||
push_fragment(arena, fragment);
|
||||
}
|
||||
|
@ -118,10 +118,12 @@ fn expand_subtree(
|
|||
ExpandResult { value: tt::Subtree { delimiter: template.delimiter, token_trees: tts }, err }
|
||||
}
|
||||
|
||||
fn expand_var(ctx: &mut ExpandCtx, v: &SmolStr, id: tt::TokenId) -> ExpandResult<Fragment> {
|
||||
fn expand_var(ctx: &mut ExpandCtx, v: &SmolStr) -> ExpandResult<Fragment> {
|
||||
if v == "crate" {
|
||||
// We simply produce identifier `$crate` here. And it will be resolved when lowering ast to Path.
|
||||
let tt = tt::Leaf::from(tt::Ident { text: "$crate".into(), id }).into();
|
||||
let tt =
|
||||
tt::Leaf::from(tt::Ident { text: "$crate".into(), id: tt::TokenId::unspecified() })
|
||||
.into();
|
||||
ExpandResult::ok(Fragment::Tokens(tt))
|
||||
} else if !ctx.bindings.contains(v) {
|
||||
// Note that it is possible to have a `$var` inside a macro which is not bound.
|
||||
|
@ -140,8 +142,14 @@ fn expand_var(ctx: &mut ExpandCtx, v: &SmolStr, id: tt::TokenId) -> ExpandResult
|
|||
let tt = tt::Subtree {
|
||||
delimiter: None,
|
||||
token_trees: vec![
|
||||
tt::Leaf::from(tt::Punct { char: '$', spacing: tt::Spacing::Alone, id }).into(),
|
||||
tt::Leaf::from(tt::Ident { text: v.clone(), id }).into(),
|
||||
tt::Leaf::from(tt::Punct {
|
||||
char: '$',
|
||||
spacing: tt::Spacing::Alone,
|
||||
id: tt::TokenId::unspecified(),
|
||||
})
|
||||
.into(),
|
||||
tt::Leaf::from(tt::Ident { text: v.clone(), id: tt::TokenId::unspecified() })
|
||||
.into(),
|
||||
],
|
||||
}
|
||||
.into();
|
||||
|
|
|
@ -8,7 +8,7 @@ use crate::{tt_iter::TtIter, ExpandError, MetaTemplate};
|
|||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub(crate) enum Op {
|
||||
Var { name: SmolStr, kind: Option<SmolStr>, id: tt::TokenId },
|
||||
Var { name: SmolStr, kind: Option<SmolStr> },
|
||||
Repeat { subtree: MetaTemplate, kind: RepeatKind, separator: Option<Separator> },
|
||||
Leaf(tt::Leaf),
|
||||
Subtree(MetaTemplate),
|
||||
|
@ -106,21 +106,18 @@ fn next_op<'a>(first: &tt::TokenTree, src: &mut TtIter<'a>, mode: Mode) -> Resul
|
|||
}
|
||||
let name = UNDERSCORE.clone();
|
||||
let kind = eat_fragment_kind(src, mode)?;
|
||||
let id = punct.id;
|
||||
Op::Var { name, kind, id }
|
||||
Op::Var { name, kind }
|
||||
}
|
||||
tt::Leaf::Ident(ident) => {
|
||||
let name = ident.text.clone();
|
||||
let kind = eat_fragment_kind(src, mode)?;
|
||||
let id = ident.id;
|
||||
Op::Var { name, kind, id }
|
||||
Op::Var { name, kind }
|
||||
}
|
||||
tt::Leaf::Literal(lit) => {
|
||||
if is_boolean_literal(&lit) {
|
||||
let name = lit.text.clone();
|
||||
let kind = eat_fragment_kind(src, mode)?;
|
||||
let id = lit.id;
|
||||
Op::Var { name, kind, id }
|
||||
Op::Var { name, kind }
|
||||
} else {
|
||||
bail!("bad var 2");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue