Skip to content

Commit 119c614

Browse files
committed
librustc: Remove @ pointer patterns from the language
1 parent ce358fc commit 119c614

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1014
-1035
lines changed

doc/rust.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -2865,19 +2865,19 @@ In a pattern whose head expression has an `enum` type, a placeholder (`_`) stand
28652865
variant. For example:
28662866

28672867
~~~~
2868-
enum List<X> { Nil, Cons(X, @List<X>) }
2868+
enum List<X> { Nil, Cons(X, ~List<X>) }
28692869
2870-
let x: List<int> = Cons(10, @Cons(11, @Nil));
2870+
let x: List<int> = Cons(10, ~Cons(11, ~Nil));
28712871
28722872
match x {
2873-
Cons(_, @Nil) => fail!("singleton list"),
2873+
Cons(_, ~Nil) => fail!("singleton list"),
28742874
Cons(..) => return,
28752875
Nil => fail!("empty list")
28762876
}
28772877
~~~~
28782878

28792879
The first pattern matches lists constructed by applying `Cons` to any head value, and a
2880-
tail value of `@Nil`. The second pattern matches _any_ list constructed with `Cons`,
2880+
tail value of `~Nil`. The second pattern matches _any_ list constructed with `Cons`,
28812881
ignoring the values of its arguments. The difference between `_` and `*` is that the pattern `C(_)` is only type-correct if
28822882
`C` has exactly one argument, while the pattern `C(..)` is type-correct for any enum variant `C`, regardless of how many arguments `C` has.
28832883

@@ -2893,12 +2893,12 @@ An example of an `match` expression:
28932893
# fn process_pair(a: int, b: int) { }
28942894
# fn process_ten() { }
28952895
2896-
enum List<X> { Nil, Cons(X, @List<X>) }
2896+
enum List<X> { Nil, Cons(X, ~List<X>) }
28972897
2898-
let x: List<int> = Cons(10, @Cons(11, @Nil));
2898+
let x: List<int> = Cons(10, ~Cons(11, ~Nil));
28992899
29002900
match x {
2901-
Cons(a, @Cons(b, _)) => {
2901+
Cons(a, ~Cons(b, _)) => {
29022902
process_pair(a,b);
29032903
}
29042904
Cons(10, _) => {

src/librustc/front/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ fn method_in_cfg(cx: &Context, meth: &ast::Method) -> bool {
201201
fn trait_method_in_cfg(cx: &Context, meth: &ast::TraitMethod) -> bool {
202202
match *meth {
203203
ast::Required(ref meth) => (cx.in_cfg)(meth.attrs),
204-
ast::Provided(@ref meth) => (cx.in_cfg)(meth.attrs)
204+
ast::Provided(meth) => (cx.in_cfg)(meth.attrs)
205205
}
206206
}
207207

src/librustc/middle/astencode.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -308,15 +308,13 @@ impl Folder for NestedItemsDropper {
308308
fn fold_block(&mut self, blk: ast::P<ast::Block>) -> ast::P<ast::Block> {
309309
let stmts_sans_items = blk.stmts.iter().filter_map(|stmt| {
310310
match stmt.node {
311-
ast::StmtExpr(_, _) | ast::StmtSemi(_, _) |
312-
ast::StmtDecl(@codemap::Spanned {
313-
node: ast::DeclLocal(_),
314-
span: _
315-
}, _) => Some(*stmt),
316-
ast::StmtDecl(@codemap::Spanned {
317-
node: ast::DeclItem(_),
318-
span: _
319-
}, _) => None,
311+
ast::StmtExpr(_, _) | ast::StmtSemi(_, _) => Some(*stmt),
312+
ast::StmtDecl(decl, _) => {
313+
match decl.node {
314+
ast::DeclLocal(_) => Some(*stmt),
315+
ast::DeclItem(_) => None,
316+
}
317+
}
320318
ast::StmtMac(..) => fail!("unexpanded macro in astencode")
321319
}
322320
}).collect();

src/librustc/middle/cfg/construct.rs

-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ impl CFGBuilder {
101101
self.add_node(pat.id, [pred])
102102
}
103103

104-
ast::PatBox(subpat) |
105104
ast::PatUniq(subpat) |
106105
ast::PatRegion(subpat) |
107106
ast::PatIdent(_, _, Some(subpat)) => {

src/librustc/middle/check_const.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use middle::typeck;
1616
use util::ppaux;
1717

1818
use syntax::ast::*;
19-
use syntax::codemap;
2019
use syntax::{ast_util, ast_map};
2120
use syntax::visit::Visitor;
2221
use syntax::visit;
@@ -84,14 +83,13 @@ pub fn check_item(v: &mut CheckCrateVisitor,
8483
pub fn check_pat(v: &mut CheckCrateVisitor, p: &Pat, _is_const: bool) {
8584
fn is_str(e: @Expr) -> bool {
8685
match e.node {
87-
ExprVstore(
88-
@Expr { node: ExprLit(@codemap::Spanned {
89-
node: LitStr(..),
90-
..}),
91-
.. },
92-
ExprVstoreUniq
93-
) => true,
94-
_ => false
86+
ExprVstore(expr, ExprVstoreUniq) => {
87+
match expr.node {
88+
ExprLit(lit) => ast_util::lit_is_str(lit),
89+
_ => false,
90+
}
91+
}
92+
_ => false,
9593
}
9694
}
9795
match p.node {
@@ -120,7 +118,7 @@ pub fn check_expr(v: &mut CheckCrateVisitor,
120118
"cannot do allocations in constant expressions");
121119
return;
122120
}
123-
ExprLit(@codemap::Spanned {node: LitStr(..), ..}) => { }
121+
ExprLit(lit) if ast_util::lit_is_str(lit) => {}
124122
ExprBinary(..) | ExprUnary(..) => {
125123
let method_map = method_map.borrow();
126124
if method_map.get().contains_key(&e.id) {

src/librustc/middle/check_match.rs

+15-9
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::num;
2323
use std::vec;
2424
use syntax::ast::*;
2525
use syntax::ast_util::{unguarded_pat, walk_pat};
26-
use syntax::codemap::{Span, DUMMY_SP, Spanned};
26+
use syntax::codemap::{DUMMY_SP, Span};
2727
use syntax::visit;
2828
use syntax::visit::{Visitor, FnKind};
2929

@@ -362,7 +362,7 @@ fn pat_ctor_id(cx: &MatchCheckCtxt, p: @Pat) -> Option<ctor> {
362362
_ => Some(single)
363363
}
364364
}
365-
PatBox(_) | PatUniq(_) | PatTup(_) | PatRegion(..) => {
365+
PatUniq(_) | PatTup(_) | PatRegion(..) => {
366366
Some(single)
367367
}
368368
PatVec(ref before, slice, ref after) => {
@@ -735,7 +735,7 @@ fn specialize(cx: &MatchCheckCtxt,
735735
}
736736
}
737737
PatTup(args) => Some(vec::append(args, r.tail())),
738-
PatBox(a) | PatUniq(a) | PatRegion(a) => {
738+
PatUniq(a) | PatRegion(a) => {
739739
Some(vec::append(~[a], r.tail()))
740740
}
741741
PatLit(expr) => {
@@ -874,16 +874,22 @@ fn is_refutable(cx: &MatchCheckCtxt, pat: &Pat) -> bool {
874874
}
875875

876876
match pat.node {
877-
PatBox(sub) | PatUniq(sub) | PatRegion(sub) |
878-
PatIdent(_, _, Some(sub)) => {
877+
PatUniq(sub) | PatRegion(sub) | PatIdent(_, _, Some(sub)) => {
879878
is_refutable(cx, sub)
880879
}
881880
PatWild | PatWildMulti | PatIdent(_, _, None) => { false }
882-
PatLit(@Expr {node: ExprLit(@Spanned { node: LitNil, ..}), ..}) => {
883-
// "()"
884-
false
881+
PatLit(lit) => {
882+
match lit.node {
883+
ExprLit(lit) => {
884+
match lit.node {
885+
LitNil => false, // `()`
886+
_ => true,
887+
}
888+
}
889+
_ => true,
890+
}
885891
}
886-
PatLit(_) | PatRange(_, _) => { true }
892+
PatRange(_, _) => { true }
887893
PatStruct(_, ref fields, _) => {
888894
fields.iter().any(|f| is_refutable(cx, f.pat))
889895
}

src/librustc/middle/kind.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,18 @@ pub fn check_expr(cx: &mut Context, e: &Expr) {
330330
// Search for auto-adjustments to find trait coercions.
331331
let adjustments = cx.tcx.adjustments.borrow();
332332
match adjustments.get().find(&e.id) {
333-
Some(&@ty::AutoObject(..)) => {
334-
let source_ty = ty::expr_ty(cx.tcx, e);
335-
let target_ty = ty::expr_ty_adjusted(cx.tcx, e);
336-
check_trait_cast(cx, source_ty, target_ty, e.span);
333+
Some(adjustment) => {
334+
match **adjustment {
335+
ty::AutoObject(..) => {
336+
let source_ty = ty::expr_ty(cx.tcx, e);
337+
let target_ty = ty::expr_ty_adjusted(cx.tcx, e);
338+
check_trait_cast(cx, source_ty, target_ty, e.span);
339+
}
340+
ty::AutoAddEnv(..) |
341+
ty::AutoDerefRef(..) => {}
342+
}
337343
}
338-
Some(&@ty::AutoAddEnv(..)) | Some(&@ty::AutoDerefRef(..)) | None => {}
344+
None => {}
339345
}
340346

341347
visit::walk_expr(cx, e, ());

src/librustc/middle/lint.rs

+42-21
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ use syntax::ast_map;
6262
use syntax::attr;
6363
use syntax::attr::{AttrMetaMethods, AttributeMethods};
6464
use syntax::codemap::Span;
65-
use syntax::codemap;
6665
use syntax::parse::token;
6766
use syntax::{ast, ast_util, visit};
6867
use syntax::ast_util::IdVisitingOperation;
@@ -590,11 +589,16 @@ fn check_while_true_expr(cx: &Context, e: &ast::Expr) {
590589
match e.node {
591590
ast::ExprWhile(cond, _) => {
592591
match cond.node {
593-
ast::ExprLit(@codemap::Spanned {
594-
node: ast::LitBool(true), ..}) =>
595-
{
596-
cx.span_lint(WhileTrue, e.span,
597-
"denote infinite loops with loop { ... }");
592+
ast::ExprLit(lit) => {
593+
match lit.node {
594+
ast::LitBool(true) => {
595+
cx.span_lint(WhileTrue,
596+
e.span,
597+
"denote infinite loops with loop \
598+
{ ... }");
599+
}
600+
_ => {}
601+
}
598602
}
599603
_ => ()
600604
}
@@ -989,9 +993,15 @@ fn check_heap_expr(cx: &Context, e: &ast::Expr) {
989993

990994
fn check_path_statement(cx: &Context, s: &ast::Stmt) {
991995
match s.node {
992-
ast::StmtSemi(@ast::Expr { node: ast::ExprPath(_), .. }, _) => {
993-
cx.span_lint(PathStatement, s.span,
994-
"path statement with no effect");
996+
ast::StmtSemi(expr, _) => {
997+
match expr.node {
998+
ast::ExprPath(_) => {
999+
cx.span_lint(PathStatement,
1000+
s.span,
1001+
"path statement with no effect");
1002+
}
1003+
_ => {}
1004+
}
9951005
}
9961006
_ => ()
9971007
}
@@ -1132,7 +1142,9 @@ fn check_unnecessary_allocation(cx: &Context, e: &ast::Expr) {
11321142
ast::ExprVstore(e2, ast::ExprVstoreUniq) |
11331143
ast::ExprVstore(e2, ast::ExprVstoreBox) => {
11341144
match e2.node {
1135-
ast::ExprLit(@codemap::Spanned{node: ast::LitStr(..), ..}) |
1145+
ast::ExprLit(lit) if ast_util::lit_is_str(lit) => {
1146+
VectorAllocation
1147+
}
11361148
ast::ExprVec(..) => VectorAllocation,
11371149
_ => return
11381150
}
@@ -1152,18 +1164,27 @@ fn check_unnecessary_allocation(cx: &Context, e: &ast::Expr) {
11521164
adjustments.get().find_copy(&e.id)
11531165
};
11541166
match adjustment {
1155-
Some(@ty::AutoDerefRef(ty::AutoDerefRef { autoref, .. })) => {
1156-
match (allocation, autoref) {
1157-
(VectorAllocation, Some(ty::AutoBorrowVec(..))) => {
1158-
report("unnecessary allocation, the sigil can be removed");
1159-
}
1160-
(BoxAllocation, Some(ty::AutoPtr(_, ast::MutImmutable))) => {
1161-
report("unnecessary allocation, use & instead");
1162-
}
1163-
(BoxAllocation, Some(ty::AutoPtr(_, ast::MutMutable))) => {
1164-
report("unnecessary allocation, use &mut instead");
1167+
Some(adjustment) => {
1168+
match *adjustment {
1169+
ty::AutoDerefRef(ty::AutoDerefRef { autoref, .. }) => {
1170+
match (allocation, autoref) {
1171+
(VectorAllocation, Some(ty::AutoBorrowVec(..))) => {
1172+
report("unnecessary allocation, the sigil can be \
1173+
removed");
1174+
}
1175+
(BoxAllocation,
1176+
Some(ty::AutoPtr(_, ast::MutImmutable))) => {
1177+
report("unnecessary allocation, use & instead");
1178+
}
1179+
(BoxAllocation,
1180+
Some(ty::AutoPtr(_, ast::MutMutable))) => {
1181+
report("unnecessary allocation, use &mut \
1182+
instead");
1183+
}
1184+
_ => ()
1185+
}
11651186
}
1166-
_ => ()
1187+
_ => {}
11671188
}
11681189
}
11691190

src/librustc/middle/mem_categorization.rs

+31-29
Original file line numberDiff line numberDiff line change
@@ -341,36 +341,39 @@ impl mem_categorization_ctxt {
341341
self.cat_expr_unadjusted(expr)
342342
}
343343

344-
Some(&@ty::AutoObject(..)) => {
345-
// Implicity casts a concrete object to trait object
346-
// Result is an rvalue
347-
let expr_ty = ty::expr_ty_adjusted(self.tcx, expr);
348-
self.cat_rvalue_node(expr, expr_ty)
349-
}
344+
Some(adjustment) => {
345+
match **adjustment {
346+
ty::AutoObject(..) => {
347+
// Implicity casts a concrete object to trait object
348+
// Result is an rvalue
349+
let expr_ty = ty::expr_ty_adjusted(self.tcx, expr);
350+
self.cat_rvalue_node(expr, expr_ty)
351+
}
350352

351-
Some(&@ty::AutoAddEnv(..)) => {
352-
// Convert a bare fn to a closure by adding NULL env.
353-
// Result is an rvalue.
354-
let expr_ty = ty::expr_ty_adjusted(self.tcx, expr);
355-
self.cat_rvalue_node(expr, expr_ty)
356-
}
353+
ty::AutoAddEnv(..) => {
354+
// Convert a bare fn to a closure by adding NULL env.
355+
// Result is an rvalue.
356+
let expr_ty = ty::expr_ty_adjusted(self.tcx, expr);
357+
self.cat_rvalue_node(expr, expr_ty)
358+
}
357359

358-
Some(
359-
&@ty::AutoDerefRef(
360-
ty::AutoDerefRef {
361-
autoref: Some(_), ..})) => {
362-
// Equivalent to &*expr or something similar.
363-
// Result is an rvalue.
364-
let expr_ty = ty::expr_ty_adjusted(self.tcx, expr);
365-
self.cat_rvalue_node(expr, expr_ty)
366-
}
360+
ty::AutoDerefRef(ty::AutoDerefRef {
361+
autoref: Some(_),
362+
..}) => {
363+
// Equivalent to &*expr or something similar.
364+
// Result is an rvalue.
365+
let expr_ty = ty::expr_ty_adjusted(self.tcx, expr);
366+
self.cat_rvalue_node(expr, expr_ty)
367+
}
367368

368-
Some(
369-
&@ty::AutoDerefRef(
370-
ty::AutoDerefRef {
371-
autoref: None, autoderefs: autoderefs})) => {
372-
// Equivalent to *expr or something similar.
373-
self.cat_expr_autoderefd(expr, autoderefs)
369+
ty::AutoDerefRef(ty::AutoDerefRef {
370+
autoref: None,
371+
autoderefs: autoderefs
372+
}) => {
373+
// Equivalent to *expr or something similar.
374+
self.cat_expr_autoderefd(expr, autoderefs)
375+
}
376+
}
374377
}
375378
}
376379
}
@@ -973,8 +976,7 @@ impl mem_categorization_ctxt {
973976
}
974977
}
975978

976-
ast::PatBox(subpat) | ast::PatUniq(subpat) |
977-
ast::PatRegion(subpat) => {
979+
ast::PatUniq(subpat) | ast::PatRegion(subpat) => {
978980
// @p1, ~p1
979981
let subcmt = self.cat_deref(pat, cmt, 0);
980982
self.cat_pattern(subcmt, subpat, op);

src/librustc/middle/moves.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,16 @@ impl VisitContext {
328328
let comp_mode = {
329329
let adjustments = self.tcx.adjustments.borrow();
330330
match adjustments.get().find(&expr.id) {
331-
Some(&@ty::AutoDerefRef(
332-
ty::AutoDerefRef {
333-
autoref: Some(_), ..})) => Read,
334-
_ => expr_mode
331+
Some(adjustment) => {
332+
match **adjustment {
333+
ty::AutoDerefRef(ty::AutoDerefRef {
334+
autoref: Some(_),
335+
..
336+
}) => Read,
337+
_ => expr_mode,
338+
}
339+
}
340+
_ => expr_mode,
335341
}
336342
};
337343

0 commit comments

Comments
 (0)