Skip to content

libsyntax: Forbid type parameters in tuple indices #19211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 23, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 { }`")
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/cfg/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down
15 changes: 6 additions & 9 deletions src/librustc/middle/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)),
Expand Down
14 changes: 4 additions & 10 deletions src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
_ => ()
Expand Down
8 changes: 3 additions & 5 deletions src/librustc/middle/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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.<n>
ast::ExprTupField(ref base, _) => { // base.<n>
self.select_from_expr(&**base);
}

Expand Down
23 changes: 9 additions & 14 deletions src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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))
}
Expand Down
27 changes: 9 additions & 18 deletions src/librustc/middle/privacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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, _, _) => {
Expand Down
9 changes: 3 additions & 6 deletions src/librustc/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down Expand Up @@ -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<Expr> = subexpr; // FIXME(#11586)
expr = &**subexpr;
}
_ => {
Expand Down
12 changes: 4 additions & 8 deletions src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand Down
13 changes: 5 additions & 8 deletions src/librustc/middle/typeck/check/method/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down
Loading