Fix perf regression by correctly matching keywords
This commit is contained in:
parent
e702534763
commit
e2a28165a3
2 changed files with 22 additions and 10 deletions
|
@ -222,7 +222,8 @@ impl<'a> Parser<'a> {
|
||||||
self.parse_use_item()?
|
self.parse_use_item()?
|
||||||
} else if self.check_fn_front_matter(def_final, case) {
|
} else if self.check_fn_front_matter(def_final, case) {
|
||||||
// FUNCTION ITEM
|
// FUNCTION ITEM
|
||||||
let (ident, sig, generics, body) = self.parse_fn(attrs, fn_parse_mode, lo, vis)?;
|
let (ident, sig, generics, body) =
|
||||||
|
self.parse_fn(attrs, fn_parse_mode, lo, vis, case)?;
|
||||||
(ident, ItemKind::Fn(Box::new(Fn { defaultness: def_(), sig, generics, body })))
|
(ident, ItemKind::Fn(Box::new(Fn { defaultness: def_(), sig, generics, body })))
|
||||||
} else if self.eat_keyword(kw::Extern) {
|
} else if self.eat_keyword(kw::Extern) {
|
||||||
if self.eat_keyword(kw::Crate) {
|
if self.eat_keyword(kw::Crate) {
|
||||||
|
@ -1792,7 +1793,13 @@ impl<'a> Parser<'a> {
|
||||||
};
|
};
|
||||||
// We use `parse_fn` to get a span for the function
|
// We use `parse_fn` to get a span for the function
|
||||||
let fn_parse_mode = FnParseMode { req_name: |_| true, req_body: true };
|
let fn_parse_mode = FnParseMode { req_name: |_| true, req_body: true };
|
||||||
match self.parse_fn(&mut AttrVec::new(), fn_parse_mode, lo, &inherited_vis) {
|
match self.parse_fn(
|
||||||
|
&mut AttrVec::new(),
|
||||||
|
fn_parse_mode,
|
||||||
|
lo,
|
||||||
|
&inherited_vis,
|
||||||
|
Case::Insensitive,
|
||||||
|
) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
let mut err = self.struct_span_err(
|
let mut err = self.struct_span_err(
|
||||||
lo.to(self.prev_token.span),
|
lo.to(self.prev_token.span),
|
||||||
|
@ -2116,8 +2123,9 @@ impl<'a> Parser<'a> {
|
||||||
fn_parse_mode: FnParseMode,
|
fn_parse_mode: FnParseMode,
|
||||||
sig_lo: Span,
|
sig_lo: Span,
|
||||||
vis: &Visibility,
|
vis: &Visibility,
|
||||||
|
case: Case,
|
||||||
) -> PResult<'a, (Ident, FnSig, Generics, Option<P<Block>>)> {
|
) -> PResult<'a, (Ident, FnSig, Generics, Option<P<Block>>)> {
|
||||||
let header = self.parse_fn_front_matter(vis)?; // `const ... fn`
|
let header = self.parse_fn_front_matter(vis, case)?; // `const ... fn`
|
||||||
let ident = self.parse_ident()?; // `foo`
|
let ident = self.parse_ident()?; // `foo`
|
||||||
let mut generics = self.parse_generics()?; // `<'a, T, ...>`
|
let mut generics = self.parse_generics()?; // `<'a, T, ...>`
|
||||||
let decl =
|
let decl =
|
||||||
|
@ -2241,24 +2249,28 @@ impl<'a> Parser<'a> {
|
||||||
///
|
///
|
||||||
/// `vis` represents the visibility that was already parsed, if any. Use
|
/// `vis` represents the visibility that was already parsed, if any. Use
|
||||||
/// `Visibility::Inherited` when no visibility is known.
|
/// `Visibility::Inherited` when no visibility is known.
|
||||||
pub(super) fn parse_fn_front_matter(&mut self, orig_vis: &Visibility) -> PResult<'a, FnHeader> {
|
pub(super) fn parse_fn_front_matter(
|
||||||
|
&mut self,
|
||||||
|
orig_vis: &Visibility,
|
||||||
|
case: Case,
|
||||||
|
) -> PResult<'a, FnHeader> {
|
||||||
let sp_start = self.token.span;
|
let sp_start = self.token.span;
|
||||||
let constness = self.parse_constness(Case::Insensitive);
|
let constness = self.parse_constness(case);
|
||||||
|
|
||||||
let async_start_sp = self.token.span;
|
let async_start_sp = self.token.span;
|
||||||
let asyncness = self.parse_asyncness(Case::Insensitive);
|
let asyncness = self.parse_asyncness(case);
|
||||||
|
|
||||||
let unsafe_start_sp = self.token.span;
|
let unsafe_start_sp = self.token.span;
|
||||||
let unsafety = self.parse_unsafety(Case::Insensitive);
|
let unsafety = self.parse_unsafety(case);
|
||||||
|
|
||||||
let ext_start_sp = self.token.span;
|
let ext_start_sp = self.token.span;
|
||||||
let ext = self.parse_extern(Case::Insensitive);
|
let ext = self.parse_extern(case);
|
||||||
|
|
||||||
if let Async::Yes { span, .. } = asyncness {
|
if let Async::Yes { span, .. } = asyncness {
|
||||||
self.ban_async_in_2015(span);
|
self.ban_async_in_2015(span);
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.eat_keyword_case(kw::Fn, Case::Insensitive) {
|
if !self.eat_keyword_case(kw::Fn, case) {
|
||||||
// It is possible for `expect_one_of` to recover given the contents of
|
// It is possible for `expect_one_of` to recover given the contents of
|
||||||
// `self.expected_tokens`, therefore, do not use `self.unexpected()` which doesn't
|
// `self.expected_tokens`, therefore, do not use `self.unexpected()` which doesn't
|
||||||
// account for this.
|
// account for this.
|
||||||
|
|
|
@ -536,7 +536,7 @@ impl<'a> Parser<'a> {
|
||||||
};
|
};
|
||||||
let span_start = self.token.span;
|
let span_start = self.token.span;
|
||||||
let ast::FnHeader { ext, unsafety, constness, asyncness } =
|
let ast::FnHeader { ext, unsafety, constness, asyncness } =
|
||||||
self.parse_fn_front_matter(&inherited_vis)?;
|
self.parse_fn_front_matter(&inherited_vis, Case::Sensitive)?;
|
||||||
if self.may_recover() && self.token.kind == TokenKind::Lt {
|
if self.may_recover() && self.token.kind == TokenKind::Lt {
|
||||||
self.recover_fn_ptr_with_generics(lo, &mut params, param_insertion_point)?;
|
self.recover_fn_ptr_with_generics(lo, &mut params, param_insertion_point)?;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue