mirror of
https://github.com/openharmony/third_party_rust_rust.git
synced 2026-07-19 19:53:38 -04:00
Auto merge of #43224 - jseyfried:fix_macro_idents_regression, r=nrc
macros: fix regression involving identifiers in `macro_rules!` patterns. Fixes #42019. r? @nrc
This commit is contained in:
@@ -196,7 +196,8 @@ fn parse_tree<I>(tree: tokenstream::TokenTree,
|
|||||||
num_captures: name_captures,
|
num_captures: name_captures,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
Some(tokenstream::TokenTree::Token(ident_span, token::Ident(ident))) => {
|
Some(tokenstream::TokenTree::Token(ident_span, ref token)) if token.is_ident() => {
|
||||||
|
let ident = token.ident().unwrap();
|
||||||
let span = Span { lo: span.lo, ..ident_span };
|
let span = Span { lo: span.lo, ..ident_span };
|
||||||
if ident.name == keywords::Crate.name() {
|
if ident.name == keywords::Crate.name() {
|
||||||
let ident = ast::Ident { name: keywords::DollarCrate.name(), ..ident };
|
let ident = ast::Ident { name: keywords::DollarCrate.name(), ..ident };
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
macro_rules! gen {
|
||||||
|
($name:ident ( $($dol:tt $var:ident)* ) $($body:tt)*) => {
|
||||||
|
macro_rules! $name {
|
||||||
|
($($dol $var:ident)*) => {
|
||||||
|
$($body)*
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gen!(m($var) $var);
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let x = 1;
|
||||||
|
assert_eq!(m!(x), 1);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user