From 9a857b4472142b6d0bf65e9185c4c2619e722fb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20Ochagav=C3=ADa?= Date: Sat, 22 Nov 2014 16:02:49 +0100 Subject: [PATCH 1/3] libsyntax: Forbid type parameters in tuple indices This breaks code like ``` let t = (42i, 42i); ... t.0:: ...; ``` Change this code to not contain an unused type parameter. For example: ``` let t = (42i, 42i); ... t.0 ...; ``` Closes https://github.com/rust-lang/rust/issues/19096 [breaking-change] --- src/libsyntax/parse/parser.rs | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index ab0543d64b7fe..e4fa650882029 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -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}; @@ -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; @@ -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::(index); - match num { + let index = from_str::(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 => { From 35316972ff2e7ea02a4583141d3ac69b79610067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20Ochagav=C3=ADa?= Date: Sun, 23 Nov 2014 12:14:35 +0100 Subject: [PATCH 2/3] Remove type parameters from ExprField and ExprTupField --- src/librustc/lint/builtin.rs | 18 +++---- src/librustc/middle/cfg/construct.rs | 4 +- src/librustc/middle/const_eval.rs | 15 +++--- src/librustc/middle/dead.rs | 14 ++--- src/librustc/middle/expr_use_visitor.rs | 8 ++- src/librustc/middle/liveness.rs | 23 ++++---- src/librustc/middle/mem_categorization.rs | 4 +- src/librustc/middle/privacy.rs | 27 ++++------ src/librustc/middle/region.rs | 9 ++-- src/librustc/middle/resolve.rs | 12 ++--- .../middle/typeck/check/method/confirm.rs | 13 ++--- src/librustc/middle/typeck/check/mod.rs | 53 ++++++------------- src/librustc_back/svh.rs | 4 +- src/librustc_trans/save/mod.rs | 26 ++++----- src/librustc_trans/trans/consts.rs | 20 +++---- src/librustc_trans/trans/debuginfo.rs | 12 ++--- src/librustc_trans/trans/expr.rs | 43 ++++----------- src/libsyntax/ast.rs | 4 +- src/libsyntax/ext/build.rs | 4 +- src/libsyntax/fold.rs | 10 ++-- src/libsyntax/parse/parser.rs | 28 ++++------ src/libsyntax/print/pprust.rs | 18 +------ src/libsyntax/visit.rs | 10 +--- 23 files changed, 125 insertions(+), 254 deletions(-) diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 00c68f42c3249..9fe7a21243f18 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -37,22 +37,18 @@ use util::ppaux::{ty_to_string}; use util::nodemap::{FnvHashMap, NodeSet}; use lint::{Context, LintPass, LintArray}; -use std::cmp; +use std::{cmp, slice}; use std::collections::hash_map::{Occupied, Vacant}; use std::num::SignedInt; -use std::slice; use std::{i8, i16, i32, i64, u8, u16, u32, u64, f32, f64}; -use syntax::abi; -use syntax::ast_map; -use syntax::ast_util::is_shift_binop; -use syntax::attr::AttrMetaMethods; -use syntax::attr; +use syntax::{abi, ast, ast_map}; +use syntax::ast_util::{mod, is_shift_binop}; +use syntax::attr::{mod, AttrMetaMethods}; use syntax::codemap::{Span, DUMMY_SP}; use syntax::parse::token; -use syntax::{ast, ast_util, visit}; use syntax::ast::{TyI, TyU, TyI8, TyU8, TyI16, TyU16, TyI32, TyU32, TyI64, TyU64}; use syntax::ptr::P; -use syntax::visit::Visitor; +use syntax::visit::{mod, Visitor}; declare_lint!(WHILE_TRUE, Warn, "suggest using `loop { }` instead of `while true { }`") @@ -1112,8 +1108,8 @@ impl UnusedParens { } ast::ExprUnary(_, ref x) | ast::ExprCast(ref x, _) | - ast::ExprField(ref x, _, _) | - ast::ExprTupField(ref x, _, _) | + ast::ExprField(ref x, _) | + ast::ExprTupField(ref x, _) | ast::ExprIndex(ref x, _) => { // &X { y: 1 }, X { y: 1 }.y contains_exterior_struct_lit(&**x) diff --git a/src/librustc/middle/cfg/construct.rs b/src/librustc/middle/cfg/construct.rs index 42e1ede147e04..61c56cf9ecc51 100644 --- a/src/librustc/middle/cfg/construct.rs +++ b/src/librustc/middle/cfg/construct.rs @@ -475,8 +475,8 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { ast::ExprCast(ref e, _) | ast::ExprUnary(_, ref e) | ast::ExprParen(ref e) | - ast::ExprField(ref e, _, _) | - ast::ExprTupField(ref e, _, _) => { + ast::ExprField(ref e, _) | + ast::ExprTupField(ref e, _) => { self.straightline(expr, pred, Some(&**e).into_iter()) } diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index c7c67e8a67b61..98ac7e413ca7c 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -15,19 +15,16 @@ pub use self::const_val::*; pub use self::constness::*; use metadata::csearch; -use middle::astencode; -use middle::def; +use middle::{astencode, def}; use middle::pat_util::def_to_path; use middle::ty::{mod, Ty}; -use middle::typeck::astconv; -use middle::typeck::check; -use util::nodemap::{DefIdMap}; +use middle::typeck::{astconv, check}; +use util::nodemap::DefIdMap; use syntax::ast::{mod, Expr}; use syntax::parse::token::InternedString; use syntax::ptr::P; -use syntax::visit::Visitor; -use syntax::visit; +use syntax::visit::{mod, Visitor}; use syntax::{ast_map, ast_util, codemap}; use std::rc::Rc; @@ -234,9 +231,9 @@ impl<'a, 'tcx> ConstEvalVisitor<'a, 'tcx> { } } - ast::ExprField(ref base, _, _) => self.classify(&**base), + ast::ExprField(ref base, _) => self.classify(&**base), - ast::ExprTupField(ref base, _, _) => self.classify(&**base), + ast::ExprTupField(ref base, _) => self.classify(&**base), ast::ExprIndex(ref base, ref idx) => join(self.classify(&**base), self.classify(&**idx)), diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 62a5d23e3332c..cf2e9a65859cd 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -12,20 +12,14 @@ // closely. The idea is that all reachable symbols are live, codes called // from live codes are live, and everything else is dead. -use middle::def; -use middle::pat_util; -use middle::privacy; -use middle::ty; -use middle::typeck; +use middle::{def, pat_util, privacy, ty, typeck}; use lint; use util::nodemap::NodeSet; use std::collections::HashSet; -use syntax::ast; -use syntax::ast_map; +use syntax::{ast, ast_map, codemap}; use syntax::ast_util::{local_def, is_local, PostExpansionMethod}; use syntax::attr::{mod, AttrMetaMethods}; -use syntax::codemap; use syntax::visit::{mod, Visitor}; // Any local node that may call something in its body block should be @@ -277,10 +271,10 @@ impl<'a, 'tcx, 'v> Visitor<'v> for MarkSymbolVisitor<'a, 'tcx> { ast::ExprMethodCall(..) => { self.lookup_and_handle_method(expr.id, expr.span); } - ast::ExprField(ref lhs, ref ident, _) => { + ast::ExprField(ref lhs, ref ident) => { self.handle_field_access(&**lhs, &ident.node); } - ast::ExprTupField(ref lhs, idx, _) => { + ast::ExprTupField(ref lhs, idx) => { self.handle_tup_field_access(&**lhs, idx.node); } _ => () diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index 645a1aef3dc73..fa0f59f686049 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -20,11 +20,9 @@ pub use self::ConsumeMode::*; pub use self::MoveReason::*; use self::OverloadedCallType::*; +use middle::{def, region, pat_util}; use middle::mem_categorization as mc; -use middle::def; use middle::mem_categorization::Typer; -use middle::region; -use middle::pat_util; use middle::ty::{mod, Ty}; use middle::typeck::{MethodCall, MethodObject, MethodTraitObject}; use middle::typeck::{MethodOrigin, MethodParam, MethodTypeParam}; @@ -331,11 +329,11 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> { } } - ast::ExprField(ref base, _, _) => { // base.f + ast::ExprField(ref base, _) => { // base.f self.select_from_expr(&**base); } - ast::ExprTupField(ref base, _, _) => { // base. + ast::ExprTupField(ref base, _) => { // base. self.select_from_expr(&**base); } diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 7d13d2e5f9431..15d9e87a9d5a3 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -113,24 +113,19 @@ use self::VarKind::*; use middle::def::*; use middle::mem_categorization::Typer; -use middle::pat_util; -use middle::typeck; -use middle::ty; +use middle::{pat_util, typeck, ty}; use lint; use util::nodemap::NodeMap; -use std::fmt; -use std::io; +use std::{fmt, io, uint}; use std::rc::Rc; -use std::uint; use syntax::ast::{mod, NodeId, Expr}; use syntax::codemap::{BytePos, original_sp, Span}; -use syntax::parse::token::special_idents; -use syntax::parse::token; +use syntax::parse::token::{mod, special_idents}; use syntax::print::pprust::{expr_to_string, block_to_string}; use syntax::ptr::P; -use syntax::{visit, ast_util}; -use syntax::visit::{Visitor, FnKind}; +use syntax::ast_util; +use syntax::visit::{mod, Visitor, FnKind}; /// For use with `propagate_through_loop`. enum LoopKind<'a> { @@ -967,11 +962,11 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { self.access_path(expr, succ, ACC_READ | ACC_USE) } - ast::ExprField(ref e, _, _) => { + ast::ExprField(ref e, _) => { self.propagate_through_expr(&**e, succ) } - ast::ExprTupField(ref e, _, _) => { + ast::ExprTupField(ref e, _) => { self.propagate_through_expr(&**e, succ) } @@ -1295,8 +1290,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { match expr.node { ast::ExprPath(_) => succ, - ast::ExprField(ref e, _, _) => self.propagate_through_expr(&**e, succ), - ast::ExprTupField(ref e, _, _) => self.propagate_through_expr(&**e, succ), + ast::ExprField(ref e, _) => self.propagate_through_expr(&**e, succ), + ast::ExprTupField(ref e, _) => self.propagate_through_expr(&**e, succ), _ => self.propagate_through_expr(expr, succ) } } diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 78b6c19874a9f..e9986e47e4a21 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -477,7 +477,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { Ok(self.cat_deref(expr, base_cmt, 0, false)) } - ast::ExprField(ref base, f_name, _) => { + ast::ExprField(ref base, f_name) => { let base_cmt = if_ok!(self.cat_expr(&**base)); debug!("cat_expr(cat_field): id={} expr={} base={}", expr.id, @@ -486,7 +486,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { Ok(self.cat_field(expr, base_cmt, f_name.node.name, expr_ty)) } - ast::ExprTupField(ref base, idx, _) => { + ast::ExprTupField(ref base, idx) => { let base_cmt = if_ok!(self.cat_expr(&**base)); Ok(self.cat_tup_field(expr, base_cmt, idx.node, expr_ty)) } diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index c2835ba5647e8..66c782877f9ca 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -17,20 +17,17 @@ use self::FieldName::*; use std::mem::replace; use metadata::csearch; -use middle::def; -use middle::resolve; +use middle::{def, resolve}; use middle::ty::{mod, Ty}; use middle::typeck::{MethodCall, MethodMap, MethodOrigin, MethodParam, MethodTypeParam}; use middle::typeck::{MethodStatic, MethodStaticUnboxedClosure, MethodObject, MethodTraitObject}; use util::nodemap::{NodeMap, NodeSet}; -use syntax::ast; -use syntax::ast_map; +use syntax::{ast, ast_map}; use syntax::ast_util::{is_local, local_def, PostExpansionMethod}; use syntax::codemap::Span; use syntax::parse::token; -use syntax::visit; -use syntax::visit::Visitor; +use syntax::visit::{mod, Visitor}; type Context<'a, 'tcx> = (&'a MethodMap<'tcx>, &'a resolve::ExportMap2); @@ -836,20 +833,14 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> { fn visit_expr(&mut self, expr: &ast::Expr) { match expr.node { - ast::ExprField(ref base, ident, _) => { - match ty::expr_ty_adjusted(self.tcx, &**base).sty { - ty::ty_struct(id, _) => { - self.check_field(expr.span, id, NamedField(ident.node)); - } - _ => {} + ast::ExprField(ref base, ident) => { + if let ty::ty_struct(id, _) = ty::expr_ty_adjusted(self.tcx, &**base).sty { + self.check_field(expr.span, id, NamedField(ident.node)); } } - ast::ExprTupField(ref base, idx, _) => { - match ty::expr_ty_adjusted(self.tcx, &**base).sty { - ty::ty_struct(id, _) => { - self.check_field(expr.span, id, UnnamedField(idx.node)); - } - _ => {} + ast::ExprTupField(ref base, idx) => { + if let ty::ty_struct(id, _) = ty::expr_ty_adjusted(self.tcx, &**base).sty { + self.check_field(expr.span, id, UnnamedField(idx.node)); } } ast::ExprMethodCall(ident, _, _) => { diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 8a50cb4ed4e1b..c5511f995bc68 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -22,8 +22,7 @@ Most of the documentation on regions can be found in use session::Session; -use middle::ty::{FreeRegion}; -use middle::ty::{mod, Ty}; +use middle::ty::{mod, Ty, FreeRegion}; use util::nodemap::{FnvHashMap, FnvHashSet, NodeMap}; use util::common::can_reach; @@ -33,7 +32,6 @@ use syntax::codemap::Span; use syntax::{ast, visit}; use syntax::ast::{Block, Item, FnDecl, NodeId, Arm, Pat, Stmt, Expr, Local}; use syntax::ast_util::{stmt_id}; -use syntax::ptr::P; use syntax::visit::{Visitor, FnKind}; /// CodeExtent represents a statically-describable extent that can be @@ -824,11 +822,10 @@ fn resolve_local(visitor: &mut RegionResolutionVisitor, local: &ast::Local) { match expr.node { ast::ExprAddrOf(_, ref subexpr) | ast::ExprUnary(ast::UnDeref, ref subexpr) | - ast::ExprField(ref subexpr, _, _) | - ast::ExprTupField(ref subexpr, _, _) | + ast::ExprField(ref subexpr, _) | + ast::ExprTupField(ref subexpr, _) | ast::ExprIndex(ref subexpr, _) | ast::ExprParen(ref subexpr) => { - let subexpr: &'a P = subexpr; // FIXME(#11586) expr = &**subexpr; } _ => { diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 6ad3d67af0acd..68a31c83ea484 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -71,17 +71,13 @@ use syntax::ast::{Variant, ViewItem, ViewItemExternCrate}; use syntax::ast::{ViewItemUse, ViewPathGlob, ViewPathList, ViewPathSimple}; use syntax::ast::{Visibility}; use syntax::ast; -use syntax::ast_util::{PostExpansionMethod, local_def, walk_pat}; -use syntax::ast_util; +use syntax::ast_util::{mod, PostExpansionMethod, local_def, walk_pat}; use syntax::attr::AttrMetaMethods; use syntax::ext::mtwt; -use syntax::parse::token::special_names; -use syntax::parse::token::special_idents; -use syntax::parse::token; +use syntax::parse::token::{mod, special_names, special_idents}; use syntax::codemap::{Span, DUMMY_SP, Pos}; use syntax::owned_slice::OwnedSlice; -use syntax::visit; -use syntax::visit::Visitor; +use syntax::visit::{mod, Visitor}; use std::collections::{HashMap, HashSet}; use std::collections::hash_map::{Occupied, Vacant}; @@ -5959,7 +5955,7 @@ impl<'a> Resolver<'a> { fn record_candidate_traits_for_expr_if_necessary(&mut self, expr: &Expr) { match expr.node { - ExprField(_, ident, _) => { + ExprField(_, ident) => { // FIXME(#6890): Even though you can't treat a method like a // field, we need to add any trait methods we find that match // the field name so that we can do some nice error reporting diff --git a/src/librustc/middle/typeck/check/method/confirm.rs b/src/librustc/middle/typeck/check/method/confirm.rs index c53befcc10d6b..5bcd96e66efc2 100644 --- a/src/librustc/middle/typeck/check/method/confirm.rs +++ b/src/librustc/middle/typeck/check/method/confirm.rs @@ -10,16 +10,13 @@ use super::probe; -use middle::subst; -use middle::subst::Subst; +use middle::subst::{mod, Subst}; use middle::traits; use middle::ty::{mod, Ty}; -use middle::typeck::check; -use middle::typeck::check::{FnCtxt, NoPreference, PreferMutLvalue}; +use middle::typeck::check::{mod, FnCtxt, NoPreference, PreferMutLvalue}; use middle::typeck::{MethodCall, MethodCallee, MethodObject, MethodOrigin, MethodParam, MethodStatic, MethodTraitObject, MethodTypeParam}; -use middle::typeck::infer; -use middle::typeck::infer::InferCtxt; +use middle::typeck::infer::{mod, InferCtxt}; use middle::ty_fold::HigherRankedFoldable; use syntax::ast; use syntax::codemap::Span; @@ -510,8 +507,8 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> { let last = exprs[exprs.len() - 1]; match last.node { ast::ExprParen(ref expr) | - ast::ExprField(ref expr, _, _) | - ast::ExprTupField(ref expr, _, _) | + ast::ExprField(ref expr, _) | + ast::ExprTupField(ref expr, _) | ast::ExprSlice(ref expr, _, _, _) | ast::ExprIndex(ref expr, _) | ast::ExprUnary(ast::UnDeref, ref expr) => exprs.push(&**expr), diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 85d2f573615b7..d38c5bc0ca9cf 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -83,62 +83,41 @@ use self::IsBinopAssignment::*; use self::TupleArgumentsFlag::*; use session::Session; -use middle::const_eval; -use middle::def; +use middle::{const_eval, def, traits}; use middle::lang_items::IteratorItem; -use middle::mem_categorization::McResult; -use middle::mem_categorization; -use middle::pat_util::pat_id_map; -use middle::pat_util; +use middle::mem_categorization::{mod, McResult}; +use middle::pat_util::{mod, pat_id_map}; use middle::region::CodeExtent; -use middle::subst; -use middle::subst::{Subst, Substs, VecPerParamSpace, ParamSpace}; -use middle::traits; -use middle::ty::{FnSig, VariantInfo}; -use middle::ty::{Polytype}; +use middle::subst::{mod, Subst, Substs, VecPerParamSpace, ParamSpace}; +use middle::ty::{FnSig, VariantInfo, Polytype}; use middle::ty::{Disr, ParamTy, ParameterEnvironment}; use middle::ty::{mod, Ty}; use middle::ty::liberate_late_bound_regions; use middle::ty_fold::TypeFolder; -use middle::typeck::astconv::AstConv; -use middle::typeck::astconv::{ast_region_to_region, ast_ty_to_ty}; -use middle::typeck::astconv; +use middle::typeck::astconv::{mod, ast_region_to_region, ast_ty_to_ty, AstConv}; use middle::typeck::check::_match::pat_ctxt; -use middle::typeck::CrateCtxt; -use middle::typeck::infer; use middle::typeck::rscope::RegionScope; -use middle::typeck::{lookup_def_ccx}; -use middle::typeck::no_params; -use middle::typeck::{require_same_types}; -use middle::typeck::{MethodCall, MethodCallee, MethodMap, ObjectCastMap}; -use middle::typeck::{TypeAndSubsts}; -use middle::typeck; +use middle::typeck::{mod, CrateCtxt, infer, lookup_def_ccx, no_params, require_same_types}; +use middle::typeck::{MethodCall, MethodCallee, MethodMap, ObjectCastMap, TypeAndSubsts}; use middle::lang_items::TypeIdLangItem; use lint; use util::common::{block_query, indenter, loop_query}; -use util::ppaux; -use util::ppaux::{UserString, Repr}; +use util::ppaux::{mod, UserString, Repr}; use util::nodemap::{DefIdMap, FnvHashMap, NodeMap}; use std::cell::{Cell, Ref, RefCell}; use std::collections::hash_map::{Occupied, Vacant}; use std::mem::replace; use std::rc::Rc; -use syntax::abi; -use syntax::ast::{ProvidedMethod, RequiredMethod, TypeTraitItem}; -use syntax::ast; -use syntax::ast_util::{local_def, PostExpansionMethod}; -use syntax::ast_util; -use syntax::attr; -use syntax::codemap::Span; -use syntax::codemap; +use syntax::{mod, abi, attr}; +use syntax::ast::{mod, ProvidedMethod, RequiredMethod, TypeTraitItem}; +use syntax::ast_util::{mod, local_def, PostExpansionMethod}; +use syntax::codemap::{mod, Span}; use syntax::owned_slice::OwnedSlice; use syntax::parse::token; use syntax::print::pprust; use syntax::ptr::P; -use syntax::visit; -use syntax::visit::Visitor; -use syntax; +use syntax::visit::{mod, Visitor}; pub mod _match; pub mod vtable; @@ -4405,10 +4384,10 @@ fn check_expr_with_unifier<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, fcx.require_expr_have_sized_type(expr, traits::StructInitializerSized); } - ast::ExprField(ref base, ref field, _) => { + ast::ExprField(ref base, ref field) => { check_field(fcx, expr, lvalue_pref, &**base, field); } - ast::ExprTupField(ref base, idx, _) => { + ast::ExprTupField(ref base, idx) => { check_tup_field(fcx, expr, lvalue_pref, &**base, idx); } ast::ExprIndex(ref base, ref idx) => { diff --git a/src/librustc_back/svh.rs b/src/librustc_back/svh.rs index cda8a1b1b5f17..549d636e8cb56 100644 --- a/src/librustc_back/svh.rs +++ b/src/librustc_back/svh.rs @@ -278,8 +278,8 @@ mod svh_visitor { ExprBlock(..) => SawExprBlock, ExprAssign(..) => SawExprAssign, ExprAssignOp(op, _, _) => SawExprAssignOp(op), - ExprField(_, id, _) => SawExprField(content(id.node)), - ExprTupField(_, id, _) => SawExprTupField(id.node), + ExprField(_, id) => SawExprField(content(id.node)), + ExprTupField(_, id) => SawExprTupField(id.node), ExprIndex(..) => SawExprIndex, ExprSlice(..) => SawExprSlice, ExprPath(..) => SawExprPath, diff --git a/src/librustc_trans/save/mod.rs b/src/librustc_trans/save/mod.rs index 67ed95f83fd37..ec228c8aa15d1 100644 --- a/src/librustc_trans/save/mod.rs +++ b/src/librustc_trans/save/mod.rs @@ -30,34 +30,26 @@ use driver::driver::CrateAnalysis; use session::Session; -use middle::def; +use middle::{def, typeck}; use middle::ty::{mod, Ty}; -use middle::typeck; use std::cell::Cell; -use std::io; -use std::io::File; -use std::io::fs; +use std::io::{mod, File, fs}; use std::os; -use syntax::ast; -use syntax::ast_util; -use syntax::ast_util::PostExpansionMethod; -use syntax::ast::{NodeId,DefId}; +use syntax::ast_util::{mod, PostExpansionMethod}; +use syntax::ast::{mod, NodeId, DefId}; use syntax::ast_map::NodeItem; use syntax::attr; use syntax::codemap::*; -use syntax::parse::token; -use syntax::parse::token::{get_ident,keywords}; +use syntax::parse::token::{mod, get_ident, keywords}; use syntax::owned_slice::OwnedSlice; -use syntax::visit; -use syntax::visit::Visitor; +use syntax::visit::{mod, Visitor}; use syntax::print::pprust::{path_to_string,ty_to_string}; use syntax::ptr::P; use self::span_utils::SpanUtils; -use self::recorder::Recorder; -use self::recorder::FmtStrs; +use self::recorder::{Recorder, FmtStrs}; use util::ppaux; @@ -1293,7 +1285,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> { ast::ExprStruct(ref path, ref fields, ref base) => self.process_struct_lit(ex, path, fields, base), ast::ExprMethodCall(_, _, ref args) => self.process_method_call(ex, args), - ast::ExprField(ref sub_ex, ident, _) => { + ast::ExprField(ref sub_ex, ident) => { if generated_code(sub_ex.span) { return } @@ -1319,7 +1311,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> { "Expected struct type, but not ty_struct"), } }, - ast::ExprTupField(ref sub_ex, idx, _) => { + ast::ExprTupField(ref sub_ex, idx) => { if generated_code(sub_ex.span) { return } diff --git a/src/librustc_trans/trans/consts.rs b/src/librustc_trans/trans/consts.rs index 4213e9417276c..c7cdf93704949 100644 --- a/src/librustc_trans/trans/consts.rs +++ b/src/librustc_trans/trans/consts.rs @@ -13,22 +13,14 @@ use back::abi; use llvm; use llvm::{ConstFCmp, ConstICmp, SetLinkage, PrivateLinkage, ValueRef, Bool, True, False}; use llvm::{IntEQ, IntNE, IntUGT, IntUGE, IntULT, IntULE, IntSGT, IntSGE, IntSLT, IntSLE, - RealOEQ, RealOGT, RealOGE, RealOLT, RealOLE, RealONE}; + RealOEQ, RealOGT, RealOGE, RealOLT, RealOLE, RealONE}; use metadata::csearch; -use middle::const_eval; -use middle::def; -use trans::adt; -use trans::base; -use trans::base::push_ctxt; -use trans::closure; +use middle::{const_eval, def}; +use trans::{adt, closure, consts, debuginfo, expr, inline, machine}; +use trans::base::{mod, push_ctxt}; use trans::common::*; -use trans::consts; -use trans::expr; -use trans::inline; -use trans::machine; use trans::type_::Type; use trans::type_of; -use trans::debuginfo; use middle::ty::{mod, Ty}; use util::ppaux::{Repr, ty_to_string}; @@ -418,7 +410,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr) -> ValueRef { } } } - ast::ExprField(ref base, field, _) => { + ast::ExprField(ref base, field) => { let (bv, bt) = const_expr(cx, &**base); let brepr = adt::represent_type(cx, bt); expr::with_field_tys(cx.tcx(), bt, None, |discr, field_tys| { @@ -426,7 +418,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr) -> ValueRef { adt::const_get_field(cx, &*brepr, bv, discr, ix) }) } - ast::ExprTupField(ref base, idx, _) => { + ast::ExprTupField(ref base, idx) => { let (bv, bt) = const_expr(cx, &**base); let brepr = adt::represent_type(cx, bt); expr::with_field_tys(cx.tcx(), bt, None, |discr, _| { diff --git a/src/librustc_trans/trans/debuginfo.rs b/src/librustc_trans/trans/debuginfo.rs index 075b6b0dd6e04..a3472e194cf58 100644 --- a/src/librustc_trans/trans/debuginfo.rs +++ b/src/librustc_trans/trans/debuginfo.rs @@ -197,13 +197,10 @@ use llvm::{ModuleRef, ContextRef, ValueRef}; use llvm::debuginfo::*; use metadata::csearch; use middle::subst::{mod, Subst, Substs}; -use trans::adt; +use trans::{mod, adt, machine, type_of}; use trans::common::*; -use trans::machine; use trans::_match::{BindingInfo, TrByCopy, TrByMove, TrByRef}; -use trans::type_of; use trans::type_::Type; -use trans; use middle::ty::{mod, Ty}; use middle::pat_util; use session::config::{mod, FullDebugInfo, LimitedDebugInfo, NoDebugInfo}; @@ -219,8 +216,7 @@ use syntax::util::interner::Interner; use syntax::codemap::{Span, Pos}; use syntax::{ast, codemap, ast_util, ast_map}; use syntax::ast_util::PostExpansionMethod; -use syntax::parse::token; -use syntax::parse::token::special_idents; +use syntax::parse::token::{mod, special_idents}; static DW_LANG_RUST: c_uint = 0x9000; @@ -3456,8 +3452,8 @@ fn populate_scope_map(cx: &CrateContext, ast::ExprCast(ref sub_exp, _) | ast::ExprAddrOf(_, ref sub_exp) | - ast::ExprField(ref sub_exp, _, _) | - ast::ExprTupField(ref sub_exp, _, _) | + ast::ExprField(ref sub_exp, _) | + ast::ExprTupField(ref sub_exp, _) | ast::ExprParen(ref sub_exp) => walk_expr(cx, &**sub_exp, scope_stack, scope_map), diff --git a/src/librustc_trans/trans/expr.rs b/src/librustc_trans/trans/expr.rs index 670e893cc0e53..9e004b137bbe8 100644 --- a/src/librustc_trans/trans/expr.rs +++ b/src/librustc_trans/trans/expr.rs @@ -38,47 +38,26 @@ pub use self::Dest::*; use self::lazy_binop_ty::*; use back::abi; -use llvm; -use llvm::{ValueRef}; +use llvm::{mod, ValueRef}; use middle::def; use middle::mem_categorization::Typer; -use middle::subst; -use middle::subst::Subst; -use trans::_match; -use trans::adt; -use trans::asm; +use middle::subst::{mod, Subst}; +use trans::{_match, adt, asm, base, callee, closure, consts, controlflow}; +use trans::{debuginfo, glue, machine, meth, inline, tvec, type_of}; use trans::base::*; -use trans::base; use trans::build::*; -use trans::callee; -use trans::cleanup; -use trans::cleanup::CleanupMethods; -use trans::closure; +use trans::cleanup::{mod, CleanupMethods}; use trans::common::*; -use trans::consts; -use trans::controlflow; use trans::datum::*; -use trans::debuginfo; -use trans::glue; -use trans::machine; -use trans::meth; -use trans::inline; -use trans::tvec; -use trans::type_of; -use middle::ty::{struct_fields, tup_fields}; -use middle::ty::{AdjustDerefRef, AdjustAddEnv, AutoUnsafe}; -use middle::ty::{AutoPtr}; -use middle::ty::{mod, Ty}; -use middle::typeck; -use middle::typeck::MethodCall; +use middle::ty::{mod, struct_fields, tup_fields}; +use middle::ty::{AdjustDerefRef, AdjustAddEnv, AutoUnsafe, AutoPtr, Ty}; +use middle::typeck::{mod, MethodCall}; use util::common::indenter; use util::ppaux::Repr; use trans::machine::{llsize_of, llsize_of_alloc}; use trans::type_::Type; -use syntax::ast; -use syntax::ast_util; -use syntax::codemap; +use syntax::{ast, ast_util, codemap}; use syntax::print::pprust::{expr_to_string}; use syntax::ptr::P; use std::rc::Rc; @@ -599,10 +578,10 @@ fn trans_datum_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ast::ExprPath(_) => { trans_def(bcx, expr, bcx.def(expr.id)) } - ast::ExprField(ref base, ident, _) => { + ast::ExprField(ref base, ident) => { trans_rec_field(bcx, &**base, ident.node) } - ast::ExprTupField(ref base, idx, _) => { + ast::ExprTupField(ref base, idx) => { trans_rec_tup_field(bcx, &**base, idx.node) } ast::ExprIndex(ref base, ref idx) => { diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 5d4fd2704a2e1..3d33774aa55e1 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -673,8 +673,8 @@ pub enum Expr_ { ExprAssign(P, P), ExprAssignOp(BinOp, P, P), - ExprField(P, SpannedIdent, Vec>), - ExprTupField(P, Spanned, Vec>), + ExprField(P, SpannedIdent), + ExprTupField(P, Spanned), ExprIndex(P, P), ExprSlice(P, Option>, Option>, Mutability), diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index b18a0c8411cb8..2c7f9e889f8b2 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -577,7 +577,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { }; let id = Spanned { node: ident, span: field_span }; - self.expr(sp, ast::ExprField(expr, id, Vec::new())) + self.expr(sp, ast::ExprField(expr, id)) } fn expr_tup_field_access(&self, sp: Span, expr: P, idx: uint) -> P { let field_span = Span { @@ -587,7 +587,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { }; let id = Spanned { node: idx, span: field_span }; - self.expr(sp, ast::ExprTupField(expr, id, Vec::new())) + self.expr(sp, ast::ExprTupField(expr, id)) } fn expr_addr_of(&self, sp: Span, e: P) -> P { self.expr(sp, ast::ExprAddrOf(ast::MutImmutable, e)) diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 1bdf9ea73df2f..6941c0e9c1800 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -1345,15 +1345,13 @@ pub fn noop_fold_expr(Expr {id, node, span}: Expr, folder: &mut T) -> folder.fold_expr(el), folder.fold_expr(er)) } - ExprField(el, ident, tys) => { + ExprField(el, ident) => { ExprField(folder.fold_expr(el), - respan(ident.span, folder.fold_ident(ident.node)), - tys.move_map(|x| folder.fold_ty(x))) + respan(ident.span, folder.fold_ident(ident.node))) } - ExprTupField(el, ident, tys) => { + ExprTupField(el, ident) => { ExprTupField(folder.fold_expr(el), - respan(ident.span, folder.fold_uint(ident.node)), - tys.move_map(|x| folder.fold_ty(x))) + respan(ident.span, folder.fold_uint(ident.node))) } ExprIndex(el, er) => { ExprIndex(folder.fold_expr(el), folder.fold_expr(er)) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index e4fa650882029..a9306c71240ef 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -71,14 +71,11 @@ use ext::tt::macro_parser; use parse; use parse::attr::ParserAttr; use parse::classify; -use parse::common::{SeqSep, seq_sep_none}; -use parse::common::{seq_sep_trailing_allowed}; -use parse::lexer::Reader; -use parse::lexer::TokenAndSpan; +use parse::common::{SeqSep, seq_sep_none, seq_sep_trailing_allowed}; +use parse::lexer::{Reader, TokenAndSpan}; use parse::obsolete::*; -use parse::token::{MatchNt, SubstNt, InternedString}; +use parse::token::{mod, MatchNt, SubstNt, InternedString}; use parse::token::{keywords, special_idents}; -use parse::token; use parse::{new_sub_parser_from_file, ParseSess}; use print::pprust; use ptr::P; @@ -86,7 +83,6 @@ use owned_slice::OwnedSlice; use std::collections::HashSet; use std::io::fs::PathExtensions; -use std::mem::replace; use std::mem; use std::num::Float; use std::rc::Rc; @@ -912,7 +908,7 @@ impl<'a> Parser<'a> { tok: token::Underscore, sp: self.span, }; - replace(&mut self.buffer[buffer_start], placeholder) + mem::replace(&mut self.buffer[buffer_start], placeholder) }; self.span = next.sp; self.token = next.tok; @@ -921,7 +917,7 @@ impl<'a> Parser<'a> { /// Advance the parser by one token and return the bumped token. pub fn bump_and_get(&mut self) -> token::Token { - let old_token = replace(&mut self.token, token::Underscore); + let old_token = mem::replace(&mut self.token, token::Underscore); self.bump(); old_token } @@ -2100,14 +2096,12 @@ impl<'a> Parser<'a> { ExprSlice(expr, start, end, mutbl) } - pub fn mk_field(&mut self, expr: P, ident: ast::SpannedIdent, - tys: Vec>) -> ast::Expr_ { - ExprField(expr, ident, tys) + pub fn mk_field(&mut self, expr: P, ident: ast::SpannedIdent) -> ast::Expr_ { + ExprField(expr, ident) } - pub fn mk_tup_field(&mut self, expr: P, idx: codemap::Spanned, - tys: Vec>) -> ast::Expr_ { - ExprTupField(expr, idx, tys) + pub fn mk_tup_field(&mut self, expr: P, idx: codemap::Spanned) -> ast::Expr_ { + ExprTupField(expr, idx) } pub fn mk_assign_op(&mut self, binop: ast::BinOp, @@ -2462,7 +2456,7 @@ impl<'a> Parser<'a> { } let id = spanned(dot, hi, i); - let field = self.mk_field(e, id, tys); + let field = self.mk_field(e, id); e = self.mk_expr(lo, hi, field); } } @@ -2481,7 +2475,7 @@ impl<'a> Parser<'a> { match index { Some(n) => { let id = spanned(dot, hi, n); - let field = self.mk_tup_field(e, id, Vec::new()); + let field = self.mk_tup_field(e, id); e = self.mk_expr(lo, hi, field); } None => { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 4ce0d74bd37f4..2b80be0bf2a7f 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1734,29 +1734,15 @@ impl<'a> State<'a> { try!(self.word_space("=")); try!(self.print_expr(&**rhs)); } - ast::ExprField(ref expr, id, ref tys) => { + ast::ExprField(ref expr, id) => { try!(self.print_expr(&**expr)); try!(word(&mut self.s, ".")); try!(self.print_ident(id.node)); - if tys.len() > 0u { - try!(word(&mut self.s, "::<")); - try!(self.commasep( - Inconsistent, tys.as_slice(), - |s, ty| s.print_type(&**ty))); - try!(word(&mut self.s, ">")); - } } - ast::ExprTupField(ref expr, id, ref tys) => { + ast::ExprTupField(ref expr, id) => { try!(self.print_expr(&**expr)); try!(word(&mut self.s, ".")); try!(self.print_uint(id.node)); - if tys.len() > 0u { - try!(word(&mut self.s, "::<")); - try!(self.commasep( - Inconsistent, tys.as_slice(), - |s, ty| s.print_type(&**ty))); - try!(word(&mut self.s, ">")); - } } ast::ExprIndex(ref expr, ref index) => { try!(self.print_expr(&**expr)); diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index a0bdd73911308..3f87dbc0740ec 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -838,17 +838,11 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { visitor.visit_expr(&**right_expression); visitor.visit_expr(&**left_expression) } - ExprField(ref subexpression, _, ref types) => { + ExprField(ref subexpression, _) => { visitor.visit_expr(&**subexpression); - for typ in types.iter() { - visitor.visit_ty(&**typ) - } } - ExprTupField(ref subexpression, _, ref types) => { + ExprTupField(ref subexpression, _) => { visitor.visit_expr(&**subexpression); - for typ in types.iter() { - visitor.visit_ty(&**typ) - } } ExprIndex(ref main_expression, ref index_expression) => { visitor.visit_expr(&**main_expression); From 40e1f8f8f1dec2c556e3805c75493752f766274f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20Ochagav=C3=ADa?= Date: Sun, 23 Nov 2014 12:27:10 +0100 Subject: [PATCH 3/3] Add test --- src/test/compile-fail/issue-19096.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/test/compile-fail/issue-19096.rs diff --git a/src/test/compile-fail/issue-19096.rs b/src/test/compile-fail/issue-19096.rs new file mode 100644 index 0000000000000..7f42abb3acca4 --- /dev/null +++ b/src/test/compile-fail/issue-19096.rs @@ -0,0 +1,16 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(tuple_indexing)] + +fn main() { + let t = (42i, 42i); + t.0::; //~ ERROR expected one of `;`, `}`, found `::` +}