Skip to content

Commit 4443957

Browse files
committed
Auto merge of #60767 - Centril:rollup-4cbsb73, r=Centril
Rollup of 4 pull requests Successful merges: - #60694 (Fix HIR printing of existential type #60662) - #60750 (syntax: Remove some legacy nonterminal tokens) - #60751 (Assorted cleanup in parser & AST validation) - #60752 (Fix minor typos for ItemLocalId) Failed merges: r? @ghost
2 parents 1764b29 + b381e52 commit 4443957

File tree

9 files changed

+80
-89
lines changed

9 files changed

+80
-89
lines changed

src/librustc/hir/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ mod item_local_id_inner {
126126
use rustc_macros::HashStable;
127127
newtype_index! {
128128
/// An `ItemLocalId` uniquely identifies something within a given "item-like",
129-
/// that is within a hir::Item, hir::TraitItem, or hir::ImplItem. There is no
129+
/// that is, within a hir::Item, hir::TraitItem, or hir::ImplItem. There is no
130130
/// guarantee that the numerical value of a given `ItemLocalId` corresponds to
131131
/// the node's position within the owning item in any way, but there is a
132132
/// guarantee that the `LocalItemId`s within an owner occupy a dense range of
133133
/// integers starting at zero, so a mapping that maps all or most nodes within
134-
/// an "item-like" to something else can be implement by a `Vec` instead of a
134+
/// an "item-like" to something else can be implemented by a `Vec` instead of a
135135
/// tree or hash map.
136136
pub struct ItemLocalId {
137137
derive [HashStable]

src/librustc/hir/print.rs

-1
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,6 @@ impl<'a> State<'a> {
618618

619619
self.print_where_clause(&exist.generics.where_clause)?;
620620
self.s.space()?;
621-
self.word_space(":")?;
622621
let mut real_bounds = Vec::with_capacity(exist.bounds.len());
623622
for b in exist.bounds.iter() {
624623
if let GenericBound::Trait(ref ptr, hir::TraitBoundModifier::Maybe) = *b {

src/librustc_passes/ast_validation.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,21 @@ struct AstValidator<'a> {
5454
has_proc_macro_decls: bool,
5555
has_global_allocator: bool,
5656

57-
// Used to ban nested `impl Trait`, e.g., `impl Into<impl Debug>`.
58-
// Nested `impl Trait` _is_ allowed in associated type position,
59-
// e.g `impl Iterator<Item=impl Debug>`
57+
/// Used to ban nested `impl Trait`, e.g., `impl Into<impl Debug>`.
58+
/// Nested `impl Trait` _is_ allowed in associated type position,
59+
/// e.g `impl Iterator<Item=impl Debug>`
6060
outer_impl_trait: Option<OuterImplTrait>,
6161

62-
// Used to ban `impl Trait` in path projections like `<impl Iterator>::Item`
63-
// or `Foo::Bar<impl Trait>`
62+
/// Used to ban `impl Trait` in path projections like `<impl Iterator>::Item`
63+
/// or `Foo::Bar<impl Trait>`
6464
is_impl_trait_banned: bool,
6565

66-
// rust-lang/rust#57979: the ban of nested `impl Trait` was buggy
67-
// until PRs #57730 and #57981 landed: it would jump directly to
68-
// walk_ty rather than visit_ty (or skip recurring entirely for
69-
// impl trait in projections), and thus miss some cases. We track
70-
// whether we should downgrade to a warning for short-term via
71-
// these booleans.
66+
/// rust-lang/rust#57979: the ban of nested `impl Trait` was buggy
67+
/// until PRs #57730 and #57981 landed: it would jump directly to
68+
/// walk_ty rather than visit_ty (or skip recurring entirely for
69+
/// impl trait in projections), and thus miss some cases. We track
70+
/// whether we should downgrade to a warning for short-term via
71+
/// these booleans.
7272
warning_period_57979_didnt_record_next_impl_trait: bool,
7373
warning_period_57979_impl_trait_in_proj: bool,
7474
}

src/libsyntax/mut_visit.rs

-4
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,6 @@ pub fn noop_visit_interpolated<T: MutVisitor>(nt: &mut token::Nonterminal, vis:
663663
token::NtMeta(meta) => vis.visit_meta_item(meta),
664664
token::NtPath(path) => vis.visit_path(path),
665665
token::NtTT(tt) => vis.visit_tt(tt),
666-
token::NtArm(arm) => vis.visit_arm(arm),
667666
token::NtImplItem(item) =>
668667
visit_clobber(item, |item| {
669668
// See reasoning above.
@@ -676,9 +675,6 @@ pub fn noop_visit_interpolated<T: MutVisitor>(nt: &mut token::Nonterminal, vis:
676675
vis.flat_map_trait_item(item)
677676
.expect_one("expected visitor to produce exactly one item")
678677
}),
679-
token::NtGenerics(generics) => vis.visit_generics(generics),
680-
token::NtWhereClause(where_clause) => vis.visit_where_clause(where_clause),
681-
token::NtArg(arg) => vis.visit_arg(arg),
682678
token::NtVis(visib) => vis.visit_vis(visib),
683679
token::NtForeignItem(item) =>
684680
visit_clobber(item, |item| {

src/libsyntax/parse/parser.rs

+38-57
Original file line numberDiff line numberDiff line change
@@ -1833,7 +1833,7 @@ impl<'a> Parser<'a> {
18331833
Ok(MutTy { ty: t, mutbl: mutbl })
18341834
}
18351835

1836-
fn is_named_argument(&mut self) -> bool {
1836+
fn is_named_argument(&self) -> bool {
18371837
let offset = match self.token {
18381838
token::Interpolated(ref nt) => match **nt {
18391839
token::NtPat(..) => return self.look_ahead(1, |t| t == &token::Colon),
@@ -1881,8 +1881,6 @@ impl<'a> Parser<'a> {
18811881
/// This version of parse arg doesn't necessarily require identifier names.
18821882
fn parse_arg_general(&mut self, require_name: bool, is_trait_item: bool,
18831883
allow_c_variadic: bool) -> PResult<'a, Arg> {
1884-
maybe_whole!(self, NtArg, |x| x);
1885-
18861884
if let Ok(Some(_)) = self.parse_self_arg() {
18871885
let mut err = self.struct_span_err(self.prev_span,
18881886
"unexpected `self` argument in function");
@@ -2345,27 +2343,27 @@ impl<'a> Parser<'a> {
23452343
})
23462344
}
23472345

2348-
fn mk_expr(&mut self, span: Span, node: ExprKind, attrs: ThinVec<Attribute>) -> P<Expr> {
2346+
fn mk_expr(&self, span: Span, node: ExprKind, attrs: ThinVec<Attribute>) -> P<Expr> {
23492347
P(Expr { node, span, attrs, id: ast::DUMMY_NODE_ID })
23502348
}
23512349

2352-
fn mk_unary(&mut self, unop: ast::UnOp, expr: P<Expr>) -> ast::ExprKind {
2350+
fn mk_unary(&self, unop: ast::UnOp, expr: P<Expr>) -> ast::ExprKind {
23532351
ExprKind::Unary(unop, expr)
23542352
}
23552353

2356-
fn mk_binary(&mut self, binop: ast::BinOp, lhs: P<Expr>, rhs: P<Expr>) -> ast::ExprKind {
2354+
fn mk_binary(&self, binop: ast::BinOp, lhs: P<Expr>, rhs: P<Expr>) -> ast::ExprKind {
23572355
ExprKind::Binary(binop, lhs, rhs)
23582356
}
23592357

2360-
fn mk_call(&mut self, f: P<Expr>, args: Vec<P<Expr>>) -> ast::ExprKind {
2358+
fn mk_call(&self, f: P<Expr>, args: Vec<P<Expr>>) -> ast::ExprKind {
23612359
ExprKind::Call(f, args)
23622360
}
23632361

2364-
fn mk_index(&mut self, expr: P<Expr>, idx: P<Expr>) -> ast::ExprKind {
2362+
fn mk_index(&self, expr: P<Expr>, idx: P<Expr>) -> ast::ExprKind {
23652363
ExprKind::Index(expr, idx)
23662364
}
23672365

2368-
fn mk_range(&mut self,
2366+
fn mk_range(&self,
23692367
start: Option<P<Expr>>,
23702368
end: Option<P<Expr>>,
23712369
limits: RangeLimits)
@@ -2377,7 +2375,7 @@ impl<'a> Parser<'a> {
23772375
}
23782376
}
23792377

2380-
fn mk_assign_op(&mut self, binop: ast::BinOp,
2378+
fn mk_assign_op(&self, binop: ast::BinOp,
23812379
lhs: P<Expr>, rhs: P<Expr>) -> ast::ExprKind {
23822380
ExprKind::AssignOp(binop, lhs, rhs)
23832381
}
@@ -2517,13 +2515,12 @@ impl<'a> Parser<'a> {
25172515
hi = path.span;
25182516
return Ok(self.mk_expr(lo.to(hi), ExprKind::Path(Some(qself), path), attrs));
25192517
}
2520-
if self.span.rust_2018() && self.check_keyword(keywords::Async)
2521-
{
2522-
if self.is_async_block() { // check for `async {` and `async move {`
2523-
return self.parse_async_block(attrs);
2518+
if self.span.rust_2018() && self.check_keyword(keywords::Async) {
2519+
return if self.is_async_block() { // check for `async {` and `async move {`
2520+
self.parse_async_block(attrs)
25242521
} else {
2525-
return self.parse_lambda_expr(attrs);
2526-
}
2522+
self.parse_lambda_expr(attrs)
2523+
};
25272524
}
25282525
if self.check_keyword(keywords::Move) || self.check_keyword(keywords::Static) {
25292526
return self.parse_lambda_expr(attrs);
@@ -3448,7 +3445,8 @@ impl<'a> Parser<'a> {
34483445
} else {
34493446
self.restrictions
34503447
};
3451-
if op.precedence() < min_prec {
3448+
let prec = op.precedence();
3449+
if prec < min_prec {
34523450
break;
34533451
}
34543452
// Check for deprecated `...` syntax
@@ -3489,8 +3487,7 @@ impl<'a> Parser<'a> {
34893487
// We have 2 alternatives here: `x..y`/`x..=y` and `x..`/`x..=` The other
34903488
// two variants are handled with `parse_prefix_range_expr` call above.
34913489
let rhs = if self.is_at_start_of_range_notation_rhs() {
3492-
Some(self.parse_assoc_expr_with(op.precedence() + 1,
3493-
LhsExpr::NotYetParsed)?)
3490+
Some(self.parse_assoc_expr_with(prec + 1, LhsExpr::NotYetParsed)?)
34943491
} else {
34953492
None
34963493
};
@@ -3510,28 +3507,18 @@ impl<'a> Parser<'a> {
35103507
break
35113508
}
35123509

3513-
let rhs = match op.fixity() {
3514-
Fixity::Right => self.with_res(
3515-
restrictions - Restrictions::STMT_EXPR,
3516-
|this| {
3517-
this.parse_assoc_expr_with(op.precedence(),
3518-
LhsExpr::NotYetParsed)
3519-
}),
3520-
Fixity::Left => self.with_res(
3521-
restrictions - Restrictions::STMT_EXPR,
3522-
|this| {
3523-
this.parse_assoc_expr_with(op.precedence() + 1,
3524-
LhsExpr::NotYetParsed)
3525-
}),
3510+
let fixity = op.fixity();
3511+
let prec_adjustment = match fixity {
3512+
Fixity::Right => 0,
3513+
Fixity::Left => 1,
35263514
// We currently have no non-associative operators that are not handled above by
35273515
// the special cases. The code is here only for future convenience.
3528-
Fixity::None => self.with_res(
3529-
restrictions - Restrictions::STMT_EXPR,
3530-
|this| {
3531-
this.parse_assoc_expr_with(op.precedence() + 1,
3532-
LhsExpr::NotYetParsed)
3533-
}),
3534-
}?;
3516+
Fixity::None => 1,
3517+
};
3518+
let rhs = self.with_res(
3519+
restrictions - Restrictions::STMT_EXPR,
3520+
|this| this.parse_assoc_expr_with(prec + prec_adjustment, LhsExpr::NotYetParsed)
3521+
)?;
35353522

35363523
// Make sure that the span of the parent node is larger than the span of lhs and rhs,
35373524
// including the attributes.
@@ -3577,7 +3564,7 @@ impl<'a> Parser<'a> {
35773564
}
35783565
};
35793566

3580-
if op.fixity() == Fixity::None { break }
3567+
if let Fixity::None = fixity { break }
35813568
}
35823569
Ok(lhs)
35833570
}
@@ -3714,7 +3701,7 @@ impl<'a> Parser<'a> {
37143701
/// Produce an error if comparison operators are chained (RFC #558).
37153702
/// We only need to check lhs, not rhs, because all comparison ops
37163703
/// have same precedence and are left-associative
3717-
fn check_no_chained_comparison(&mut self, lhs: &Expr, outer_op: &AssocOp) {
3704+
fn check_no_chained_comparison(&self, lhs: &Expr, outer_op: &AssocOp) {
37183705
debug_assert!(outer_op.is_comparison(),
37193706
"check_no_chained_comparison: {:?} is not comparison",
37203707
outer_op);
@@ -4053,8 +4040,6 @@ impl<'a> Parser<'a> {
40534040
}
40544041

40554042
crate fn parse_arm(&mut self) -> PResult<'a, Arm> {
4056-
maybe_whole!(self, NtArm, |x| x);
4057-
40584043
let attrs = self.parse_outer_attributes()?;
40594044
let pats = self.parse_pats()?;
40604045
let guard = if self.eat_keyword(keywords::If) {
@@ -5011,7 +4996,7 @@ impl<'a> Parser<'a> {
50114996
})
50124997
}
50134998

5014-
fn is_async_block(&mut self) -> bool {
4999+
fn is_async_block(&self) -> bool {
50155000
self.token.is_keyword(keywords::Async) &&
50165001
(
50175002
( // `async move {`
@@ -5023,19 +5008,19 @@ impl<'a> Parser<'a> {
50235008
)
50245009
}
50255010

5026-
fn is_async_fn(&mut self) -> bool {
5011+
fn is_async_fn(&self) -> bool {
50275012
self.token.is_keyword(keywords::Async) &&
50285013
self.look_ahead(1, |t| t.is_keyword(keywords::Fn))
50295014
}
50305015

5031-
fn is_do_catch_block(&mut self) -> bool {
5016+
fn is_do_catch_block(&self) -> bool {
50325017
self.token.is_keyword(keywords::Do) &&
50335018
self.look_ahead(1, |t| t.is_keyword(keywords::Catch)) &&
50345019
self.look_ahead(2, |t| *t == token::OpenDelim(token::Brace)) &&
50355020
!self.restrictions.contains(Restrictions::NO_STRUCT_LITERAL)
50365021
}
50375022

5038-
fn is_try_block(&mut self) -> bool {
5023+
fn is_try_block(&self) -> bool {
50395024
self.token.is_keyword(keywords::Try) &&
50405025
self.look_ahead(1, |t| *t == token::OpenDelim(token::Brace)) &&
50415026
self.span.rust_2018() &&
@@ -5057,7 +5042,7 @@ impl<'a> Parser<'a> {
50575042
self.look_ahead(1, |t| t.is_keyword(keywords::Type))
50585043
}
50595044

5060-
fn is_auto_trait_item(&mut self) -> bool {
5045+
fn is_auto_trait_item(&self) -> bool {
50615046
// auto trait
50625047
(self.token.is_keyword(keywords::Auto)
50635048
&& self.look_ahead(1, |t| t.is_keyword(keywords::Trait)))
@@ -5319,7 +5304,7 @@ impl<'a> Parser<'a> {
53195304
}
53205305

53215306
/// Checks if this expression is a successfully parsed statement.
5322-
fn expr_is_complete(&mut self, e: &Expr) -> bool {
5307+
fn expr_is_complete(&self, e: &Expr) -> bool {
53235308
self.restrictions.contains(Restrictions::STMT_EXPR) &&
53245309
!classify::expr_requires_semi_to_be_stmt(e)
53255310
}
@@ -5789,8 +5774,6 @@ impl<'a> Parser<'a> {
57895774
/// | ( < lifetimes , typaramseq ( , )? > )
57905775
/// where typaramseq = ( typaram ) | ( typaram , typaramseq )
57915776
fn parse_generics(&mut self) -> PResult<'a, ast::Generics> {
5792-
maybe_whole!(self, NtGenerics, |x| x);
5793-
57945777
let span_lo = self.span;
57955778
if self.eat_lt() {
57965779
let params = self.parse_generic_params()?;
@@ -6043,8 +6026,6 @@ impl<'a> Parser<'a> {
60436026
/// where T : Trait<U, V> + 'b, 'a : 'b
60446027
/// ```
60456028
fn parse_where_clause(&mut self) -> PResult<'a, WhereClause> {
6046-
maybe_whole!(self, NtWhereClause, |x| x);
6047-
60486029
let mut where_clause = WhereClause {
60496030
id: ast::DUMMY_NODE_ID,
60506031
predicates: Vec::new(),
@@ -6391,7 +6372,7 @@ impl<'a> Parser<'a> {
63916372
Ok((id, generics))
63926373
}
63936374

6394-
fn mk_item(&mut self, span: Span, ident: Ident, node: ItemKind, vis: Visibility,
6375+
fn mk_item(&self, span: Span, ident: Ident, node: ItemKind, vis: Visibility,
63956376
attrs: Vec<Attribute>) -> P<Item> {
63966377
P(Item {
63976378
ident,
@@ -6423,7 +6404,7 @@ impl<'a> Parser<'a> {
64236404

64246405
/// Returns `true` if we are looking at `const ID`
64256406
/// (returns `false` for things like `const fn`, etc.).
6426-
fn is_const_item(&mut self) -> bool {
6407+
fn is_const_item(&self) -> bool {
64276408
self.token.is_keyword(keywords::Const) &&
64286409
!self.look_ahead(1, |t| t.is_keyword(keywords::Fn)) &&
64296410
!self.look_ahead(1, |t| t.is_keyword(keywords::Unsafe))
@@ -6531,7 +6512,7 @@ impl<'a> Parser<'a> {
65316512
})
65326513
}
65336514

6534-
fn complain_if_pub_macro(&mut self, vis: &VisibilityKind, sp: Span) {
6515+
fn complain_if_pub_macro(&self, vis: &VisibilityKind, sp: Span) {
65356516
match *vis {
65366517
VisibilityKind::Inherited => {}
65376518
_ => {
@@ -6560,7 +6541,7 @@ impl<'a> Parser<'a> {
65606541
}
65616542
}
65626543

6563-
fn missing_assoc_item_kind_err(&mut self, item_type: &str, prev_span: Span)
6544+
fn missing_assoc_item_kind_err(&self, item_type: &str, prev_span: Span)
65646545
-> DiagnosticBuilder<'a>
65656546
{
65666547
let expected_kinds = if item_type == "extern" {

src/libsyntax/parse/token.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -597,14 +597,12 @@ pub enum Nonterminal {
597597
NtPath(ast::Path),
598598
NtVis(ast::Visibility),
599599
NtTT(TokenTree),
600-
// These are not exposed to macros, but are used by quasiquote.
601-
NtArm(ast::Arm),
602-
NtImplItem(ast::ImplItem),
600+
// Used only for passing items to proc macro attributes (they are not
601+
// strictly necessary for that, `Annotatable` can be converted into
602+
// tokens directly, but doing that naively regresses pretty-printing).
603603
NtTraitItem(ast::TraitItem),
604+
NtImplItem(ast::ImplItem),
604605
NtForeignItem(ast::ForeignItem),
605-
NtGenerics(ast::Generics),
606-
NtWhereClause(ast::WhereClause),
607-
NtArg(ast::Arg),
608606
}
609607

610608
impl PartialEq for Nonterminal {
@@ -637,13 +635,9 @@ impl fmt::Debug for Nonterminal {
637635
NtMeta(..) => f.pad("NtMeta(..)"),
638636
NtPath(..) => f.pad("NtPath(..)"),
639637
NtTT(..) => f.pad("NtTT(..)"),
640-
NtArm(..) => f.pad("NtArm(..)"),
641638
NtImplItem(..) => f.pad("NtImplItem(..)"),
642639
NtTraitItem(..) => f.pad("NtTraitItem(..)"),
643640
NtForeignItem(..) => f.pad("NtForeignItem(..)"),
644-
NtGenerics(..) => f.pad("NtGenerics(..)"),
645-
NtWhereClause(..) => f.pad("NtWhereClause(..)"),
646-
NtArg(..) => f.pad("NtArg(..)"),
647641
NtVis(..) => f.pad("NtVis(..)"),
648642
NtLifetime(..) => f.pad("NtLifetime(..)"),
649643
}

src/libsyntax/print/pprust.rs

-4
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,8 @@ pub fn nonterminal_to_string(nt: &Nonterminal) -> String {
263263
token::NtLifetime(e) => ident_to_string(e),
264264
token::NtLiteral(ref e) => expr_to_string(e),
265265
token::NtTT(ref tree) => tt_to_string(tree.clone()),
266-
token::NtArm(ref e) => arm_to_string(e),
267266
token::NtImplItem(ref e) => impl_item_to_string(e),
268267
token::NtTraitItem(ref e) => trait_item_to_string(e),
269-
token::NtGenerics(ref e) => generic_params_to_string(&e.params),
270-
token::NtWhereClause(ref e) => where_clause_to_string(e),
271-
token::NtArg(ref e) => arg_to_string(e),
272268
token::NtVis(ref e) => vis_to_string(e),
273269
token::NtForeignItem(ref e) => foreign_item_to_string(e),
274270
}

0 commit comments

Comments
 (0)