aboutsummaryrefslogtreecommitdiff
path: root/crates/mbe/src/parser.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-01-02 17:42:45 +0000
committerGitHub <[email protected]>2021-01-02 17:42:45 +0000
commita88d4f8c7216105e8bffed55fe85d9de796dc172 (patch)
treeda8fe6fd5f771181ee1753907af22d9c0ce60586 /crates/mbe/src/parser.rs
parent510abef5da1427c542e7b37dcea805c7b022984c (diff)
parent3545289603dae852fb2b99181e9be5e3117b0a2e (diff)
Merge #7133
7133: Proper handling $crate and local_inner_macros r=jonas-schievink a=edwin0cheng This PR introduces `HygineFrames` to store the macro definition/call site hierarchy in hyginee and when resolving `local_inner_macros` and `$crate`, we use the token to look up the corresponding frame and return the correct value. See also: https://rustc-dev-guide.rust-lang.org/macro-expansion.html#hygiene-and-hierarchies fixe #6890 and #6788 r? @jonas-schievink Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/mbe/src/parser.rs')
-rw-r--r--crates/mbe/src/parser.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/crates/mbe/src/parser.rs b/crates/mbe/src/parser.rs
index 2f3ebc831..77cc739b6 100644
--- a/crates/mbe/src/parser.rs
+++ b/crates/mbe/src/parser.rs
@@ -8,7 +8,7 @@ use crate::{tt_iter::TtIter, ExpandError, MetaTemplate};
8 8
9#[derive(Clone, Debug, PartialEq, Eq)] 9#[derive(Clone, Debug, PartialEq, Eq)]
10pub(crate) enum Op { 10pub(crate) enum Op {
11 Var { name: SmolStr, kind: Option<SmolStr> }, 11 Var { name: SmolStr, kind: Option<SmolStr>, id: tt::TokenId },
12 Repeat { subtree: MetaTemplate, kind: RepeatKind, separator: Option<Separator> }, 12 Repeat { subtree: MetaTemplate, kind: RepeatKind, separator: Option<Separator> },
13 Leaf(tt::Leaf), 13 Leaf(tt::Leaf),
14 Subtree(MetaTemplate), 14 Subtree(MetaTemplate),
@@ -106,18 +106,21 @@ fn next_op<'a>(first: &tt::TokenTree, src: &mut TtIter<'a>, mode: Mode) -> Resul
106 } 106 }
107 let name = UNDERSCORE.clone(); 107 let name = UNDERSCORE.clone();
108 let kind = eat_fragment_kind(src, mode)?; 108 let kind = eat_fragment_kind(src, mode)?;
109 Op::Var { name, kind } 109 let id = punct.id;
110 Op::Var { name, kind, id }
110 } 111 }
111 tt::Leaf::Ident(ident) => { 112 tt::Leaf::Ident(ident) => {
112 let name = ident.text.clone(); 113 let name = ident.text.clone();
113 let kind = eat_fragment_kind(src, mode)?; 114 let kind = eat_fragment_kind(src, mode)?;
114 Op::Var { name, kind } 115 let id = ident.id;
116 Op::Var { name, kind, id }
115 } 117 }
116 tt::Leaf::Literal(lit) => { 118 tt::Leaf::Literal(lit) => {
117 if is_boolean_literal(&lit) { 119 if is_boolean_literal(&lit) {
118 let name = lit.text.clone(); 120 let name = lit.text.clone();
119 let kind = eat_fragment_kind(src, mode)?; 121 let kind = eat_fragment_kind(src, mode)?;
120 Op::Var { name, kind } 122 let id = lit.id;
123 Op::Var { name, kind, id }
121 } else { 124 } else {
122 bail!("bad var 2"); 125 bail!("bad var 2");
123 } 126 }