diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-01-03 10:48:41 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-03 10:48:41 +0000 |
commit | b47c63a4bcefe93be3e5fe97b2a57489f13da493 (patch) | |
tree | f02b994b580aacd64a3b8172a17fa464a52b4713 /crates/mbe/src/mbe_expander | |
parent | 354c1daedc91abd15ca0ce6ada417053ce45ecfa (diff) | |
parent | 85cc3cfec99a7d232384efae010bfbc8224f1351 (diff) |
Merge #7137
7137: Revert "Proper handling $crate and local_inner_macros" r=jonas-schievink a=jonas-schievink
Reverts rust-analyzer/rust-analyzer#7133
It caused a fairly significant performance regression.
bors r+
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
Diffstat (limited to 'crates/mbe/src/mbe_expander')
-rw-r--r-- | crates/mbe/src/mbe_expander/matcher.rs | 2 | ||||
-rw-r--r-- | crates/mbe/src/mbe_expander/transcriber.rs | 20 |
2 files changed, 15 insertions, 7 deletions
diff --git a/crates/mbe/src/mbe_expander/matcher.rs b/crates/mbe/src/mbe_expander/matcher.rs index 385b46601..ab5f87c48 100644 --- a/crates/mbe/src/mbe_expander/matcher.rs +++ b/crates/mbe/src/mbe_expander/matcher.rs | |||
@@ -150,7 +150,7 @@ fn match_subtree( | |||
150 | res.add_err(err!("leftover tokens")); | 150 | res.add_err(err!("leftover tokens")); |
151 | } | 151 | } |
152 | } | 152 | } |
153 | Op::Var { name, kind, .. } => { | 153 | Op::Var { name, kind } => { |
154 | let kind = match kind { | 154 | let kind = match kind { |
155 | Some(k) => k, | 155 | Some(k) => k, |
156 | None => { | 156 | None => { |
diff --git a/crates/mbe/src/mbe_expander/transcriber.rs b/crates/mbe/src/mbe_expander/transcriber.rs index 57f3f104d..720531237 100644 --- a/crates/mbe/src/mbe_expander/transcriber.rs +++ b/crates/mbe/src/mbe_expander/transcriber.rs | |||
@@ -100,8 +100,8 @@ fn expand_subtree( | |||
100 | err = err.or(e); | 100 | err = err.or(e); |
101 | arena.push(tt.into()); | 101 | arena.push(tt.into()); |
102 | } | 102 | } |
103 | Op::Var { name, id, .. } => { | 103 | Op::Var { name, .. } => { |
104 | let ExpandResult { value: fragment, err: e } = expand_var(ctx, &name, *id); | 104 | let ExpandResult { value: fragment, err: e } = expand_var(ctx, &name); |
105 | err = err.or(e); | 105 | err = err.or(e); |
106 | push_fragment(arena, fragment); | 106 | push_fragment(arena, fragment); |
107 | } | 107 | } |
@@ -118,10 +118,12 @@ fn expand_subtree( | |||
118 | ExpandResult { value: tt::Subtree { delimiter: template.delimiter, token_trees: tts }, err } | 118 | ExpandResult { value: tt::Subtree { delimiter: template.delimiter, token_trees: tts }, err } |
119 | } | 119 | } |
120 | 120 | ||
121 | fn expand_var(ctx: &mut ExpandCtx, v: &SmolStr, id: tt::TokenId) -> ExpandResult<Fragment> { | 121 | fn expand_var(ctx: &mut ExpandCtx, v: &SmolStr) -> ExpandResult<Fragment> { |
122 | if v == "crate" { | 122 | if v == "crate" { |
123 | // We simply produce identifier `$crate` here. And it will be resolved when lowering ast to Path. | 123 | // We simply produce identifier `$crate` here. And it will be resolved when lowering ast to Path. |
124 | let tt = tt::Leaf::from(tt::Ident { text: "$crate".into(), id }).into(); | 124 | let tt = |
125 | tt::Leaf::from(tt::Ident { text: "$crate".into(), id: tt::TokenId::unspecified() }) | ||
126 | .into(); | ||
125 | ExpandResult::ok(Fragment::Tokens(tt)) | 127 | ExpandResult::ok(Fragment::Tokens(tt)) |
126 | } else if !ctx.bindings.contains(v) { | 128 | } else if !ctx.bindings.contains(v) { |
127 | // Note that it is possible to have a `$var` inside a macro which is not bound. | 129 | // 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 | |||
140 | let tt = tt::Subtree { | 142 | let tt = tt::Subtree { |
141 | delimiter: None, | 143 | delimiter: None, |
142 | token_trees: vec![ | 144 | token_trees: vec![ |
143 | tt::Leaf::from(tt::Punct { char: '$', spacing: tt::Spacing::Alone, id }).into(), | 145 | tt::Leaf::from(tt::Punct { |
144 | tt::Leaf::from(tt::Ident { text: v.clone(), id }).into(), | 146 | char: '$', |
147 | spacing: tt::Spacing::Alone, | ||
148 | id: tt::TokenId::unspecified(), | ||
149 | }) | ||
150 | .into(), | ||
151 | tt::Leaf::from(tt::Ident { text: v.clone(), id: tt::TokenId::unspecified() }) | ||
152 | .into(), | ||
145 | ], | 153 | ], |
146 | } | 154 | } |
147 | .into(); | 155 | .into(); |