Skip to content

Commit ad200af

Browse files
authored
Rollup merge of rust-lang#69587 - petrochenkov:reqname, r=Centril
rustc_parse: Tweak the function parameter name check The function doesn't need a full token, only its edition. Noticed while implementing rust-lang#69384. I'm still not sure whether normalized or unnormalized token is a better fit for the edition check here, so rust-lang#69384 and this PR just keep the status quo behavior. r? @Centril
2 parents cf48ca6 + 65a666c commit ad200af

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/librustc_parse/parser/item.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::maybe_whole;
66

77
use rustc_ast_pretty::pprust;
88
use rustc_errors::{struct_span_err, Applicability, PResult, StashKey};
9+
use rustc_span::edition::Edition;
910
use rustc_span::source_map::{self, Span};
1011
use rustc_span::symbol::{kw, sym, Symbol};
1112
use syntax::ast::{self, AttrStyle, AttrVec, Attribute, Ident, DUMMY_NODE_ID};
@@ -636,7 +637,7 @@ impl<'a> Parser<'a> {
636637
}
637638

638639
pub fn parse_trait_item(&mut self) -> PResult<'a, Option<Option<P<AssocItem>>>> {
639-
self.parse_assoc_item(|t| t.span.rust_2018())
640+
self.parse_assoc_item(|edition| edition >= Edition::Edition2018)
640641
}
641642

642643
/// Parses associated items.
@@ -1380,7 +1381,7 @@ impl<'a> Parser<'a> {
13801381
/// The parsing configuration used to parse a parameter list (see `parse_fn_params`).
13811382
///
13821383
/// The function decides if, per-parameter `p`, `p` must have a pattern or just a type.
1383-
type ReqName = fn(&token::Token) -> bool;
1384+
type ReqName = fn(Edition) -> bool;
13841385

13851386
/// Parsing of functions and methods.
13861387
impl<'a> Parser<'a> {
@@ -1536,7 +1537,7 @@ impl<'a> Parser<'a> {
15361537

15371538
let is_name_required = match self.token.kind {
15381539
token::DotDotDot => false,
1539-
_ => req_name(&self.normalized_token),
1540+
_ => req_name(self.normalized_token.span.edition()),
15401541
};
15411542
let (pat, ty) = if is_name_required || self.is_named_param() {
15421543
debug!("parse_param_general parse_pat (is_name_required:{})", is_name_required);

0 commit comments

Comments
 (0)