Skip to content

Commit 79c3651

Browse files
committed
syntax: Optimize maybe_whole/maybe_whole_expr slightly
1 parent 18229bb commit 79c3651

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/libsyntax/parse/parser.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -118,23 +118,22 @@ enum BlockMode {
118118
/// `token::Interpolated` tokens.
119119
macro_rules! maybe_whole_expr {
120120
($p:expr) => {
121-
if let token::Interpolated(nt) = $p.token.clone() {
122-
match *nt {
123-
token::NtExpr(ref e) | token::NtLiteral(ref e) => {
121+
if let token::Interpolated(nt) = &$p.token {
122+
match &**nt {
123+
token::NtExpr(e) | token::NtLiteral(e) => {
124+
let e = e.clone();
124125
$p.bump();
125-
return Ok((*e).clone());
126+
return Ok(e);
126127
}
127-
token::NtPath(ref path) => {
128+
token::NtPath(path) => {
129+
let path = path.clone();
128130
$p.bump();
129-
let span = $p.span;
130-
let kind = ExprKind::Path(None, (*path).clone());
131-
return Ok($p.mk_expr(span, kind, ThinVec::new()));
131+
return Ok($p.mk_expr($p.span, ExprKind::Path(None, path), ThinVec::new()));
132132
}
133-
token::NtBlock(ref block) => {
133+
token::NtBlock(block) => {
134+
let block = block.clone();
134135
$p.bump();
135-
let span = $p.span;
136-
let kind = ExprKind::Block((*block).clone(), None);
137-
return Ok($p.mk_expr(span, kind, ThinVec::new()));
136+
return Ok($p.mk_expr($p.span, ExprKind::Block(block, None), ThinVec::new()));
138137
}
139138
_ => {},
140139
};
@@ -145,8 +144,9 @@ macro_rules! maybe_whole_expr {
145144
/// As maybe_whole_expr, but for things other than expressions
146145
macro_rules! maybe_whole {
147146
($p:expr, $constructor:ident, |$x:ident| $e:expr) => {
148-
if let token::Interpolated(nt) = $p.token.clone() {
149-
if let token::$constructor($x) = (*nt).clone() {
147+
if let token::Interpolated(nt) = &$p.token {
148+
if let token::$constructor(x) = &**nt {
149+
let $x = x.clone();
150150
$p.bump();
151151
return Ok($e);
152152
}

0 commit comments

Comments
 (0)