Skip to content

Commit 9a857b4

Browse files
committed
libsyntax: Forbid type parameters in tuple indices
This breaks code like ``` let t = (42i, 42i); ... t.0::<int> ...; ``` Change this code to not contain an unused type parameter. For example: ``` let t = (42i, 42i); ... t.0 ...; ``` Closes #19096 [breaking-change]
1 parent acfdb14 commit 9a857b4

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ use ast::{PolyTraitRef};
4949
use ast::{QPath, RequiredMethod};
5050
use ast::{Return, BiShl, BiShr, Stmt, StmtDecl};
5151
use ast::{StmtExpr, StmtSemi, StmtMac, StructDef, StructField};
52-
use ast::{StructVariantKind, BiSub};
53-
use ast::StrStyle;
52+
use ast::{StructVariantKind, BiSub, StrStyle};
5453
use ast::{SelfExplicit, SelfRegion, SelfStatic, SelfValue};
5554
use ast::{Delimited, SequenceRepetition, TokenTree, TraitItem, TraitRef};
5655
use ast::{TtDelimited, TtSequence, TtToken};
@@ -65,10 +64,8 @@ use ast::{UnsafeFn, ViewItem, ViewItem_, ViewItemExternCrate, ViewItemUse};
6564
use ast::{ViewPath, ViewPathGlob, ViewPathList, ViewPathSimple};
6665
use ast::{Visibility, WhereClause, WherePredicate};
6766
use ast;
68-
use ast_util::{as_prec, ident_to_path, operator_prec};
69-
use ast_util;
70-
use codemap::{Span, BytePos, Spanned, spanned, mk_sp};
71-
use codemap;
67+
use ast_util::{mod, as_prec, ident_to_path, operator_prec};
68+
use codemap::{mod, Span, BytePos, Spanned, spanned, mk_sp};
7269
use diagnostic;
7370
use ext::tt::macro_parser;
7471
use parse;
@@ -2472,24 +2469,19 @@ impl<'a> Parser<'a> {
24722469
}
24732470
token::Literal(token::Integer(n), suf) => {
24742471
let sp = self.span;
2472+
2473+
// A tuple index may not have a suffix
24752474
self.expect_no_suffix(sp, "tuple index", suf);
24762475

2477-
let index = n.as_str();
24782476
let dot = self.last_span.hi;
24792477
hi = self.span.hi;
24802478
self.bump();
2481-
let (_, tys) = if self.eat(&token::ModSep) {
2482-
self.expect_lt();
2483-
self.parse_generic_values_after_lt()
2484-
} else {
2485-
(Vec::new(), Vec::new())
2486-
};
24872479

2488-
let num = from_str::<uint>(index);
2489-
match num {
2480+
let index = from_str::<uint>(n.as_str());
2481+
match index {
24902482
Some(n) => {
24912483
let id = spanned(dot, hi, n);
2492-
let field = self.mk_tup_field(e, id, tys);
2484+
let field = self.mk_tup_field(e, id, Vec::new());
24932485
e = self.mk_expr(lo, hi, field);
24942486
}
24952487
None => {

0 commit comments

Comments
 (0)