Streamline attribute stitching on AST nodes.
It can be done more concisely.
This commit is contained in:
parent
fe647f0538
commit
2eb2ef1684
@ -53,10 +53,9 @@ pub(crate) fn take_for_recovery(self, psess: &ParseSess) -> AttrVec {
|
|||||||
|
|
||||||
/// Prepend `self.attrs` to `attrs`.
|
/// Prepend `self.attrs` to `attrs`.
|
||||||
// FIXME: require passing an NT to prevent misuse of this method
|
// FIXME: require passing an NT to prevent misuse of this method
|
||||||
pub(crate) fn prepend_to_nt_inner(self, attrs: &mut AttrVec) {
|
pub(crate) fn prepend_to_nt_inner(mut self, attrs: &mut AttrVec) {
|
||||||
let mut self_attrs = self.attrs;
|
mem::swap(attrs, &mut self.attrs);
|
||||||
mem::swap(attrs, &mut self_attrs);
|
attrs.extend(self.attrs);
|
||||||
attrs.extend(self_attrs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
|
@ -877,7 +877,7 @@ pub(super) fn parse_expr_dot_or_call_with(
|
|||||||
mut e: P<Expr>,
|
mut e: P<Expr>,
|
||||||
lo: Span,
|
lo: Span,
|
||||||
) -> PResult<'a, P<Expr>> {
|
) -> PResult<'a, P<Expr>> {
|
||||||
let res = ensure_sufficient_stack(|| {
|
let mut res = ensure_sufficient_stack(|| {
|
||||||
loop {
|
loop {
|
||||||
let has_question =
|
let has_question =
|
||||||
if self.prev_token.kind == TokenKind::Ident(kw::Return, IdentIsRaw::No) {
|
if self.prev_token.kind == TokenKind::Ident(kw::Return, IdentIsRaw::No) {
|
||||||
@ -924,17 +924,13 @@ pub(super) fn parse_expr_dot_or_call_with(
|
|||||||
|
|
||||||
// Stitch the list of outer attributes onto the return value. A little
|
// Stitch the list of outer attributes onto the return value. A little
|
||||||
// bit ugly, but the best way given the current code structure.
|
// bit ugly, but the best way given the current code structure.
|
||||||
if attrs.is_empty() {
|
if !attrs.is_empty()
|
||||||
res
|
&& let Ok(expr) = &mut res
|
||||||
} else {
|
{
|
||||||
res.map(|expr| {
|
mem::swap(&mut expr.attrs, &mut attrs);
|
||||||
expr.map(|mut expr| {
|
expr.attrs.extend(attrs)
|
||||||
attrs.extend(expr.attrs);
|
|
||||||
expr.attrs = attrs;
|
|
||||||
expr
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn parse_dot_suffix_expr(
|
pub(super) fn parse_dot_suffix_expr(
|
||||||
|
Loading…
Reference in New Issue
Block a user