Skip to content

Commit d31b9eb

Browse files
committed
Implement <T>::method UFCS expression syntax.
1 parent fdfb532 commit d31b9eb

40 files changed

+286
-200
lines changed

src/librustc/lint/builtin.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
437437

438438
impl<'a, 'tcx, 'v> Visitor<'v> for ImproperCTypesVisitor<'a, 'tcx> {
439439
fn visit_ty(&mut self, ty: &ast::Ty) {
440-
if let ast::TyPath(_) = ty.node {
440+
if let ast::TyPath(..) = ty.node {
441441
self.check_def(ty.span, ty.id);
442442
}
443443
visit::walk_ty(self, ty);
@@ -682,8 +682,8 @@ impl LintPass for PathStatements {
682682
match s.node {
683683
ast::StmtSemi(ref expr, _) => {
684684
match expr.node {
685-
ast::ExprPath(_) => cx.span_lint(PATH_STATEMENTS, s.span,
686-
"path statement with no effect"),
685+
ast::ExprPath(..) => cx.span_lint(PATH_STATEMENTS, s.span,
686+
"path statement with no effect"),
687687
_ => ()
688688
}
689689
}

src/librustc/metadata/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
12211221
encode_unsafety(rbml_w, unsafety);
12221222
encode_polarity(rbml_w, polarity);
12231223
match ty.node {
1224-
ast::TyPath(ref path) if path.segments.len() == 1 => {
1224+
ast::TyPath(None, ref path) if path.segments.len() == 1 => {
12251225
let ident = path.segments.last().unwrap().identifier;
12261226
encode_impl_type_basename(rbml_w, ident);
12271227
}

src/librustc/middle/astconv_util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub fn prim_ty_to_ty<'tcx>(tcx: &ty::ctxt<'tcx>,
5959

6060
pub fn ast_ty_to_prim_ty<'tcx>(tcx: &ty::ctxt<'tcx>, ast_ty: &ast::Ty)
6161
-> Option<Ty<'tcx>> {
62-
if let ast::TyPath(ref path) = ast_ty.node {
62+
if let ast::TyPath(None, ref path) = ast_ty.node {
6363
let def = match tcx.def_map.borrow().get(&ast_ty.id) {
6464
None => {
6565
tcx.sess.span_bug(ast_ty.span,

src/librustc/middle/cfg/construct.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
398398
ast::ExprMac(..) |
399399
ast::ExprClosure(..) |
400400
ast::ExprLit(..) |
401-
ast::ExprPath(..) |
402-
ast::ExprQPath(..) => {
401+
ast::ExprPath(..) => {
403402
self.straightline(expr, pred, None::<ast::Expr>.iter())
404403
}
405404
}

src/librustc/middle/check_const.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
439439
}
440440
}
441441
}
442-
ast::ExprPath(_) | ast::ExprQPath(_) => {
442+
ast::ExprPath(..) => {
443443
let def = v.tcx.def_map.borrow().get(&e.id).map(|d| d.full_def());
444444
match def {
445445
Some(def::DefVariant(_, _, _)) => {

src/librustc/middle/check_static_recursion.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ impl<'a, 'ast, 'v> Visitor<'v> for CheckItemRecursionVisitor<'a, 'ast> {
9393

9494
fn visit_expr(&mut self, e: &ast::Expr) {
9595
match e.node {
96-
ast::ExprPath(_) | ast::ExprQPath(_) => {
97-
match self.def_map.borrow().get(&e.id).map(|d| d.full_def()) {
96+
ast::ExprPath(..) => {
97+
match self.def_map.borrow().get(&e.id).map(|d| d.base_def) {
9898
Some(DefStatic(def_id, _)) |
9999
Some(DefConst(def_id)) if
100100
ast_util::is_local(def_id) => {

src/librustc/middle/const_eval.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr, span: Span) -> P<ast::Pat>
178178
ast::PatVec(pats, None, vec![])
179179
}
180180

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

197-
ast::ExprQPath(_) => {
198-
match lookup_const(tcx, expr) {
199-
Some(actual) => return const_expr_to_pat(tcx, actual, span),
200-
_ => unreachable!()
201-
}
202-
}
203-
204197
_ => ast::PatLit(P(expr.clone()))
205198
};
206199
P(ast::Pat { id: expr.id, node: pat, span: span })
@@ -388,7 +381,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
388381
let val = try!(eval_const_expr_partial(tcx, &**base, Some(base_hint)));
389382
cast_const(val, ety)
390383
}
391-
ast::ExprPath(_) | ast::ExprQPath(_) => {
384+
ast::ExprPath(..) => {
392385
let opt_def = tcx.def_map.borrow().get(&e.id).map(|d| d.full_def());
393386
let (const_expr, const_ty) = match opt_def {
394387
Some(def::DefConst(def_id)) => {

src/librustc/middle/effect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EffectCheckVisitor<'a, 'tcx> {
175175
ast::ExprInlineAsm(..) => {
176176
self.require_unsafe(expr.span, "use of inline assembly");
177177
}
178-
ast::ExprPath(_) | ast::ExprQPath(_) => {
178+
ast::ExprPath(..) => {
179179
if let def::DefStatic(_, true) = ty::resolve_expr(self.tcx, expr) {
180180
self.require_unsafe(expr.span, "use of mutable static");
181181
}

src/librustc/middle/expr_use_visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
422422
self.walk_expr(&**subexpr)
423423
}
424424

425-
ast::ExprPath(_) | ast::ExprQPath(_) => { }
425+
ast::ExprPath(..) => { }
426426

427427
ast::ExprUnary(ast::UnDeref, ref base) => { // *base
428428
if !self.walk_overloaded_operator(expr, &**base, Vec::new(), PassArgs::ByRef) {

src/librustc/middle/infer/error_reporting.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
12331233
}
12341234
ty_queue.push(&*mut_ty.ty);
12351235
}
1236-
ast::TyPath(ref path) => {
1236+
ast::TyPath(ref maybe_qself, ref path) => {
12371237
let a_def = match self.tcx.def_map.borrow().get(&cur_ty.id) {
12381238
None => {
12391239
self.tcx
@@ -1277,9 +1277,16 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
12771277
region_names: region_names
12781278
};
12791279
let new_path = self.rebuild_path(rebuild_info, lifetime);
1280+
let qself = maybe_qself.as_ref().map(|qself| {
1281+
ast::QSelf {
1282+
ty: self.rebuild_arg_ty_or_output(&qself.ty, lifetime,
1283+
anon_nums, region_names),
1284+
position: qself.position
1285+
}
1286+
});
12801287
let to = ast::Ty {
12811288
id: cur_ty.id,
1282-
node: ast::TyPath(new_path),
1289+
node: ast::TyPath(qself, new_path),
12831290
span: cur_ty.span
12841291
};
12851292
new_ty = self.rebuild_ty(new_ty, P(to));

src/librustc/middle/liveness.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ fn visit_arm(ir: &mut IrMaps, arm: &ast::Arm) {
445445
fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
446446
match expr.node {
447447
// live nodes required for uses or definitions of variables:
448-
ast::ExprPath(_) | ast::ExprQPath(_) => {
448+
ast::ExprPath(..) => {
449449
let def = ir.tcx.def_map.borrow()[expr.id].full_def();
450450
debug!("expr {}: path that leads to {:?}", expr.id, def);
451451
if let DefLocal(..) = def {
@@ -947,7 +947,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
947947
match expr.node {
948948
// Interesting cases with control flow or which gen/kill
949949

950-
ast::ExprPath(_) | ast::ExprQPath(_) => {
950+
ast::ExprPath(..) => {
951951
self.access_path(expr, succ, ACC_READ | ACC_USE)
952952
}
953953

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

12771277
match expr.node {
1278-
ast::ExprPath(_) | ast::ExprQPath(_) => succ,
1278+
ast::ExprPath(..) => succ,
12791279
ast::ExprField(ref e, _) => self.propagate_through_expr(&**e, succ),
12801280
ast::ExprTupField(ref e, _) => self.propagate_through_expr(&**e, succ),
12811281
_ => self.propagate_through_expr(expr, succ)
@@ -1286,7 +1286,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
12861286
fn write_lvalue(&mut self, expr: &Expr, succ: LiveNode, acc: uint)
12871287
-> LiveNode {
12881288
match expr.node {
1289-
ast::ExprPath(_) | ast::ExprQPath(_) => {
1289+
ast::ExprPath(..) => {
12901290
self.access_path(expr, succ, acc)
12911291
}
12921292

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

15621562
fn check_lvalue(&mut self, expr: &Expr) {
15631563
match expr.node {
1564-
ast::ExprPath(_) | ast::ExprQPath(_) => {
1564+
ast::ExprPath(..) => {
15651565
if let DefLocal(nid) = self.ir.tcx.def_map.borrow()[expr.id].full_def() {
15661566
// Assignment to an immutable variable or argument: only legal
15671567
// if there is no later assignment. If this local is actually

src/librustc/middle/mem_categorization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
529529
}
530530
}
531531

532-
ast::ExprPath(_) | ast::ExprQPath(_) => {
532+
ast::ExprPath(..) => {
533533
let def = self.tcx().def_map.borrow()[expr.id].full_def();
534534
self.cat_def(expr.id, expr.span, expr_ty, def)
535535
}

src/librustc/middle/reachable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for ReachableContext<'a, 'tcx> {
9494
fn visit_expr(&mut self, expr: &ast::Expr) {
9595

9696
match expr.node {
97-
ast::ExprPath(_) | ast::ExprQPath(_) => {
97+
ast::ExprPath(..) => {
9898
let def = match self.tcx.def_map.borrow().get(&expr.id) {
9999
Some(d) => d.full_def(),
100100
None => {

src/librustc/middle/resolve_lifetime.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
165165
visit::walk_ty(this, ty);
166166
});
167167
}
168-
ast::TyPath(ref path) => {
168+
ast::TyPath(None, ref path) => {
169169
// if this path references a trait, then this will resolve to
170170
// a trait ref, which introduces a binding scope.
171171
match self.def_map.borrow().get(&ty.id).map(|d| (d.base_def, d.depth)) {

src/librustc/middle/ty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4550,7 +4550,7 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
45504550
}
45514551

45524552
match expr.node {
4553-
ast::ExprPath(_) | ast::ExprQPath(_) => {
4553+
ast::ExprPath(..) => {
45544554
match resolve_expr(tcx, expr) {
45554555
def::DefVariant(tid, vid, _) => {
45564556
let variant_info = enum_variant_with_id(tcx, tid, vid);
@@ -5838,7 +5838,7 @@ pub fn eval_repeat_count(tcx: &ctxt, count_expr: &ast::Expr) -> uint {
58385838
}
58395839
Err(_) => {
58405840
let found = match count_expr.node {
5841-
ast::ExprPath(ast::Path {
5841+
ast::ExprPath(None, ast::Path {
58425842
global: false,
58435843
ref segments,
58445844
..

src/librustc_back/svh.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,7 @@ mod svh_visitor {
244244
SawExprAssignOp(ast::BinOp_),
245245
SawExprIndex,
246246
SawExprRange,
247-
SawExprPath,
248-
SawExprQPath,
247+
SawExprPath(Option<usize>),
249248
SawExprAddrOf(ast::Mutability),
250249
SawExprRet,
251250
SawExprInlineAsm(&'a ast::InlineAsm),
@@ -277,8 +276,7 @@ mod svh_visitor {
277276
ExprTupField(_, id) => SawExprTupField(id.node),
278277
ExprIndex(..) => SawExprIndex,
279278
ExprRange(..) => SawExprRange,
280-
ExprPath(..) => SawExprPath,
281-
ExprQPath(..) => SawExprQPath,
279+
ExprPath(ref qself, _) => SawExprPath(qself.as_ref().map(|q| q.position)),
282280
ExprAddrOf(m, _) => SawExprAddrOf(m),
283281
ExprBreak(id) => SawExprBreak(id.map(content)),
284282
ExprAgain(id) => SawExprAgain(id.map(content)),

src/librustc_privacy/lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
258258
// * Private trait impls for private types can be completely ignored
259259
ast::ItemImpl(_, _, _, _, ref ty, ref impl_items) => {
260260
let public_ty = match ty.node {
261-
ast::TyPath(_) => {
261+
ast::TyPath(..) => {
262262
match self.tcx.def_map.borrow()[ty.id].full_def() {
263263
def::DefPrimTy(..) => true,
264264
def => {
@@ -325,7 +325,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
325325
}
326326

327327
ast::ItemTy(ref ty, _) if public_first => {
328-
if let ast::TyPath(_) = ty.node {
328+
if let ast::TyPath(..) = ty.node {
329329
match self.tcx.def_map.borrow()[ty.id].full_def() {
330330
def::DefPrimTy(..) | def::DefTyParam(..) => {},
331331
def => {
@@ -627,7 +627,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
627627
// was private.
628628
ast::ItemImpl(_, _, _, _, ref ty, _) => {
629629
match ty.node {
630-
ast::TyPath(_) => {}
630+
ast::TyPath(..) => {}
631631
_ => return Some((err_span, err_msg, None)),
632632
};
633633
let def = self.tcx.def_map.borrow()[ty.id].full_def();
@@ -908,7 +908,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
908908
struct type?!"),
909909
}
910910
}
911-
ast::ExprPath(_) | ast::ExprQPath(_) => {
911+
ast::ExprPath(..) => {
912912
let guard = |did: ast::DefId| {
913913
let fields = ty::lookup_struct_fields(self.tcx, did);
914914
let any_priv = fields.iter().any(|f| {
@@ -1254,7 +1254,7 @@ impl<'a, 'tcx> VisiblePrivateTypesVisitor<'a, 'tcx> {
12541254

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

14621462
fn visit_ty(&mut self, t: &ast::Ty) {
1463-
if let ast::TyPath(ref p) = t.node {
1463+
if let ast::TyPath(_, ref p) = t.node {
14641464
if !self.tcx.sess.features.borrow().visible_private_types &&
14651465
self.path_is_private_type(t.id) {
14661466
self.tcx.sess.span_err(p.span,

0 commit comments

Comments
 (0)