Skip to content

Commit

Permalink
Implement <T>::method UFCS expression syntax.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Feb 24, 2015
1 parent fdfb532 commit d31b9eb
Show file tree
Hide file tree
Showing 40 changed files with 286 additions and 200 deletions.
6 changes: 3 additions & 3 deletions src/librustc/lint/builtin.rs
Expand Up @@ -437,7 +437,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {

impl<'a, 'tcx, 'v> Visitor<'v> for ImproperCTypesVisitor<'a, 'tcx> {
fn visit_ty(&mut self, ty: &ast::Ty) {
if let ast::TyPath(_) = ty.node {
if let ast::TyPath(..) = ty.node {
self.check_def(ty.span, ty.id);
}
visit::walk_ty(self, ty);
Expand Down Expand Up @@ -682,8 +682,8 @@ impl LintPass for PathStatements {
match s.node {
ast::StmtSemi(ref expr, _) => {
match expr.node {
ast::ExprPath(_) => cx.span_lint(PATH_STATEMENTS, s.span,
"path statement with no effect"),
ast::ExprPath(..) => cx.span_lint(PATH_STATEMENTS, s.span,
"path statement with no effect"),
_ => ()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/encoder.rs
Expand Up @@ -1221,7 +1221,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_unsafety(rbml_w, unsafety);
encode_polarity(rbml_w, polarity);
match ty.node {
ast::TyPath(ref path) if path.segments.len() == 1 => {
ast::TyPath(None, ref path) if path.segments.len() == 1 => {
let ident = path.segments.last().unwrap().identifier;
encode_impl_type_basename(rbml_w, ident);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/astconv_util.rs
Expand Up @@ -59,7 +59,7 @@ pub fn prim_ty_to_ty<'tcx>(tcx: &ty::ctxt<'tcx>,

pub fn ast_ty_to_prim_ty<'tcx>(tcx: &ty::ctxt<'tcx>, ast_ty: &ast::Ty)
-> Option<Ty<'tcx>> {
if let ast::TyPath(ref path) = ast_ty.node {
if let ast::TyPath(None, ref path) = ast_ty.node {
let def = match tcx.def_map.borrow().get(&ast_ty.id) {
None => {
tcx.sess.span_bug(ast_ty.span,
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/cfg/construct.rs
Expand Up @@ -398,8 +398,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
ast::ExprMac(..) |
ast::ExprClosure(..) |
ast::ExprLit(..) |
ast::ExprPath(..) |
ast::ExprQPath(..) => {
ast::ExprPath(..) => {
self.straightline(expr, pred, None::<ast::Expr>.iter())
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/check_const.rs
Expand Up @@ -439,7 +439,7 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
}
}
}
ast::ExprPath(_) | ast::ExprQPath(_) => {
ast::ExprPath(..) => {
let def = v.tcx.def_map.borrow().get(&e.id).map(|d| d.full_def());
match def {
Some(def::DefVariant(_, _, _)) => {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/check_static_recursion.rs
Expand Up @@ -93,8 +93,8 @@ impl<'a, 'ast, 'v> Visitor<'v> for CheckItemRecursionVisitor<'a, 'ast> {

fn visit_expr(&mut self, e: &ast::Expr) {
match e.node {
ast::ExprPath(_) | ast::ExprQPath(_) => {
match self.def_map.borrow().get(&e.id).map(|d| d.full_def()) {
ast::ExprPath(..) => {
match self.def_map.borrow().get(&e.id).map(|d| d.base_def) {
Some(DefStatic(def_id, _)) |
Some(DefConst(def_id)) if
ast_util::is_local(def_id) => {
Expand Down
11 changes: 2 additions & 9 deletions src/librustc/middle/const_eval.rs
Expand Up @@ -178,7 +178,7 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr, span: Span) -> P<ast::Pat>
ast::PatVec(pats, None, vec![])
}

ast::ExprPath(ref path) => {
ast::ExprPath(_, ref path) => {
let opt_def = tcx.def_map.borrow().get(&expr.id).map(|d| d.full_def());
match opt_def {
Some(def::DefStruct(..)) =>
Expand All @@ -194,13 +194,6 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr, span: Span) -> P<ast::Pat>
}
}

ast::ExprQPath(_) => {
match lookup_const(tcx, expr) {
Some(actual) => return const_expr_to_pat(tcx, actual, span),
_ => unreachable!()
}
}

_ => ast::PatLit(P(expr.clone()))
};
P(ast::Pat { id: expr.id, node: pat, span: span })
Expand Down Expand Up @@ -388,7 +381,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
let val = try!(eval_const_expr_partial(tcx, &**base, Some(base_hint)));
cast_const(val, ety)
}
ast::ExprPath(_) | ast::ExprQPath(_) => {
ast::ExprPath(..) => {
let opt_def = tcx.def_map.borrow().get(&e.id).map(|d| d.full_def());
let (const_expr, const_ty) = match opt_def {
Some(def::DefConst(def_id)) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/effect.rs
Expand Up @@ -175,7 +175,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EffectCheckVisitor<'a, 'tcx> {
ast::ExprInlineAsm(..) => {
self.require_unsafe(expr.span, "use of inline assembly");
}
ast::ExprPath(_) | ast::ExprQPath(_) => {
ast::ExprPath(..) => {
if let def::DefStatic(_, true) = ty::resolve_expr(self.tcx, expr) {
self.require_unsafe(expr.span, "use of mutable static");
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/expr_use_visitor.rs
Expand Up @@ -422,7 +422,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
self.walk_expr(&**subexpr)
}

ast::ExprPath(_) | ast::ExprQPath(_) => { }
ast::ExprPath(..) => { }

ast::ExprUnary(ast::UnDeref, ref base) => { // *base
if !self.walk_overloaded_operator(expr, &**base, Vec::new(), PassArgs::ByRef) {
Expand Down
11 changes: 9 additions & 2 deletions src/librustc/middle/infer/error_reporting.rs
Expand Up @@ -1233,7 +1233,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
}
ty_queue.push(&*mut_ty.ty);
}
ast::TyPath(ref path) => {
ast::TyPath(ref maybe_qself, ref path) => {
let a_def = match self.tcx.def_map.borrow().get(&cur_ty.id) {
None => {
self.tcx
Expand Down Expand Up @@ -1277,9 +1277,16 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
region_names: region_names
};
let new_path = self.rebuild_path(rebuild_info, lifetime);
let qself = maybe_qself.as_ref().map(|qself| {
ast::QSelf {
ty: self.rebuild_arg_ty_or_output(&qself.ty, lifetime,
anon_nums, region_names),
position: qself.position
}
});
let to = ast::Ty {
id: cur_ty.id,
node: ast::TyPath(new_path),
node: ast::TyPath(qself, new_path),
span: cur_ty.span
};
new_ty = self.rebuild_ty(new_ty, P(to));
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/middle/liveness.rs
Expand Up @@ -445,7 +445,7 @@ fn visit_arm(ir: &mut IrMaps, arm: &ast::Arm) {
fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
match expr.node {
// live nodes required for uses or definitions of variables:
ast::ExprPath(_) | ast::ExprQPath(_) => {
ast::ExprPath(..) => {
let def = ir.tcx.def_map.borrow()[expr.id].full_def();
debug!("expr {}: path that leads to {:?}", expr.id, def);
if let DefLocal(..) = def {
Expand Down Expand Up @@ -947,7 +947,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
match expr.node {
// Interesting cases with control flow or which gen/kill

ast::ExprPath(_) | ast::ExprQPath(_) => {
ast::ExprPath(..) => {
self.access_path(expr, succ, ACC_READ | ACC_USE)
}

Expand Down Expand Up @@ -1275,7 +1275,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
// just ignore such cases and treat them as reads.

match expr.node {
ast::ExprPath(_) | ast::ExprQPath(_) => succ,
ast::ExprPath(..) => 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 All @@ -1286,7 +1286,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
fn write_lvalue(&mut self, expr: &Expr, succ: LiveNode, acc: uint)
-> LiveNode {
match expr.node {
ast::ExprPath(_) | ast::ExprQPath(_) => {
ast::ExprPath(..) => {
self.access_path(expr, succ, acc)
}

Expand Down Expand Up @@ -1468,7 +1468,7 @@ fn check_expr(this: &mut Liveness, expr: &Expr) {
ast::ExprBlock(..) | ast::ExprMac(..) | ast::ExprAddrOf(..) |
ast::ExprStruct(..) | ast::ExprRepeat(..) | ast::ExprParen(..) |
ast::ExprClosure(..) | ast::ExprPath(..) | ast::ExprBox(..) |
ast::ExprRange(..) | ast::ExprQPath(..) => {
ast::ExprRange(..) => {
visit::walk_expr(this, expr);
}
ast::ExprIfLet(..) => {
Expand Down Expand Up @@ -1561,7 +1561,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {

fn check_lvalue(&mut self, expr: &Expr) {
match expr.node {
ast::ExprPath(_) | ast::ExprQPath(_) => {
ast::ExprPath(..) => {
if let DefLocal(nid) = self.ir.tcx.def_map.borrow()[expr.id].full_def() {
// Assignment to an immutable variable or argument: only legal
// if there is no later assignment. If this local is actually
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/mem_categorization.rs
Expand Up @@ -529,7 +529,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
}
}

ast::ExprPath(_) | ast::ExprQPath(_) => {
ast::ExprPath(..) => {
let def = self.tcx().def_map.borrow()[expr.id].full_def();
self.cat_def(expr.id, expr.span, expr_ty, def)
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/reachable.rs
Expand Up @@ -94,7 +94,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for ReachableContext<'a, 'tcx> {
fn visit_expr(&mut self, expr: &ast::Expr) {

match expr.node {
ast::ExprPath(_) | ast::ExprQPath(_) => {
ast::ExprPath(..) => {
let def = match self.tcx.def_map.borrow().get(&expr.id) {
Some(d) => d.full_def(),
None => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/resolve_lifetime.rs
Expand Up @@ -165,7 +165,7 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
visit::walk_ty(this, ty);
});
}
ast::TyPath(ref path) => {
ast::TyPath(None, ref path) => {
// if this path references a trait, then this will resolve to
// a trait ref, which introduces a binding scope.
match self.def_map.borrow().get(&ty.id).map(|d| (d.base_def, d.depth)) {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/ty.rs
Expand Up @@ -4550,7 +4550,7 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
}

match expr.node {
ast::ExprPath(_) | ast::ExprQPath(_) => {
ast::ExprPath(..) => {
match resolve_expr(tcx, expr) {
def::DefVariant(tid, vid, _) => {
let variant_info = enum_variant_with_id(tcx, tid, vid);
Expand Down Expand Up @@ -5838,7 +5838,7 @@ pub fn eval_repeat_count(tcx: &ctxt, count_expr: &ast::Expr) -> uint {
}
Err(_) => {
let found = match count_expr.node {
ast::ExprPath(ast::Path {
ast::ExprPath(None, ast::Path {
global: false,
ref segments,
..
Expand Down
6 changes: 2 additions & 4 deletions src/librustc_back/svh.rs
Expand Up @@ -244,8 +244,7 @@ mod svh_visitor {
SawExprAssignOp(ast::BinOp_),
SawExprIndex,
SawExprRange,
SawExprPath,
SawExprQPath,
SawExprPath(Option<usize>),
SawExprAddrOf(ast::Mutability),
SawExprRet,
SawExprInlineAsm(&'a ast::InlineAsm),
Expand Down Expand Up @@ -277,8 +276,7 @@ mod svh_visitor {
ExprTupField(_, id) => SawExprTupField(id.node),
ExprIndex(..) => SawExprIndex,
ExprRange(..) => SawExprRange,
ExprPath(..) => SawExprPath,
ExprQPath(..) => SawExprQPath,
ExprPath(ref qself, _) => SawExprPath(qself.as_ref().map(|q| q.position)),
ExprAddrOf(m, _) => SawExprAddrOf(m),
ExprBreak(id) => SawExprBreak(id.map(content)),
ExprAgain(id) => SawExprAgain(id.map(content)),
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_privacy/lib.rs
Expand Up @@ -258,7 +258,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
// * Private trait impls for private types can be completely ignored
ast::ItemImpl(_, _, _, _, ref ty, ref impl_items) => {
let public_ty = match ty.node {
ast::TyPath(_) => {
ast::TyPath(..) => {
match self.tcx.def_map.borrow()[ty.id].full_def() {
def::DefPrimTy(..) => true,
def => {
Expand Down Expand Up @@ -325,7 +325,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
}

ast::ItemTy(ref ty, _) if public_first => {
if let ast::TyPath(_) = ty.node {
if let ast::TyPath(..) = ty.node {
match self.tcx.def_map.borrow()[ty.id].full_def() {
def::DefPrimTy(..) | def::DefTyParam(..) => {},
def => {
Expand Down Expand Up @@ -627,7 +627,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
// was private.
ast::ItemImpl(_, _, _, _, ref ty, _) => {
match ty.node {
ast::TyPath(_) => {}
ast::TyPath(..) => {}
_ => return Some((err_span, err_msg, None)),
};
let def = self.tcx.def_map.borrow()[ty.id].full_def();
Expand Down Expand Up @@ -908,7 +908,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
struct type?!"),
}
}
ast::ExprPath(_) | ast::ExprQPath(_) => {
ast::ExprPath(..) => {
let guard = |did: ast::DefId| {
let fields = ty::lookup_struct_fields(self.tcx, did);
let any_priv = fields.iter().any(|f| {
Expand Down Expand Up @@ -1254,7 +1254,7 @@ impl<'a, 'tcx> VisiblePrivateTypesVisitor<'a, 'tcx> {

impl<'a, 'b, 'tcx, 'v> Visitor<'v> for CheckTypeForPrivatenessVisitor<'a, 'b, 'tcx> {
fn visit_ty(&mut self, ty: &ast::Ty) {
if let ast::TyPath(_) = ty.node {
if let ast::TyPath(..) = ty.node {
if self.inner.path_is_private_type(ty.id) {
self.contains_private = true;
// found what we're looking for so let's stop
Expand Down Expand Up @@ -1460,7 +1460,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
}

fn visit_ty(&mut self, t: &ast::Ty) {
if let ast::TyPath(ref p) = t.node {
if let ast::TyPath(_, ref p) = t.node {
if !self.tcx.sess.features.borrow().visible_private_types &&
self.path_is_private_type(t.id) {
self.tcx.sess.span_err(p.span,
Expand Down

0 comments on commit d31b9eb

Please sign in to comment.