Skip to content

Commit

Permalink
syntax::parse: don't depend on syntax::ext
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Oct 16, 2019
1 parent 7ec38a9 commit d160a4e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/libsyntax/parse/parser/expr.rs
Expand Up @@ -1946,4 +1946,8 @@ impl<'a> Parser<'a> {
crate fn mk_expr(&self, span: Span, kind: ExprKind, attrs: ThinVec<Attribute>) -> P<Expr> {
P(Expr { kind, span, attrs, id: DUMMY_NODE_ID })
}

pub(super) fn mk_expr_err(&self, span: Span) -> P<Expr> {
self.mk_expr(span, ExprKind::Err, ThinVec::new())
}
}
3 changes: 1 addition & 2 deletions src/libsyntax/parse/parser/item.rs
Expand Up @@ -9,7 +9,6 @@ use crate::ast::{PathSegment, IsAuto, Constness, IsAsync, Unsafety, Defaultness}
use crate::ast::{Visibility, VisibilityKind, Mutability, FnHeader, ForeignItem, ForeignItemKind};
use crate::ast::{Ty, TyKind, Generics, GenericBounds, TraitRef, EnumDef, VariantData, StructField};
use crate::ast::{Mac, MacDelimiter, Block, BindingMode, FnDecl, MethodSig, SelfKind, Param};
use crate::ext::base::DummyResult;
use crate::parse::token;
use crate::parse::parser::maybe_append;
use crate::tokenstream::{TokenTree, TokenStream};
Expand Down Expand Up @@ -606,7 +605,7 @@ impl<'a> Parser<'a> {
let ty_second = if self.token == token::DotDot {
// We need to report this error after `cfg` expansion for compatibility reasons
self.bump(); // `..`, do not add it to expected tokens
Some(DummyResult::raw_ty(self.prev_span, true))
Some(self.mk_ty(self.prev_span, TyKind::Err))
} else if has_for || self.token.can_begin_type() {
Some(self.parse_ty()?)
} else {
Expand Down
5 changes: 2 additions & 3 deletions src/libsyntax/parse/parser/stmt.rs
Expand Up @@ -8,7 +8,6 @@ use crate::ptr::P;
use crate::{maybe_whole, ThinVec};
use crate::ast::{self, DUMMY_NODE_ID, Stmt, StmtKind, Local, Block, BlockCheckMode, Expr, ExprKind};
use crate::ast::{Attribute, AttrStyle, VisibilityKind, MacStmtStyle, Mac, MacDelimiter};
use crate::ext::base::DummyResult;
use crate::parse::{classify, DirectoryOwnership};
use crate::parse::token;
use crate::source_map::{respan, Span};
Expand Down Expand Up @@ -400,7 +399,7 @@ impl<'a> Parser<'a> {
self.recover_stmt_(SemiColonMode::Ignore, BlockMode::Ignore);
Some(Stmt {
id: DUMMY_NODE_ID,
kind: StmtKind::Expr(DummyResult::raw_expr(self.token.span, true)),
kind: StmtKind::Expr(self.mk_expr_err(self.token.span)),
span: self.token.span,
})
}
Expand Down Expand Up @@ -443,7 +442,7 @@ impl<'a> Parser<'a> {
self.recover_stmt();
// Don't complain about type errors in body tail after parse error (#57383).
let sp = expr.span.to(self.prev_span);
stmt.kind = StmtKind::Expr(DummyResult::raw_expr(sp, true));
stmt.kind = StmtKind::Expr(self.mk_expr_err(sp));
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/libsyntax/parse/parser/ty.rs
Expand Up @@ -210,7 +210,7 @@ impl<'a> Parser<'a> {
};

let span = lo.to(self.prev_span);
let ty = P(Ty { kind, span, id: ast::DUMMY_NODE_ID });
let ty = self.mk_ty(span, kind);

// Try to recover from use of `+` with incorrect priority.
self.maybe_report_ambiguous_plus(allow_plus, impl_dyn_multi, &ty);
Expand Down Expand Up @@ -448,4 +448,8 @@ impl<'a> Parser<'a> {
self.span_bug(self.token.span, "not a lifetime")
}
}

pub(super) fn mk_ty(&self, span: Span, kind: TyKind) -> P<Ty> {
P(Ty { kind, span, id: ast::DUMMY_NODE_ID })
}
}

0 comments on commit d160a4e

Please sign in to comment.