Skip to content

Commit

Permalink
libsyntax: Forbid type parameters in tuple indices
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
aochagavia committed Nov 23, 2014
1 parent acfdb14 commit 9a857b4
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/libsyntax/parse/parser.rs
Expand Up @@ -49,8 +49,7 @@ use ast::{PolyTraitRef};
use ast::{QPath, RequiredMethod};
use ast::{Return, BiShl, BiShr, Stmt, StmtDecl};
use ast::{StmtExpr, StmtSemi, StmtMac, StructDef, StructField};
use ast::{StructVariantKind, BiSub};
use ast::StrStyle;
use ast::{StructVariantKind, BiSub, StrStyle};
use ast::{SelfExplicit, SelfRegion, SelfStatic, SelfValue};
use ast::{Delimited, SequenceRepetition, TokenTree, TraitItem, TraitRef};
use ast::{TtDelimited, TtSequence, TtToken};
Expand All @@ -65,10 +64,8 @@ use ast::{UnsafeFn, ViewItem, ViewItem_, ViewItemExternCrate, ViewItemUse};
use ast::{ViewPath, ViewPathGlob, ViewPathList, ViewPathSimple};
use ast::{Visibility, WhereClause, WherePredicate};
use ast;
use ast_util::{as_prec, ident_to_path, operator_prec};
use ast_util;
use codemap::{Span, BytePos, Spanned, spanned, mk_sp};
use codemap;
use ast_util::{mod, as_prec, ident_to_path, operator_prec};
use codemap::{mod, Span, BytePos, Spanned, spanned, mk_sp};
use diagnostic;
use ext::tt::macro_parser;
use parse;
Expand Down Expand Up @@ -2472,24 +2469,19 @@ impl<'a> Parser<'a> {
}
token::Literal(token::Integer(n), suf) => {
let sp = self.span;

// A tuple index may not have a suffix
self.expect_no_suffix(sp, "tuple index", suf);

let index = n.as_str();
let dot = self.last_span.hi;
hi = self.span.hi;
self.bump();
let (_, tys) = if self.eat(&token::ModSep) {
self.expect_lt();
self.parse_generic_values_after_lt()
} else {
(Vec::new(), Vec::new())
};

let num = from_str::<uint>(index);
match num {
let index = from_str::<uint>(n.as_str());
match index {
Some(n) => {
let id = spanned(dot, hi, n);
let field = self.mk_tup_field(e, id, tys);
let field = self.mk_tup_field(e, id, Vec::new());
e = self.mk_expr(lo, hi, field);
}
None => {
Expand Down

0 comments on commit 9a857b4

Please sign in to comment.