Skip to content

Commit c4dd066

Browse files
committed
Auto merge of #33864 - Manishearth:breaking-batch, r=Manishearth
Batch up libsyntax breaking changes cc #31645
2 parents d5759a3 + 2b73335 commit c4dd066

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1143
-666
lines changed

Diff for: src/doc/reference.md

+2
Original file line numberDiff line numberDiff line change
@@ -2433,6 +2433,8 @@ The currently implemented features of the reference compiler are:
24332433
* - `abi_vectorcall` - Allows the usage of the vectorcall calling convention
24342434
(e.g. `extern "vectorcall" func fn_();`)
24352435

2436+
* - `dotdot_in_tuple_patterns` - Allows `..` in tuple (struct) patterns.
2437+
24362438
If a feature is promoted to a language feature, then all existing programs will
24372439
start to receive compilation warnings about `#![feature]` directives which enabled
24382440
the new feature (because the directive is no longer necessary). However, if a

Diff for: src/librustc/cfg/construct.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
100100
fn pat(&mut self, pat: &hir::Pat, pred: CFGIndex) -> CFGIndex {
101101
match pat.node {
102102
PatKind::Ident(_, _, None) |
103-
PatKind::TupleStruct(_, None) |
104103
PatKind::Path(..) |
105104
PatKind::QPath(..) |
106105
PatKind::Lit(..) |
@@ -116,8 +115,8 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
116115
self.add_ast_node(pat.id, &[subpat_exit])
117116
}
118117

119-
PatKind::TupleStruct(_, Some(ref subpats)) |
120-
PatKind::Tup(ref subpats) => {
118+
PatKind::TupleStruct(_, ref subpats, _) |
119+
PatKind::Tuple(ref subpats, _) => {
121120
let pats_exit = self.pats_all(subpats.iter(), pred);
122121
self.add_ast_node(pat.id, &[pats_exit])
123122
}

Diff for: src/librustc/hir/fold.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -923,9 +923,9 @@ pub fn noop_fold_pat<T: Folder>(p: P<Pat>, folder: &mut T) -> P<Pat> {
923923
sub.map(|x| folder.fold_pat(x)))
924924
}
925925
PatKind::Lit(e) => PatKind::Lit(folder.fold_expr(e)),
926-
PatKind::TupleStruct(pth, pats) => {
926+
PatKind::TupleStruct(pth, pats, ddpos) => {
927927
PatKind::TupleStruct(folder.fold_path(pth),
928-
pats.map(|pats| pats.move_map(|x| folder.fold_pat(x))))
928+
pats.move_map(|x| folder.fold_pat(x)), ddpos)
929929
}
930930
PatKind::Path(pth) => {
931931
PatKind::Path(folder.fold_path(pth))
@@ -948,7 +948,9 @@ pub fn noop_fold_pat<T: Folder>(p: P<Pat>, folder: &mut T) -> P<Pat> {
948948
});
949949
PatKind::Struct(pth, fs, etc)
950950
}
951-
PatKind::Tup(elts) => PatKind::Tup(elts.move_map(|x| folder.fold_pat(x))),
951+
PatKind::Tuple(elts, ddpos) => {
952+
PatKind::Tuple(elts.move_map(|x| folder.fold_pat(x)), ddpos)
953+
}
952954
PatKind::Box(inner) => PatKind::Box(folder.fold_pat(inner)),
953955
PatKind::Ref(inner, mutbl) => PatKind::Ref(folder.fold_pat(inner), mutbl),
954956
PatKind::Range(e1, e2) => {
@@ -1009,11 +1011,15 @@ pub fn noop_fold_expr<T: Folder>(Expr { id, node, span, attrs }: Expr, folder: &
10091011
ExprWhile(cond, body, opt_name) => {
10101012
ExprWhile(folder.fold_expr(cond),
10111013
folder.fold_block(body),
1012-
opt_name.map(|i| folder.fold_name(i)))
1014+
opt_name.map(|label| {
1015+
respan(folder.new_span(label.span), folder.fold_name(label.node))
1016+
}))
10131017
}
10141018
ExprLoop(body, opt_name) => {
10151019
ExprLoop(folder.fold_block(body),
1016-
opt_name.map(|i| folder.fold_name(i)))
1020+
opt_name.map(|label| {
1021+
respan(folder.new_span(label.span), folder.fold_name(label.node))
1022+
}))
10171023
}
10181024
ExprMatch(expr, arms, source) => {
10191025
ExprMatch(folder.fold_expr(expr),

Diff for: src/librustc/hir/intravisit.rs

+16-14
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
use syntax::abi::Abi;
2929
use syntax::ast::{NodeId, CRATE_NODE_ID, Name, Attribute};
3030
use syntax::attr::ThinAttributesExt;
31-
use syntax::codemap::Span;
31+
use syntax::codemap::{Span, Spanned};
3232
use hir::*;
3333

3434
use std::cmp;
@@ -203,11 +203,17 @@ pub trait Visitor<'v> : Sized {
203203
}
204204

205205
pub fn walk_opt_name<'v, V: Visitor<'v>>(visitor: &mut V, span: Span, opt_name: Option<Name>) {
206-
for name in opt_name {
206+
if let Some(name) = opt_name {
207207
visitor.visit_name(span, name);
208208
}
209209
}
210210

211+
pub fn walk_opt_sp_name<'v, V: Visitor<'v>>(visitor: &mut V, opt_sp_name: &Option<Spanned<Name>>) {
212+
if let Some(ref sp_name) = *opt_sp_name {
213+
visitor.visit_name(sp_name.span, sp_name.node);
214+
}
215+
}
216+
211217
/// Walks the contents of a crate. See also `Crate::visit_all_items`.
212218
pub fn walk_crate<'v, V: Visitor<'v>>(visitor: &mut V, krate: &'v Crate) {
213219
visitor.visit_mod(&krate.module, krate.span, CRATE_NODE_ID);
@@ -454,11 +460,9 @@ pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>(visitor: &mut V,
454460

455461
pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
456462
match pattern.node {
457-
PatKind::TupleStruct(ref path, ref opt_children) => {
463+
PatKind::TupleStruct(ref path, ref children, _) => {
458464
visitor.visit_path(path, pattern.id);
459-
if let Some(ref children) = *opt_children {
460-
walk_list!(visitor, visit_pat, children);
461-
}
465+
walk_list!(visitor, visit_pat, children);
462466
}
463467
PatKind::Path(ref path) => {
464468
visitor.visit_path(path, pattern.id);
@@ -474,7 +478,7 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
474478
visitor.visit_pat(&field.node.pat)
475479
}
476480
}
477-
PatKind::Tup(ref tuple_elements) => {
481+
PatKind::Tuple(ref tuple_elements, _) => {
478482
walk_list!(visitor, visit_pat, tuple_elements);
479483
}
480484
PatKind::Box(ref subpattern) |
@@ -737,14 +741,14 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
737741
visitor.visit_block(if_block);
738742
walk_list!(visitor, visit_expr, optional_else);
739743
}
740-
ExprWhile(ref subexpression, ref block, opt_name) => {
744+
ExprWhile(ref subexpression, ref block, ref opt_sp_name) => {
741745
visitor.visit_expr(subexpression);
742746
visitor.visit_block(block);
743-
walk_opt_name(visitor, expression.span, opt_name)
747+
walk_opt_sp_name(visitor, opt_sp_name);
744748
}
745-
ExprLoop(ref block, opt_name) => {
749+
ExprLoop(ref block, ref opt_sp_name) => {
746750
visitor.visit_block(block);
747-
walk_opt_name(visitor, expression.span, opt_name)
751+
walk_opt_sp_name(visitor, opt_sp_name);
748752
}
749753
ExprMatch(ref subexpression, ref arms, _) => {
750754
visitor.visit_expr(subexpression);
@@ -784,9 +788,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
784788
visitor.visit_path(path, expression.id)
785789
}
786790
ExprBreak(ref opt_sp_name) | ExprAgain(ref opt_sp_name) => {
787-
for sp_name in opt_sp_name {
788-
visitor.visit_name(sp_name.span, sp_name.node);
789-
}
791+
walk_opt_sp_name(visitor, opt_sp_name);
790792
}
791793
ExprRet(ref optional_expression) => {
792794
walk_list!(visitor, visit_expr, optional_expression);

Diff for: src/librustc/hir/lowering.rs

+29-31
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ impl<'a> LoweringContext<'a> {
192192
}
193193
}
194194

195+
fn lower_opt_sp_ident(&mut self, o_id: Option<Spanned<Ident>>) -> Option<Spanned<Name>> {
196+
o_id.map(|sp_ident| respan(sp_ident.span, self.lower_ident(sp_ident.node)))
197+
}
198+
195199
fn lower_attrs(&mut self, attrs: &Vec<Attribute>) -> hir::HirVec<Attribute> {
196200
attrs.clone().into()
197201
}
@@ -269,7 +273,7 @@ impl<'a> LoweringContext<'a> {
269273
P(hir::Ty {
270274
id: t.id,
271275
node: match t.node {
272-
Infer => hir::TyInfer,
276+
Infer | ImplicitSelf => hir::TyInfer,
273277
Vec(ref ty) => hir::TyVec(self.lower_ty(ty)),
274278
Ptr(ref mt) => hir::TyPtr(self.lower_mt(mt)),
275279
Rptr(ref region, ref mt) => {
@@ -787,23 +791,24 @@ impl<'a> LoweringContext<'a> {
787791
}
788792

789793
fn lower_method_sig(&mut self, sig: &MethodSig) -> hir::MethodSig {
790-
// Check for `self: _` and `self: &_`
791-
if let SelfKind::Explicit(ref ty, _) = sig.explicit_self.node {
792-
match sig.decl.inputs.get(0).and_then(Arg::to_self).map(|eself| eself.node) {
793-
Some(SelfKind::Value(..)) | Some(SelfKind::Region(..)) => {
794-
self.id_assigner.diagnostic().span_err(ty.span,
795-
"the type placeholder `_` is not allowed within types on item signatures");
796-
}
797-
_ => {}
798-
}
799-
}
800-
hir::MethodSig {
794+
let hir_sig = hir::MethodSig {
801795
generics: self.lower_generics(&sig.generics),
802796
abi: sig.abi,
803797
unsafety: self.lower_unsafety(sig.unsafety),
804798
constness: self.lower_constness(sig.constness),
805799
decl: self.lower_fn_decl(&sig.decl),
800+
};
801+
// Check for `self: _` and `self: &_`
802+
if let Some(SelfKind::Explicit(..)) = sig.decl.get_self().map(|eself| eself.node) {
803+
match hir_sig.decl.get_self().map(|eself| eself.node) {
804+
Some(hir::SelfKind::Value(..)) | Some(hir::SelfKind::Region(..)) => {
805+
self.id_assigner.diagnostic().span_err(sig.decl.inputs[0].ty.span,
806+
"the type placeholder `_` is not allowed within types on item signatures");
807+
}
808+
_ => {}
809+
}
806810
}
811+
hir_sig
807812
}
808813

809814
fn lower_unsafety(&mut self, u: Unsafety) -> hir::Unsafety {
@@ -872,10 +877,10 @@ impl<'a> LoweringContext<'a> {
872877
})
873878
}
874879
PatKind::Lit(ref e) => hir::PatKind::Lit(self.lower_expr(e)),
875-
PatKind::TupleStruct(ref pth, ref pats) => {
880+
PatKind::TupleStruct(ref pth, ref pats, ddpos) => {
876881
hir::PatKind::TupleStruct(self.lower_path(pth),
877-
pats.as_ref()
878-
.map(|pats| pats.iter().map(|x| self.lower_pat(x)).collect()))
882+
pats.iter().map(|x| self.lower_pat(x)).collect(),
883+
ddpos)
879884
}
880885
PatKind::Path(ref pth) => {
881886
hir::PatKind::Path(self.lower_path(pth))
@@ -903,8 +908,8 @@ impl<'a> LoweringContext<'a> {
903908
.collect();
904909
hir::PatKind::Struct(pth, fs, etc)
905910
}
906-
PatKind::Tup(ref elts) => {
907-
hir::PatKind::Tup(elts.iter().map(|x| self.lower_pat(x)).collect())
911+
PatKind::Tuple(ref elts, ddpos) => {
912+
hir::PatKind::Tuple(elts.iter().map(|x| self.lower_pat(x)).collect(), ddpos)
908913
}
909914
PatKind::Box(ref inner) => hir::PatKind::Box(self.lower_pat(inner)),
910915
PatKind::Ref(ref inner, mutbl) => {
@@ -1122,11 +1127,10 @@ impl<'a> LoweringContext<'a> {
11221127
}
11231128
ExprKind::While(ref cond, ref body, opt_ident) => {
11241129
hir::ExprWhile(self.lower_expr(cond), self.lower_block(body),
1125-
opt_ident.map(|ident| self.lower_ident(ident)))
1130+
self.lower_opt_sp_ident(opt_ident))
11261131
}
11271132
ExprKind::Loop(ref body, opt_ident) => {
1128-
hir::ExprLoop(self.lower_block(body),
1129-
opt_ident.map(|ident| self.lower_ident(ident)))
1133+
hir::ExprLoop(self.lower_block(body), self.lower_opt_sp_ident(opt_ident))
11301134
}
11311135
ExprKind::Match(ref expr, ref arms) => {
11321136
hir::ExprMatch(self.lower_expr(expr),
@@ -1243,12 +1247,8 @@ impl<'a> LoweringContext<'a> {
12431247
};
12441248
hir::ExprPath(hir_qself, self.lower_path_full(path, rename))
12451249
}
1246-
ExprKind::Break(opt_ident) => hir::ExprBreak(opt_ident.map(|sp_ident| {
1247-
respan(sp_ident.span, self.lower_ident(sp_ident.node))
1248-
})),
1249-
ExprKind::Again(opt_ident) => hir::ExprAgain(opt_ident.map(|sp_ident| {
1250-
respan(sp_ident.span, self.lower_ident(sp_ident.node))
1251-
})),
1250+
ExprKind::Break(opt_ident) => hir::ExprBreak(self.lower_opt_sp_ident(opt_ident)),
1251+
ExprKind::Again(opt_ident) => hir::ExprAgain(self.lower_opt_sp_ident(opt_ident)),
12521252
ExprKind::Ret(ref e) => hir::ExprRet(e.as_ref().map(|x| self.lower_expr(x))),
12531253
ExprKind::InlineAsm(InlineAsm {
12541254
ref inputs,
@@ -1422,8 +1422,7 @@ impl<'a> LoweringContext<'a> {
14221422

14231423
// `[opt_ident]: loop { ... }`
14241424
let loop_block = self.block_expr(match_expr);
1425-
let loop_expr = hir::ExprLoop(loop_block,
1426-
opt_ident.map(|ident| self.lower_ident(ident)));
1425+
let loop_expr = hir::ExprLoop(loop_block, self.lower_opt_sp_ident(opt_ident));
14271426
// add attributes to the outer returned expr node
14281427
let attrs = e.attrs.clone();
14291428
return P(hir::Expr { id: e.id, node: loop_expr, span: e.span, attrs: attrs });
@@ -1503,8 +1502,7 @@ impl<'a> LoweringContext<'a> {
15031502

15041503
// `[opt_ident]: loop { ... }`
15051504
let loop_block = self.block_expr(match_expr);
1506-
let loop_expr = hir::ExprLoop(loop_block,
1507-
opt_ident.map(|ident| self.lower_ident(ident)));
1505+
let loop_expr = hir::ExprLoop(loop_block, self.lower_opt_sp_ident(opt_ident));
15081506
let loop_expr =
15091507
P(hir::Expr { id: e.id, node: loop_expr, span: e.span, attrs: None });
15101508

@@ -1857,7 +1855,7 @@ impl<'a> LoweringContext<'a> {
18571855
let pt = if subpats.is_empty() {
18581856
hir::PatKind::Path(path)
18591857
} else {
1860-
hir::PatKind::TupleStruct(path, Some(subpats))
1858+
hir::PatKind::TupleStruct(path, subpats, None)
18611859
};
18621860
let pat = self.pat(span, pt);
18631861
self.resolver.record_resolution(pat.id, def);

Diff for: src/librustc/hir/mod.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ impl Pat {
470470
PatKind::Struct(_, ref fields, _) => {
471471
fields.iter().all(|field| field.node.pat.walk_(it))
472472
}
473-
PatKind::TupleStruct(_, Some(ref s)) | PatKind::Tup(ref s) => {
473+
PatKind::TupleStruct(_, ref s, _) | PatKind::Tuple(ref s, _) => {
474474
s.iter().all(|p| p.walk_(it))
475475
}
476476
PatKind::Box(ref s) | PatKind::Ref(ref s, _) => {
@@ -485,7 +485,6 @@ impl Pat {
485485
PatKind::Lit(_) |
486486
PatKind::Range(_, _) |
487487
PatKind::Ident(_, _, _) |
488-
PatKind::TupleStruct(..) |
489488
PatKind::Path(..) |
490489
PatKind::QPath(_, _) => {
491490
true
@@ -539,9 +538,10 @@ pub enum PatKind {
539538
/// The `bool` is `true` in the presence of a `..`.
540539
Struct(Path, HirVec<Spanned<FieldPat>>, bool),
541540

542-
/// A tuple struct/variant pattern `Variant(x, y, z)`.
543-
/// "None" means a `Variant(..)` pattern where we don't bind the fields to names.
544-
TupleStruct(Path, Option<HirVec<P<Pat>>>),
541+
/// A tuple struct/variant pattern `Variant(x, y, .., z)`.
542+
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
543+
/// 0 <= position <= subpats.len()
544+
TupleStruct(Path, HirVec<P<Pat>>, Option<usize>),
545545

546546
/// A path pattern.
547547
/// Such pattern can be resolved to a unit struct/variant or a constant.
@@ -553,8 +553,10 @@ pub enum PatKind {
553553
/// PatKind::Path, and the resolver will have to sort that out.
554554
QPath(QSelf, Path),
555555

556-
/// A tuple pattern `(a, b)`
557-
Tup(HirVec<P<Pat>>),
556+
/// A tuple pattern `(a, b)`.
557+
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
558+
/// 0 <= position <= subpats.len()
559+
Tuple(HirVec<P<Pat>>, Option<usize>),
558560
/// A `box` pattern
559561
Box(P<Pat>),
560562
/// A reference pattern, e.g. `&mut (a, b)`
@@ -873,11 +875,11 @@ pub enum Expr_ {
873875
/// A while loop, with an optional label
874876
///
875877
/// `'label: while expr { block }`
876-
ExprWhile(P<Expr>, P<Block>, Option<Name>),
878+
ExprWhile(P<Expr>, P<Block>, Option<Spanned<Name>>),
877879
/// Conditionless loop (can be exited with break, continue, or return)
878880
///
879881
/// `'label: loop { block }`
880-
ExprLoop(P<Block>, Option<Name>),
882+
ExprLoop(P<Block>, Option<Spanned<Name>>),
881883
/// A `match` block, with a source that indicates whether or not it is
882884
/// the result of a desugaring, and if so, which kind.
883885
ExprMatch(P<Expr>, HirVec<Arm>, MatchSource),
@@ -1175,6 +1177,9 @@ pub struct FnDecl {
11751177
}
11761178

11771179
impl FnDecl {
1180+
pub fn get_self(&self) -> Option<ExplicitSelf> {
1181+
self.inputs.get(0).and_then(Arg::to_self)
1182+
}
11781183
pub fn has_self(&self) -> bool {
11791184
self.inputs.get(0).map(Arg::is_self).unwrap_or(false)
11801185
}

0 commit comments

Comments
 (0)