Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
14adc9bb
R
Rust
项目概览
int
/
Rust
接近 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
14adc9bb
编写于
2月 11, 2016
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename ast::Pat_ and its variants
上级
5801991b
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
145 addition
and
145 deletion
+145
-145
src/librustc_front/lowering.rs
src/librustc_front/lowering.rs
+14
-12
src/librustc_passes/const_fn.rs
src/librustc_passes/const_fn.rs
+3
-3
src/librustc_trans/save/dump_csv.rs
src/librustc_trans/save/dump_csv.rs
+2
-2
src/librustc_trans/save/mod.rs
src/librustc_trans/save/mod.rs
+5
-5
src/libsyntax/ast.rs
src/libsyntax/ast.rs
+18
-19
src/libsyntax/ast_util.rs
src/libsyntax/ast_util.rs
+2
-2
src/libsyntax/ext/base.rs
src/libsyntax/ext/base.rs
+3
-3
src/libsyntax/ext/build.rs
src/libsyntax/ext/build.rs
+9
-9
src/libsyntax/ext/expand.rs
src/libsyntax/ext/expand.rs
+12
-12
src/libsyntax/feature_gate.rs
src/libsyntax/feature_gate.rs
+4
-4
src/libsyntax/fold.rs
src/libsyntax/fold.rs
+18
-18
src/libsyntax/parse/mod.rs
src/libsyntax/parse/mod.rs
+4
-4
src/libsyntax/parse/parser.rs
src/libsyntax/parse/parser.rs
+20
-21
src/libsyntax/print/pprust.rs
src/libsyntax/print/pprust.rs
+16
-16
src/libsyntax/visit.rs
src/libsyntax/visit.rs
+12
-12
src/libsyntax_ext/deriving/generic/mod.rs
src/libsyntax_ext/deriving/generic/mod.rs
+3
-3
未找到文件。
src/librustc_front/lowering.rs
浏览文件 @
14adc9bb
...
...
@@ -913,26 +913,26 @@ pub fn lower_pat(lctx: &LoweringContext, p: &Pat) -> P<hir::Pat> {
P
(
hir
::
Pat
{
id
:
p
.id
,
node
:
match
p
.node
{
PatWild
=>
hir
::
PatWild
,
PatIdent
(
ref
binding_mode
,
pth1
,
ref
sub
)
=>
{
Pat
Kind
::
Wild
=>
hir
::
PatWild
,
Pat
Kind
::
Ident
(
ref
binding_mode
,
pth1
,
ref
sub
)
=>
{
hir
::
PatIdent
(
lower_binding_mode
(
lctx
,
binding_mode
),
respan
(
pth1
.span
,
lower_ident
(
lctx
,
pth1
.node
)),
sub
.as_ref
()
.map
(|
x
|
lower_pat
(
lctx
,
x
)))
}
PatLit
(
ref
e
)
=>
hir
::
PatLit
(
lower_expr
(
lctx
,
e
)),
PatEnum
(
ref
pth
,
ref
pats
)
=>
{
Pat
Kind
::
Lit
(
ref
e
)
=>
hir
::
PatLit
(
lower_expr
(
lctx
,
e
)),
Pat
Kind
::
Enum
(
ref
pth
,
ref
pats
)
=>
{
hir
::
PatEnum
(
lower_path
(
lctx
,
pth
),
pats
.as_ref
()
.map
(|
pats
|
pats
.iter
()
.map
(|
x
|
lower_pat
(
lctx
,
x
))
.collect
()))
}
PatQPath
(
ref
qself
,
ref
pth
)
=>
{
Pat
Kind
::
QPath
(
ref
qself
,
ref
pth
)
=>
{
let
qself
=
hir
::
QSelf
{
ty
:
lower_ty
(
lctx
,
&
qself
.ty
),
position
:
qself
.position
,
};
hir
::
PatQPath
(
qself
,
lower_path
(
lctx
,
pth
))
}
PatStruct
(
ref
pth
,
ref
fields
,
etc
)
=>
{
Pat
Kind
::
Struct
(
ref
pth
,
ref
fields
,
etc
)
=>
{
let
pth
=
lower_path
(
lctx
,
pth
);
let
fs
=
fields
.iter
()
.map
(|
f
|
{
...
...
@@ -948,20 +948,22 @@ pub fn lower_pat(lctx: &LoweringContext, p: &Pat) -> P<hir::Pat> {
.collect
();
hir
::
PatStruct
(
pth
,
fs
,
etc
)
}
PatTup
(
ref
elts
)
=>
hir
::
PatTup
(
elts
.iter
()
.map
(|
x
|
lower_pat
(
lctx
,
x
))
.collect
()),
PatBox
(
ref
inner
)
=>
hir
::
PatBox
(
lower_pat
(
lctx
,
inner
)),
PatRegion
(
ref
inner
,
mutbl
)
=>
{
PatKind
::
Tup
(
ref
elts
)
=>
{
hir
::
PatTup
(
elts
.iter
()
.map
(|
x
|
lower_pat
(
lctx
,
x
))
.collect
())
}
PatKind
::
Box
(
ref
inner
)
=>
hir
::
PatBox
(
lower_pat
(
lctx
,
inner
)),
PatKind
::
Ref
(
ref
inner
,
mutbl
)
=>
{
hir
::
PatRegion
(
lower_pat
(
lctx
,
inner
),
lower_mutability
(
lctx
,
mutbl
))
}
PatRange
(
ref
e1
,
ref
e2
)
=>
{
Pat
Kind
::
Range
(
ref
e1
,
ref
e2
)
=>
{
hir
::
PatRange
(
lower_expr
(
lctx
,
e1
),
lower_expr
(
lctx
,
e2
))
}
PatVec
(
ref
before
,
ref
slice
,
ref
after
)
=>
{
Pat
Kind
::
Vec
(
ref
before
,
ref
slice
,
ref
after
)
=>
{
hir
::
PatVec
(
before
.iter
()
.map
(|
x
|
lower_pat
(
lctx
,
x
))
.collect
(),
slice
.as_ref
()
.map
(|
x
|
lower_pat
(
lctx
,
x
)),
after
.iter
()
.map
(|
x
|
lower_pat
(
lctx
,
x
))
.collect
())
}
PatMac
(
_
)
=>
panic!
(
"Shouldn't exist here"
),
Pat
Kind
::
Mac
(
_
)
=>
panic!
(
"Shouldn't exist here"
),
},
span
:
p
.span
,
})
...
...
src/librustc_passes/const_fn.rs
浏览文件 @
14adc9bb
...
...
@@ -13,7 +13,7 @@
use
rustc
::
session
::{
Session
,
CompileResult
};
use
syntax
::
ast
;
use
syntax
::
ast
::{
self
,
PatKind
}
;
use
syntax
::
visit
::{
self
,
Visitor
,
FnKind
};
use
syntax
::
codemap
::
Span
;
...
...
@@ -104,8 +104,8 @@ fn visit_fn(&mut self,
// Ensure the arguments are simple, not mutable/by-ref or patterns.
for
arg
in
&
fd
.inputs
{
match
arg
.pat.node
{
ast
::
Pat
Wild
=>
{}
ast
::
Pat
Ident
(
ast
::
BindingMode
::
ByValue
(
ast
::
Mutability
::
Immutable
),
_
,
None
)
=>
{}
PatKind
::
Wild
=>
{}
PatKind
::
Ident
(
ast
::
BindingMode
::
ByValue
(
ast
::
Mutability
::
Immutable
),
_
,
None
)
=>
{}
_
=>
{
span_err!
(
self
.sess
,
arg
.pat.span
,
E0022
,
"arguments of constant functions can only
\
...
...
src/librustc_trans/save/dump_csv.rs
浏览文件 @
14adc9bb
...
...
@@ -40,7 +40,7 @@
use
std
::
hash
::
*
;
use
std
::
collections
::
HashSet
;
use
syntax
::
ast
::{
self
,
NodeId
};
use
syntax
::
ast
::{
self
,
NodeId
,
PatKind
};
use
syntax
::
codemap
::
*
;
use
syntax
::
parse
::
token
::{
self
,
keywords
};
use
syntax
::
visit
::{
self
,
Visitor
};
...
...
@@ -780,7 +780,7 @@ fn process_method_call(&mut self, ex: &ast::Expr, args: &Vec<P<ast::Expr>>) {
fn
process_pat
(
&
mut
self
,
p
:
&
ast
::
Pat
)
{
match
p
.node
{
ast
::
Pat
Struct
(
ref
path
,
ref
fields
,
_
)
=>
{
PatKind
::
Struct
(
ref
path
,
ref
fields
,
_
)
=>
{
visit
::
walk_path
(
self
,
path
);
let
adt
=
self
.tcx
.node_id_to_type
(
p
.id
)
.ty_adt_def
()
.unwrap
();
let
def
=
self
.tcx.def_map
.borrow
()[
&
p
.id
]
.full_def
();
...
...
src/librustc_trans/save/mod.rs
浏览文件 @
14adc9bb
...
...
@@ -21,7 +21,7 @@
use
rustc
::
front
::
map
::
NodeItem
;
use
rustc
::
session
::
config
::
CrateType
::
CrateTypeExecutable
;
use
syntax
::
ast
::{
self
,
NodeId
};
use
syntax
::
ast
::{
self
,
NodeId
,
PatKind
};
use
syntax
::
ast_util
;
use
syntax
::
codemap
::
*
;
use
syntax
::
parse
::
token
::{
self
,
keywords
};
...
...
@@ -758,16 +758,16 @@ fn new() -> PathCollector {
impl
<
'v
>
Visitor
<
'v
>
for
PathCollector
{
fn
visit_pat
(
&
mut
self
,
p
:
&
ast
::
Pat
)
{
match
p
.node
{
ast
::
Pat
Struct
(
ref
path
,
_
,
_
)
=>
{
PatKind
::
Struct
(
ref
path
,
_
,
_
)
=>
{
self
.collected_paths
.push
((
p
.id
,
path
.clone
(),
ast
::
Mutability
::
Mutable
,
recorder
::
TypeRef
));
}
ast
::
Pat
Enum
(
ref
path
,
_
)
|
ast
::
Pat
QPath
(
_
,
ref
path
)
=>
{
PatKind
::
Enum
(
ref
path
,
_
)
|
PatKind
::
QPath
(
_
,
ref
path
)
=>
{
self
.collected_paths
.push
((
p
.id
,
path
.clone
(),
ast
::
Mutability
::
Mutable
,
recorder
::
VarRef
));
}
ast
::
Pat
Ident
(
bm
,
ref
path1
,
_
)
=>
{
PatKind
::
Ident
(
bm
,
ref
path1
,
_
)
=>
{
debug!
(
"PathCollector, visit ident in pat {}: {:?} {:?}"
,
path1
.node
,
p
.span
,
...
...
src/libsyntax/ast.rs
浏览文件 @
14adc9bb
...
...
@@ -10,7 +10,6 @@
// The Rust abstract syntax tree.
pub
use
self
::
Pat_
::
*
;
pub
use
self
::
StructFieldKind
::
*
;
pub
use
self
::
TyParamBound
::
*
;
pub
use
self
::
UnsafeSource
::
*
;
...
...
@@ -521,7 +520,7 @@ pub struct Block {
#[derive(Clone,
PartialEq,
Eq,
RustcEncodable,
RustcDecodable,
Hash)]
pub
struct
Pat
{
pub
id
:
NodeId
,
pub
node
:
Pat
_
,
pub
node
:
Pat
Kind
,
pub
span
:
Span
,
}
...
...
@@ -552,11 +551,11 @@ pub enum BindingMode {
}
#[derive(Clone,
PartialEq,
Eq,
RustcEncodable,
RustcDecodable,
Hash,
Debug)]
pub
enum
Pat
_
{
pub
enum
Pat
Kind
{
/// Represents a wildcard pattern (`_`)
Pat
Wild
,
Wild
,
/// A PatIdent may either be a new bound variable,
/// A Pat
Kind::
Ident may either be a new bound variable,
/// or a nullary enum (in which case the third field
/// is None).
///
...
...
@@ -564,35 +563,35 @@ pub enum Pat_ {
/// which it is. The resolver determines this, and
/// records this pattern's NodeId in an auxiliary
/// set (of "PatIdents that refer to nullary enums")
Pat
Ident
(
BindingMode
,
SpannedIdent
,
Option
<
P
<
Pat
>>
),
Ident
(
BindingMode
,
SpannedIdent
,
Option
<
P
<
Pat
>>
),
/// "None" means a `Variant(..)` pattern where we don't bind the fields to names.
Pat
Enum
(
Path
,
Option
<
Vec
<
P
<
Pat
>>>
),
Enum
(
Path
,
Option
<
Vec
<
P
<
Pat
>>>
),
/// An associated const named using the qualified path `<T>::CONST` or
/// `<T as Trait>::CONST`. Associated consts from inherent impls can be
/// referred to as simply `T::CONST`, in which case they will end up as
/// PatEnum, and the resolver will have to sort that out.
Pat
QPath
(
QSelf
,
Path
),
/// Pat
Kind::
Enum, and the resolver will have to sort that out.
QPath
(
QSelf
,
Path
),
/// Destructuring of a struct, e.g. `Foo {x, y, ..}`
/// The `bool` is `true` in the presence of a `..`
Pat
Struct
(
Path
,
Vec
<
Spanned
<
FieldPat
>>
,
bool
),
Struct
(
Path
,
Vec
<
Spanned
<
FieldPat
>>
,
bool
),
/// A tuple pattern `(a, b)`
Pat
Tup
(
Vec
<
P
<
Pat
>>
),
Tup
(
Vec
<
P
<
Pat
>>
),
/// A `box` pattern
Pat
Box
(
P
<
Pat
>
),
Box
(
P
<
Pat
>
),
/// A reference pattern, e.g. `&mut (a, b)`
PatRegion
(
P
<
Pat
>
,
Mutability
),
Ref
(
P
<
Pat
>
,
Mutability
),
/// A literal
Pat
Lit
(
P
<
Expr
>
),
Lit
(
P
<
Expr
>
),
/// A range pattern, e.g. `1...2`
Pat
Range
(
P
<
Expr
>
,
P
<
Expr
>
),
Range
(
P
<
Expr
>
,
P
<
Expr
>
),
/// `[a, b, ..i, y, z]` is represented as:
/// `PatVec(box [a, b], Some(i), box [y, z])`
Pat
Vec
(
Vec
<
P
<
Pat
>>
,
Option
<
P
<
Pat
>>
,
Vec
<
P
<
Pat
>>
),
/// `Pat
Kind::
Vec(box [a, b], Some(i), box [y, z])`
Vec
(
Vec
<
P
<
Pat
>>
,
Option
<
P
<
Pat
>>
,
Vec
<
P
<
Pat
>>
),
/// A macro pattern; pre-expansion
Pat
Mac
(
Mac
),
Mac
(
Mac
),
}
#[derive(Clone,
PartialEq,
Eq,
RustcEncodable,
RustcDecodable,
Hash,
Debug,
Copy)]
...
...
@@ -1609,7 +1608,7 @@ pub fn new_self(span: Span, mutability: Mutability, self_ident: Ident) -> Arg {
}),
pat
:
P
(
Pat
{
id
:
DUMMY_NODE_ID
,
node
:
PatIdent
(
BindingMode
::
ByValue
(
mutability
),
path
,
None
),
node
:
Pat
Kind
::
Ident
(
BindingMode
::
ByValue
(
mutability
),
path
,
None
),
span
:
span
}),
id
:
DUMMY_NODE_ID
...
...
src/libsyntax/ast_util.rs
浏览文件 @
14adc9bb
...
...
@@ -69,7 +69,7 @@ pub fn ident_to_pat(id: NodeId, s: Span, i: Ident) -> P<Pat> {
let
spanned
=
codemap
::
Spanned
{
span
:
s
,
node
:
i
};
P
(
Pat
{
id
:
id
,
node
:
PatIdent
(
BindingMode
::
ByValue
(
Mutability
::
Immutable
),
spanned
,
None
),
node
:
Pat
Kind
::
Ident
(
BindingMode
::
ByValue
(
Mutability
::
Immutable
),
spanned
,
None
),
span
:
s
})
}
...
...
@@ -348,7 +348,7 @@ pub fn compute_id_range_for_fn_body(fk: FnKind,
/// and false otherwise.
pub
fn
pat_is_ident
(
pat
:
P
<
ast
::
Pat
>
)
->
bool
{
match
pat
.node
{
ast
::
Pat
Ident
(
..
)
=>
true
,
PatKind
::
Ident
(
..
)
=>
true
,
_
=>
false
,
}
}
...
...
src/libsyntax/ext/base.rs
浏览文件 @
14adc9bb
...
...
@@ -11,7 +11,7 @@
pub
use
self
::
SyntaxExtension
::
*
;
use
ast
;
use
ast
::
Name
;
use
ast
::
{
Name
,
PatKind
}
;
use
codemap
;
use
codemap
::{
CodeMap
,
Span
,
ExpnId
,
ExpnInfo
,
NO_EXPANSION
};
use
errors
::
DiagnosticBuilder
;
...
...
@@ -307,7 +307,7 @@ fn make_pat(self: Box<Self>) -> Option<P<ast::Pat>> {
return
Some
(
P
(
ast
::
Pat
{
id
:
ast
::
DUMMY_NODE_ID
,
span
:
e
.span
,
node
:
ast
::
Pat
Lit
(
e
),
node
:
PatKind
::
Lit
(
e
),
}));
}
}
...
...
@@ -359,7 +359,7 @@ pub fn raw_expr(sp: Span) -> P<ast::Expr> {
pub
fn
raw_pat
(
sp
:
Span
)
->
ast
::
Pat
{
ast
::
Pat
{
id
:
ast
::
DUMMY_NODE_ID
,
node
:
ast
::
Pat
Wild
,
node
:
PatKind
::
Wild
,
span
:
sp
,
}
}
...
...
src/libsyntax/ext/build.rs
浏览文件 @
14adc9bb
...
...
@@ -9,7 +9,7 @@
// except according to those terms.
use
abi
::
Abi
;
use
ast
::{
self
,
Ident
,
Generics
,
Expr
,
BlockCheckMode
,
UnOp
};
use
ast
::{
self
,
Ident
,
Generics
,
Expr
,
BlockCheckMode
,
UnOp
,
PatKind
};
use
attr
;
use
codemap
::{
Span
,
respan
,
Spanned
,
DUMMY_SP
,
Pos
};
use
ext
::
base
::
ExtCtxt
;
...
...
@@ -166,7 +166,7 @@ fn expr_struct_ident(&self, span: Span, id: ast::Ident,
fn
expr_err
(
&
self
,
span
:
Span
,
expr
:
P
<
ast
::
Expr
>
)
->
P
<
ast
::
Expr
>
;
fn
expr_try
(
&
self
,
span
:
Span
,
head
:
P
<
ast
::
Expr
>
)
->
P
<
ast
::
Expr
>
;
fn
pat
(
&
self
,
span
:
Span
,
pat
:
ast
::
Pat_
)
->
P
<
ast
::
Pat
>
;
fn
pat
(
&
self
,
span
:
Span
,
pat
:
PatKind
)
->
P
<
ast
::
Pat
>
;
fn
pat_wild
(
&
self
,
span
:
Span
)
->
P
<
ast
::
Pat
>
;
fn
pat_lit
(
&
self
,
span
:
Span
,
expr
:
P
<
ast
::
Expr
>
)
->
P
<
ast
::
Pat
>
;
fn
pat_ident
(
&
self
,
span
:
Span
,
ident
:
ast
::
Ident
)
->
P
<
ast
::
Pat
>
;
...
...
@@ -805,14 +805,14 @@ fn expr_try(&self, sp: Span, head: P<ast::Expr>) -> P<ast::Expr> {
}
fn
pat
(
&
self
,
span
:
Span
,
pat
:
ast
::
Pat_
)
->
P
<
ast
::
Pat
>
{
fn
pat
(
&
self
,
span
:
Span
,
pat
:
PatKind
)
->
P
<
ast
::
Pat
>
{
P
(
ast
::
Pat
{
id
:
ast
::
DUMMY_NODE_ID
,
node
:
pat
,
span
:
span
})
}
fn
pat_wild
(
&
self
,
span
:
Span
)
->
P
<
ast
::
Pat
>
{
self
.pat
(
span
,
ast
::
Pat
Wild
)
self
.pat
(
span
,
PatKind
::
Wild
)
}
fn
pat_lit
(
&
self
,
span
:
Span
,
expr
:
P
<
ast
::
Expr
>
)
->
P
<
ast
::
Pat
>
{
self
.pat
(
span
,
ast
::
Pat
Lit
(
expr
))
self
.pat
(
span
,
PatKind
::
Lit
(
expr
))
}
fn
pat_ident
(
&
self
,
span
:
Span
,
ident
:
ast
::
Ident
)
->
P
<
ast
::
Pat
>
{
let
binding_mode
=
ast
::
BindingMode
::
ByValue
(
ast
::
Mutability
::
Immutable
);
...
...
@@ -823,20 +823,20 @@ fn pat_ident_binding_mode(&self,
span
:
Span
,
ident
:
ast
::
Ident
,
bm
:
ast
::
BindingMode
)
->
P
<
ast
::
Pat
>
{
let
pat
=
ast
::
Pat
Ident
(
bm
,
Spanned
{
span
:
span
,
node
:
ident
},
None
);
let
pat
=
PatKind
::
Ident
(
bm
,
Spanned
{
span
:
span
,
node
:
ident
},
None
);
self
.pat
(
span
,
pat
)
}
fn
pat_enum
(
&
self
,
span
:
Span
,
path
:
ast
::
Path
,
subpats
:
Vec
<
P
<
ast
::
Pat
>>
)
->
P
<
ast
::
Pat
>
{
let
pat
=
ast
::
Pat
Enum
(
path
,
Some
(
subpats
));
let
pat
=
PatKind
::
Enum
(
path
,
Some
(
subpats
));
self
.pat
(
span
,
pat
)
}
fn
pat_struct
(
&
self
,
span
:
Span
,
path
:
ast
::
Path
,
field_pats
:
Vec
<
Spanned
<
ast
::
FieldPat
>>
)
->
P
<
ast
::
Pat
>
{
let
pat
=
ast
::
Pat
Struct
(
path
,
field_pats
,
false
);
let
pat
=
PatKind
::
Struct
(
path
,
field_pats
,
false
);
self
.pat
(
span
,
pat
)
}
fn
pat_tuple
(
&
self
,
span
:
Span
,
pats
:
Vec
<
P
<
ast
::
Pat
>>
)
->
P
<
ast
::
Pat
>
{
self
.pat
(
span
,
ast
::
Pat
Tup
(
pats
))
self
.pat
(
span
,
PatKind
::
Tup
(
pats
))
}
fn
pat_some
(
&
self
,
span
:
Span
,
pat
:
P
<
ast
::
Pat
>
)
->
P
<
ast
::
Pat
>
{
...
...
src/libsyntax/ext/expand.rs
浏览文件 @
14adc9bb
...
...
@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use
ast
::{
Block
,
Crate
,
DeclKind
,
Pat
Mac
};
use
ast
::{
Block
,
Crate
,
DeclKind
,
Pat
Kind
};
use
ast
::{
Local
,
Ident
,
Mac_
,
Name
};
use
ast
::{
MacStmtStyle
,
Mrk
,
Stmt
,
StmtKind
,
ItemKind
};
use
ast
::
TokenTree
;
...
...
@@ -666,7 +666,7 @@ fn rename_in_scope<X, F>(pats: Vec<P<ast::Pat>>,
(
f
(
&
mut
rename_fld
,
fld
,
x
),
rewritten_pats
)
}
/// A visitor that extracts the PatIdent (binding) paths
/// A visitor that extracts the Pat
Kind::
Ident (binding) paths
/// from a given thingy and puts them in a mutable
/// array
#[derive(Clone)]
...
...
@@ -677,9 +677,9 @@ struct PatIdentFinder {
impl
<
'v
>
Visitor
<
'v
>
for
PatIdentFinder
{
fn
visit_pat
(
&
mut
self
,
pattern
:
&
ast
::
Pat
)
{
match
*
pattern
{
ast
::
Pat
{
id
:
_
,
node
:
ast
::
Pat
Ident
(
_
,
ref
path1
,
ref
inner
),
span
:
_
}
=>
{
ast
::
Pat
{
id
:
_
,
node
:
PatKind
::
Ident
(
_
,
ref
path1
,
ref
inner
),
span
:
_
}
=>
{
self
.ident_accumulator
.push
(
path1
.node
);
// visit optional subpattern of PatIdent:
// visit optional subpattern of Pat
Kind::
Ident:
if
let
Some
(
ref
subpat
)
=
*
inner
{
self
.visit_pat
(
subpat
)
}
...
...
@@ -690,14 +690,14 @@ fn visit_pat(&mut self, pattern: &ast::Pat) {
}
}
/// find the PatIdent paths in a pattern
/// find the Pat
Kind::
Ident paths in a pattern
fn
pattern_bindings
(
pat
:
&
ast
::
Pat
)
->
Vec
<
ast
::
Ident
>
{
let
mut
name_finder
=
PatIdentFinder
{
ident_accumulator
:
Vec
::
new
()};
name_finder
.visit_pat
(
pat
);
name_finder
.ident_accumulator
}
/// find the PatIdent paths in a
/// find the Pat
Kind::
Ident paths in a
fn
fn_decl_arg_bindings
(
fn_decl
:
&
ast
::
FnDecl
)
->
Vec
<
ast
::
Ident
>
{
let
mut
pat_idents
=
PatIdentFinder
{
ident_accumulator
:
Vec
::
new
()};
for
arg
in
&
fn_decl
.inputs
{
...
...
@@ -746,12 +746,12 @@ pub fn expand_block_elts(b: P<Block>, fld: &mut MacroExpander) -> P<Block> {
fn
expand_pat
(
p
:
P
<
ast
::
Pat
>
,
fld
:
&
mut
MacroExpander
)
->
P
<
ast
::
Pat
>
{
match
p
.node
{
PatMac
(
_
)
=>
{}
Pat
Kind
::
Mac
(
_
)
=>
{}
_
=>
return
noop_fold_pat
(
p
,
fld
)
}
p
.map
(|
ast
::
Pat
{
node
,
span
,
..
}|
{
let
(
pth
,
tts
)
=
match
node
{
PatMac
(
mac
)
=>
(
mac
.node.path
,
mac
.node.tts
),
Pat
Kind
::
Mac
(
mac
)
=>
(
mac
.node.path
,
mac
.node.tts
),
_
=>
unreachable!
()
};
if
pth
.segments
.len
()
>
1
{
...
...
@@ -840,7 +840,7 @@ fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac {
}
/// A tree-folder that applies every rename in its list to
/// the idents that are in PatIdent patterns. This is more narrowly
/// the idents that are in Pat
Kind::
Ident patterns. This is more narrowly
/// focused than IdentRenamer, and is needed for FnDecl,
/// where we want to rename the args but not the fn name or the generics etc.
pub
struct
PatIdentRenamer
<
'a
>
{
...
...
@@ -850,16 +850,16 @@ pub struct PatIdentRenamer<'a> {
impl
<
'a
>
Folder
for
PatIdentRenamer
<
'a
>
{
fn
fold_pat
(
&
mut
self
,
pat
:
P
<
ast
::
Pat
>
)
->
P
<
ast
::
Pat
>
{
match
pat
.node
{
ast
::
Pat
Ident
(
..
)
=>
{},
PatKind
::
Ident
(
..
)
=>
{},
_
=>
return
noop_fold_pat
(
pat
,
self
)
}
pat
.map
(|
ast
::
Pat
{
id
,
node
,
span
}|
match
node
{
ast
::
Pat
Ident
(
binding_mode
,
Spanned
{
span
:
sp
,
node
:
ident
},
sub
)
=>
{
PatKind
::
Ident
(
binding_mode
,
Spanned
{
span
:
sp
,
node
:
ident
},
sub
)
=>
{
let
new_ident
=
Ident
::
new
(
ident
.name
,
mtwt
::
apply_renames
(
self
.renames
,
ident
.ctxt
));
let
new_node
=
ast
::
Pat
Ident
(
binding_mode
,
PatKind
::
Ident
(
binding_mode
,
Spanned
{
span
:
self
.new_span
(
sp
),
node
:
new_ident
},
sub
.map
(|
p
|
self
.fold_pat
(
p
)));
ast
::
Pat
{
...
...
src/libsyntax/feature_gate.rs
浏览文件 @
14adc9bb
...
...
@@ -27,7 +27,7 @@
use
self
::
AttributeGate
::
*
;
use
abi
::
Abi
;
use
ast
::
NodeId
;
use
ast
::
{
NodeId
,
PatKind
}
;
use
ast
;
use
attr
;
use
attr
::
AttrMetaMethods
;
...
...
@@ -1005,19 +1005,19 @@ fn visit_expr(&mut self, e: &ast::Expr) {
fn
visit_pat
(
&
mut
self
,
pattern
:
&
ast
::
Pat
)
{
match
pattern
.node
{
ast
::
Pat
Vec
(
_
,
Some
(
_
),
ref
last
)
if
!
last
.is_empty
()
=>
{
PatKind
::
Vec
(
_
,
Some
(
_
),
ref
last
)
if
!
last
.is_empty
()
=>
{
self
.gate_feature
(
"advanced_slice_patterns"
,
pattern
.span
,
"multiple-element slice matches anywhere
\
but at the end of a slice (e.g.
\
`[0, ..xs, 0]`) are experimental"
)
}
ast
::
Pat
Vec
(
..
)
=>
{
PatKind
::
Vec
(
..
)
=>
{
self
.gate_feature
(
"slice_patterns"
,
pattern
.span
,
"slice pattern syntax is experimental"
);
}
ast
::
Pat
Box
(
..
)
=>
{
PatKind
::
Box
(
..
)
=>
{
self
.gate_feature
(
"box_patterns"
,
pattern
.span
,
"box pattern syntax is experimental"
);
...
...
src/libsyntax/fold.rs
浏览文件 @
14adc9bb
...
...
@@ -1119,23 +1119,23 @@ pub fn noop_fold_pat<T: Folder>(p: P<Pat>, folder: &mut T) -> P<Pat> {
p
.map
(|
Pat
{
id
,
node
,
span
}|
Pat
{
id
:
folder
.new_id
(
id
),
node
:
match
node
{
Pat
Wild
=>
Pat
Wild
,
PatIdent
(
binding_mode
,
pth1
,
sub
)
=>
{
PatIdent
(
binding_mode
,
Pat
Kind
::
Wild
=>
PatKind
::
Wild
,
Pat
Kind
::
Ident
(
binding_mode
,
pth1
,
sub
)
=>
{
Pat
Kind
::
Ident
(
binding_mode
,
Spanned
{
span
:
folder
.new_span
(
pth1
.span
),
node
:
folder
.fold_ident
(
pth1
.node
)},
sub
.map
(|
x
|
folder
.fold_pat
(
x
)))
}
Pat
Lit
(
e
)
=>
Pat
Lit
(
folder
.fold_expr
(
e
)),
PatEnum
(
pth
,
pats
)
=>
{
PatEnum
(
folder
.fold_path
(
pth
),
Pat
Kind
::
Lit
(
e
)
=>
PatKind
::
Lit
(
folder
.fold_expr
(
e
)),
Pat
Kind
::
Enum
(
pth
,
pats
)
=>
{
Pat
Kind
::
Enum
(
folder
.fold_path
(
pth
),
pats
.map
(|
pats
|
pats
.move_map
(|
x
|
folder
.fold_pat
(
x
))))
}
PatQPath
(
qself
,
pth
)
=>
{
Pat
Kind
::
QPath
(
qself
,
pth
)
=>
{
let
qself
=
QSelf
{
ty
:
folder
.fold_ty
(
qself
.ty
),
..
qself
};
PatQPath
(
qself
,
folder
.fold_path
(
pth
))
Pat
Kind
::
QPath
(
qself
,
folder
.fold_path
(
pth
))
}
PatStruct
(
pth
,
fields
,
etc
)
=>
{
Pat
Kind
::
Struct
(
pth
,
fields
,
etc
)
=>
{
let
pth
=
folder
.fold_path
(
pth
);
let
fs
=
fields
.move_map
(|
f
|
{
Spanned
{
span
:
folder
.new_span
(
f
.span
),
...
...
@@ -1145,20 +1145,20 @@ pub fn noop_fold_pat<T: Folder>(p: P<Pat>, folder: &mut T) -> P<Pat> {
is_shorthand
:
f
.node.is_shorthand
,
}}
});
PatStruct
(
pth
,
fs
,
etc
)
Pat
Kind
::
Struct
(
pth
,
fs
,
etc
)
}
Pat
Tup
(
elts
)
=>
Pat
Tup
(
elts
.move_map
(|
x
|
folder
.fold_pat
(
x
))),
Pat
Box
(
inner
)
=>
Pat
Box
(
folder
.fold_pat
(
inner
)),
Pat
Region
(
inner
,
mutbl
)
=>
PatRegion
(
folder
.fold_pat
(
inner
),
mutbl
),
PatRange
(
e1
,
e2
)
=>
{
PatRange
(
folder
.fold_expr
(
e1
),
folder
.fold_expr
(
e2
))
Pat
Kind
::
Tup
(
elts
)
=>
PatKind
::
Tup
(
elts
.move_map
(|
x
|
folder
.fold_pat
(
x
))),
Pat
Kind
::
Box
(
inner
)
=>
PatKind
::
Box
(
folder
.fold_pat
(
inner
)),
Pat
Kind
::
Ref
(
inner
,
mutbl
)
=>
PatKind
::
Ref
(
folder
.fold_pat
(
inner
),
mutbl
),
Pat
Kind
::
Range
(
e1
,
e2
)
=>
{
Pat
Kind
::
Range
(
folder
.fold_expr
(
e1
),
folder
.fold_expr
(
e2
))
},
PatVec
(
before
,
slice
,
after
)
=>
{
PatVec
(
before
.move_map
(|
x
|
folder
.fold_pat
(
x
)),
Pat
Kind
::
Vec
(
before
,
slice
,
after
)
=>
{
Pat
Kind
::
Vec
(
before
.move_map
(|
x
|
folder
.fold_pat
(
x
)),
slice
.map
(|
x
|
folder
.fold_pat
(
x
)),
after
.move_map
(|
x
|
folder
.fold_pat
(
x
)))
}
Pat
Mac
(
mac
)
=>
Pat
Mac
(
folder
.fold_mac
(
mac
))
Pat
Kind
::
Mac
(
mac
)
=>
PatKind
::
Mac
(
folder
.fold_mac
(
mac
))
},
span
:
folder
.new_span
(
span
)
})
...
...
src/libsyntax/parse/mod.rs
浏览文件 @
14adc9bb
...
...
@@ -675,7 +675,7 @@ mod tests {
use
super
::
*
;
use
std
::
rc
::
Rc
;
use
codemap
::{
Span
,
BytePos
,
Pos
,
Spanned
,
NO_EXPANSION
};
use
ast
::{
self
,
TokenTree
};
use
ast
::{
self
,
TokenTree
,
PatKind
};
use
abi
::
Abi
;
use
attr
::{
first_attr_value_str_by_name
,
AttrMetaMethods
};
use
parse
;
...
...
@@ -896,7 +896,7 @@ fn parser_done(p: Parser){
assert
!
(
panictry!
(
parser
.parse_pat
())
==
P
(
ast
::
Pat
{
id
:
ast
::
DUMMY_NODE_ID
,
node
:
ast
::
Pat
Ident
(
ast
::
BindingMode
::
ByValue
(
ast
::
Mutability
::
Immutable
),
node
:
PatKind
::
Ident
(
ast
::
BindingMode
::
ByValue
(
ast
::
Mutability
::
Immutable
),
Spanned
{
span
:
sp
(
0
,
1
),
node
:
str_to_ident
(
"b"
)
},
...
...
@@ -931,7 +931,7 @@ fn parser_done(p: Parser){
}),
pat
:
P
(
ast
::
Pat
{
id
:
ast
::
DUMMY_NODE_ID
,
node
:
ast
::
Pat
Ident
(
node
:
PatKind
::
Ident
(
ast
::
BindingMode
::
ByValue
(
ast
::
Mutability
::
Immutable
),
Spanned
{
span
:
sp
(
6
,
7
),
...
...
@@ -1020,7 +1020,7 @@ struct PatIdentVisitor {
impl
<
'v
>
::
visit
::
Visitor
<
'v
>
for
PatIdentVisitor
{
fn
visit_pat
(
&
mut
self
,
p
:
&
'v
ast
::
Pat
)
{
match
p
.node
{
ast
::
Pat
Ident
(
_
,
ref
spannedident
,
_
)
=>
{
PatKind
::
Ident
(
_
,
ref
spannedident
,
_
)
=>
{
self
.spans
.push
(
spannedident
.span
.clone
());
}
_
=>
{
...
...
src/libsyntax/parse/parser.rs
浏览文件 @
14adc9bb
...
...
@@ -30,8 +30,7 @@
use
ast
::
Mac_
;
use
ast
::{
MutTy
,
Mutability
};
use
ast
::
NamedField
;
use
ast
::{
Pat
,
PatBox
,
PatEnum
,
PatIdent
,
PatLit
,
PatQPath
,
PatMac
,
PatRange
};
use
ast
::{
PatRegion
,
PatStruct
,
PatTup
,
PatVec
,
PatWild
};
use
ast
::{
Pat
,
PatKind
};
use
ast
::{
PolyTraitRef
,
QSelf
};
use
ast
::{
Stmt
,
StmtKind
};
use
ast
::{
VariantData
,
StructField
};
...
...
@@ -3292,7 +3291,7 @@ fn parse_pat_vec_elements(
self
.check
(
&
token
::
CloseDelim
(
token
::
Bracket
))
{
slice
=
Some
(
P
(
ast
::
Pat
{
id
:
ast
::
DUMMY_NODE_ID
,
node
:
PatWild
,
node
:
Pat
Kind
::
Wild
,
span
:
self
.span
,
}));
before_slice
=
false
;
...
...
@@ -3370,14 +3369,14 @@ fn parse_pat_fields(&mut self) -> PResult<'a, (Vec<codemap::Spanned<ast::FieldPa
let
fieldpath
=
codemap
::
Spanned
{
span
:
self
.last_span
,
node
:
fieldname
};
let
fieldpat
=
P
(
ast
::
Pat
{
id
:
ast
::
DUMMY_NODE_ID
,
node
:
PatIdent
(
bind_type
,
fieldpath
,
None
),
node
:
Pat
Kind
::
Ident
(
bind_type
,
fieldpath
,
None
),
span
:
mk_sp
(
boxed_span_lo
,
hi
),
});
let
subpat
=
if
is_box
{
P
(
ast
::
Pat
{
id
:
ast
::
DUMMY_NODE_ID
,
node
:
PatBox
(
fieldpat
),
node
:
Pat
Kind
::
Box
(
fieldpat
),
span
:
mk_sp
(
lo
,
hi
),
})
}
else
{
...
...
@@ -3429,7 +3428,7 @@ pub fn parse_pat(&mut self) -> PResult<'a, P<Pat>> {
token
::
Underscore
=>
{
// Parse _
self
.bump
();
pat
=
PatWild
;
pat
=
Pat
Kind
::
Wild
;
}
token
::
BinOp
(
token
::
And
)
|
token
::
AndAnd
=>
{
// Parse &pat / &mut pat
...
...
@@ -3440,21 +3439,21 @@ pub fn parse_pat(&mut self) -> PResult<'a, P<Pat>> {
}
let
subpat
=
try!
(
self
.parse_pat
());
pat
=
Pat
Region
(
subpat
,
mutbl
);
pat
=
Pat
Kind
::
Ref
(
subpat
,
mutbl
);
}
token
::
OpenDelim
(
token
::
Paren
)
=>
{
// Parse (pat,pat,pat,...) as tuple pattern
self
.bump
();
let
fields
=
try!
(
self
.parse_pat_tuple_elements
());
try!
(
self
.expect
(
&
token
::
CloseDelim
(
token
::
Paren
)));
pat
=
PatTup
(
fields
);
pat
=
Pat
Kind
::
Tup
(
fields
);
}
token
::
OpenDelim
(
token
::
Bracket
)
=>
{
// Parse [pat,pat,...] as slice pattern
self
.bump
();
let
(
before
,
slice
,
after
)
=
try!
(
self
.parse_pat_vec_elements
());
try!
(
self
.expect
(
&
token
::
CloseDelim
(
token
::
Bracket
)));
pat
=
PatVec
(
before
,
slice
,
after
);
pat
=
Pat
Kind
::
Vec
(
before
,
slice
,
after
);
}
_
=>
{
// At this point, token != _, &, &&, (, [
...
...
@@ -3468,7 +3467,7 @@ pub fn parse_pat(&mut self) -> PResult<'a, P<Pat>> {
}
else
if
self
.eat_keyword
(
keywords
::
Box
)
{
// Parse box pat
let
subpat
=
try!
(
self
.parse_pat
());
pat
=
PatBox
(
subpat
);
pat
=
Pat
Kind
::
Box
(
subpat
);
}
else
if
self
.is_path_start
()
{
// Parse pattern starting with a path
if
self
.token
.is_plain_ident
()
&&
self
.look_ahead
(
1
,
|
t
|
*
t
!=
token
::
DotDotDot
&&
...
...
@@ -3487,7 +3486,7 @@ pub fn parse_pat(&mut self) -> PResult<'a, P<Pat>> {
let
tts
=
try!
(
self
.parse_seq_to_end
(
&
token
::
CloseDelim
(
delim
),
seq_sep_none
(),
|
p
|
p
.parse_token_tree
()));
let
mac
=
Mac_
{
path
:
path
,
tts
:
tts
,
ctxt
:
EMPTY_CTXT
};
pat
=
PatMac
(
codemap
::
Spanned
{
node
:
mac
,
pat
=
Pat
Kind
::
Mac
(
codemap
::
Spanned
{
node
:
mac
,
span
:
mk_sp
(
lo
,
self
.last_span.hi
)});
}
else
{
// Parse ident @ pat
...
...
@@ -3513,7 +3512,7 @@ pub fn parse_pat(&mut self) -> PResult<'a, P<Pat>> {
let
begin
=
self
.mk_expr
(
lo
,
hi
,
ExprKind
::
Path
(
qself
,
path
),
None
);
self
.bump
();
let
end
=
try!
(
self
.parse_pat_range_end
());
pat
=
PatRange
(
begin
,
end
);
pat
=
Pat
Kind
::
Range
(
begin
,
end
);
}
token
::
OpenDelim
(
token
::
Brace
)
=>
{
if
qself
.is_some
()
{
...
...
@@ -3523,7 +3522,7 @@ pub fn parse_pat(&mut self) -> PResult<'a, P<Pat>> {
self
.bump
();
let
(
fields
,
etc
)
=
try!
(
self
.parse_pat_fields
());
self
.bump
();
pat
=
PatStruct
(
path
,
fields
,
etc
);
pat
=
Pat
Kind
::
Struct
(
path
,
fields
,
etc
);
}
token
::
OpenDelim
(
token
::
Paren
)
=>
{
if
qself
.is_some
()
{
...
...
@@ -3535,22 +3534,22 @@ pub fn parse_pat(&mut self) -> PResult<'a, P<Pat>> {
self
.bump
();
self
.bump
();
try!
(
self
.expect
(
&
token
::
CloseDelim
(
token
::
Paren
)));
pat
=
PatEnum
(
path
,
None
);
pat
=
Pat
Kind
::
Enum
(
path
,
None
);
}
else
{
let
args
=
try!
(
self
.parse_enum_variant_seq
(
&
token
::
OpenDelim
(
token
::
Paren
),
&
token
::
CloseDelim
(
token
::
Paren
),
seq_sep_trailing_allowed
(
token
::
Comma
),
|
p
|
p
.parse_pat
()));
pat
=
PatEnum
(
path
,
Some
(
args
));
pat
=
Pat
Kind
::
Enum
(
path
,
Some
(
args
));
}
}
_
=>
{
pat
=
match
qself
{
// Parse qualified path
Some
(
qself
)
=>
PatQPath
(
qself
,
path
),
Some
(
qself
)
=>
Pat
Kind
::
QPath
(
qself
,
path
),
// Parse nullary enum
None
=>
PatEnum
(
path
,
Some
(
vec!
[]))
None
=>
Pat
Kind
::
Enum
(
path
,
Some
(
vec!
[]))
};
}
}
...
...
@@ -3560,9 +3559,9 @@ pub fn parse_pat(&mut self) -> PResult<'a, P<Pat>> {
let
begin
=
try!
(
self
.parse_pat_literal_maybe_minus
());
if
self
.eat
(
&
token
::
DotDotDot
)
{
let
end
=
try!
(
self
.parse_pat_range_end
());
pat
=
PatRange
(
begin
,
end
);
pat
=
Pat
Kind
::
Range
(
begin
,
end
);
}
else
{
pat
=
PatLit
(
begin
);
pat
=
Pat
Kind
::
Lit
(
begin
);
}
}
}
...
...
@@ -3581,7 +3580,7 @@ pub fn parse_pat(&mut self) -> PResult<'a, P<Pat>> {
/// error message when parsing mistakes like ref foo(a,b)
fn
parse_pat_ident
(
&
mut
self
,
binding_mode
:
ast
::
BindingMode
)
->
PResult
<
'a
,
ast
::
Pat_
>
{
->
PResult
<
'a
,
PatKind
>
{
if
!
self
.token
.is_plain_ident
()
{
let
span
=
self
.span
;
let
tok_str
=
self
.this_token_to_string
();
...
...
@@ -3610,7 +3609,7 @@ fn parse_pat_ident(&mut self,
"expected identifier, found enum pattern"
))
}
Ok
(
PatIdent
(
binding_mode
,
name
,
sub
))
Ok
(
Pat
Kind
::
Ident
(
binding_mode
,
name
,
sub
))
}
/// Parse a local variable declaration
...
...
src/libsyntax/print/pprust.rs
浏览文件 @
14adc9bb
...
...
@@ -11,7 +11,7 @@
pub
use
self
::
AnnNode
::
*
;
use
abi
::{
self
,
Abi
};
use
ast
::{
self
,
TokenTree
,
BlockCheckMode
};
use
ast
::{
self
,
TokenTree
,
BlockCheckMode
,
PatKind
};
use
ast
::{
RegionTyParamBound
,
TraitTyParamBound
,
TraitBoundModifier
};
use
ast
::
Attribute
;
use
attr
::
ThinAttributesExt
;
...
...
@@ -2457,8 +2457,8 @@ pub fn print_pat(&mut self, pat: &ast::Pat) -> io::Result<()> {
/* Pat isn't normalized, but the beauty of it
is that it doesn't matter */
match
pat
.node
{
ast
::
Pat
Wild
=>
try!
(
word
(
&
mut
self
.s
,
"_"
)),
ast
::
Pat
Ident
(
binding_mode
,
ref
path1
,
ref
sub
)
=>
{
PatKind
::
Wild
=>
try!
(
word
(
&
mut
self
.s
,
"_"
)),
PatKind
::
Ident
(
binding_mode
,
ref
path1
,
ref
sub
)
=>
{
match
binding_mode
{
ast
::
BindingMode
::
ByRef
(
mutbl
)
=>
{
try!
(
self
.word_nbsp
(
"ref"
));
...
...
@@ -2478,7 +2478,7 @@ pub fn print_pat(&mut self, pat: &ast::Pat) -> io::Result<()> {
None
=>
()
}
}
ast
::
Pat
Enum
(
ref
path
,
ref
args_
)
=>
{
PatKind
::
Enum
(
ref
path
,
ref
args_
)
=>
{
try!
(
self
.print_path
(
path
,
true
,
0
));
match
*
args_
{
None
=>
try!
(
word
(
&
mut
self
.s
,
"(..)"
)),
...
...
@@ -2492,10 +2492,10 @@ pub fn print_pat(&mut self, pat: &ast::Pat) -> io::Result<()> {
}
}
}
ast
::
Pat
QPath
(
ref
qself
,
ref
path
)
=>
{
PatKind
::
QPath
(
ref
qself
,
ref
path
)
=>
{
try!
(
self
.print_qpath
(
path
,
qself
,
false
));
}
ast
::
Pat
Struct
(
ref
path
,
ref
fields
,
etc
)
=>
{
PatKind
::
Struct
(
ref
path
,
ref
fields
,
etc
)
=>
{
try!
(
self
.print_path
(
path
,
true
,
0
));
try!
(
self
.nbsp
());
try!
(
self
.word_space
(
"{"
));
...
...
@@ -2518,7 +2518,7 @@ pub fn print_pat(&mut self, pat: &ast::Pat) -> io::Result<()> {
try!
(
space
(
&
mut
self
.s
));
try!
(
word
(
&
mut
self
.s
,
"}"
));
}
ast
::
Pat
Tup
(
ref
elts
)
=>
{
PatKind
::
Tup
(
ref
elts
)
=>
{
try!
(
self
.popen
());
try!
(
self
.commasep
(
Inconsistent
,
&
elts
[
..
],
...
...
@@ -2528,32 +2528,32 @@ pub fn print_pat(&mut self, pat: &ast::Pat) -> io::Result<()> {
}
try!
(
self
.pclose
());
}
ast
::
Pat
Box
(
ref
inner
)
=>
{
PatKind
::
Box
(
ref
inner
)
=>
{
try!
(
word
(
&
mut
self
.s
,
"box "
));
try!
(
self
.print_pat
(
&
inner
));
}
ast
::
PatRegion
(
ref
inner
,
mutbl
)
=>
{
PatKind
::
Ref
(
ref
inner
,
mutbl
)
=>
{
try!
(
word
(
&
mut
self
.s
,
"&"
));
if
mutbl
==
ast
::
Mutability
::
Mutable
{
try!
(
word
(
&
mut
self
.s
,
"mut "
));
}
try!
(
self
.print_pat
(
&
inner
));
}
ast
::
PatLit
(
ref
e
)
=>
try!
(
self
.print_expr
(
&
e
)),
ast
::
Pat
Range
(
ref
begin
,
ref
end
)
=>
{
PatKind
::
Lit
(
ref
e
)
=>
try!
(
self
.print_expr
(
&**
e
)),
PatKind
::
Range
(
ref
begin
,
ref
end
)
=>
{
try!
(
self
.print_expr
(
&
begin
));
try!
(
space
(
&
mut
self
.s
));
try!
(
word
(
&
mut
self
.s
,
"..."
));
try!
(
self
.print_expr
(
&
end
));
}
ast
::
Pat
Vec
(
ref
before
,
ref
slice
,
ref
after
)
=>
{
PatKind
::
Vec
(
ref
before
,
ref
slice
,
ref
after
)
=>
{
try!
(
word
(
&
mut
self
.s
,
"["
));
try!
(
self
.commasep
(
Inconsistent
,
&
before
[
..
],
|
s
,
p
|
s
.print_pat
(
&
p
)));
if
let
Some
(
ref
p
)
=
*
slice
{
if
!
before
.is_empty
()
{
try!
(
self
.word_space
(
","
));
}
if
p
.node
!=
ast
::
Pat
Wild
{
if
p
.node
!=
PatKind
::
Wild
{
try!
(
self
.print_pat
(
&
p
));
}
try!
(
word
(
&
mut
self
.s
,
".."
));
...
...
@@ -2564,7 +2564,7 @@ pub fn print_pat(&mut self, pat: &ast::Pat) -> io::Result<()> {
|
s
,
p
|
s
.print_pat
(
&
p
)));
try!
(
word
(
&
mut
self
.s
,
"]"
));
}
ast
::
Pat
Mac
(
ref
m
)
=>
try!
(
self
.print_mac
(
m
,
token
::
Paren
)),
PatKind
::
Mac
(
ref
m
)
=>
try!
(
self
.print_mac
(
m
,
token
::
Paren
)),
}
self
.ann
.post
(
self
,
NodePat
(
pat
))
}
...
...
@@ -2671,7 +2671,7 @@ pub fn print_fn_args(&mut self, decl: &ast::FnDecl,
let
m
=
match
*
explicit_self
{
ast
::
SelfKind
::
Static
=>
ast
::
Mutability
::
Immutable
,
_
=>
match
decl
.inputs
[
0
]
.pat.node
{
ast
::
Pat
Ident
(
ast
::
BindingMode
::
ByValue
(
m
),
_
,
_
)
=>
m
,
PatKind
::
Ident
(
ast
::
BindingMode
::
ByValue
(
m
),
_
,
_
)
=>
m
,
_
=>
ast
::
Mutability
::
Immutable
}
};
...
...
@@ -2962,7 +2962,7 @@ pub fn print_arg(&mut self, input: &ast::Arg, is_closure: bool) -> io::Result<()
ast
::
TyKind
::
Infer
if
is_closure
=>
try!
(
self
.print_pat
(
&
input
.pat
)),
_
=>
{
match
input
.pat.node
{
ast
::
Pat
Ident
(
_
,
ref
path1
,
_
)
if
PatKind
::
Ident
(
_
,
ref
path1
,
_
)
if
path1
.node.name
==
parse
::
token
::
special_idents
::
invalid
.name
=>
{
// Do nothing.
...
...
src/libsyntax/visit.rs
浏览文件 @
14adc9bb
...
...
@@ -419,46 +419,46 @@ pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>(visitor: &mut V,
pub
fn
walk_pat
<
'v
,
V
:
Visitor
<
'v
>>
(
visitor
:
&
mut
V
,
pattern
:
&
'v
Pat
)
{
match
pattern
.node
{
PatEnum
(
ref
path
,
ref
opt_children
)
=>
{
Pat
Kind
::
Enum
(
ref
path
,
ref
opt_children
)
=>
{
visitor
.visit_path
(
path
,
pattern
.id
);
if
let
Some
(
ref
children
)
=
*
opt_children
{
walk_list!
(
visitor
,
visit_pat
,
children
);
}
}
PatQPath
(
ref
qself
,
ref
path
)
=>
{
Pat
Kind
::
QPath
(
ref
qself
,
ref
path
)
=>
{
visitor
.visit_ty
(
&
qself
.ty
);
visitor
.visit_path
(
path
,
pattern
.id
)
}
PatStruct
(
ref
path
,
ref
fields
,
_
)
=>
{
Pat
Kind
::
Struct
(
ref
path
,
ref
fields
,
_
)
=>
{
visitor
.visit_path
(
path
,
pattern
.id
);
for
field
in
fields
{
visitor
.visit_ident
(
field
.span
,
field
.node.ident
);
visitor
.visit_pat
(
&
field
.node.pat
)
}
}
PatTup
(
ref
tuple_elements
)
=>
{
Pat
Kind
::
Tup
(
ref
tuple_elements
)
=>
{
walk_list!
(
visitor
,
visit_pat
,
tuple_elements
);
}
PatBox
(
ref
subpattern
)
|
Pat
Region
(
ref
subpattern
,
_
)
=>
{
Pat
Kind
::
Box
(
ref
subpattern
)
|
Pat
Kind
::
Ref
(
ref
subpattern
,
_
)
=>
{
visitor
.visit_pat
(
subpattern
)
}
PatIdent
(
_
,
ref
pth1
,
ref
optional_subpattern
)
=>
{
Pat
Kind
::
Ident
(
_
,
ref
pth1
,
ref
optional_subpattern
)
=>
{
visitor
.visit_ident
(
pth1
.span
,
pth1
.node
);
walk_list!
(
visitor
,
visit_pat
,
optional_subpattern
);
}
PatLit
(
ref
expression
)
=>
visitor
.visit_expr
(
expression
),
PatRange
(
ref
lower_bound
,
ref
upper_bound
)
=>
{
Pat
Kind
::
Lit
(
ref
expression
)
=>
visitor
.visit_expr
(
expression
),
Pat
Kind
::
Range
(
ref
lower_bound
,
ref
upper_bound
)
=>
{
visitor
.visit_expr
(
lower_bound
);
visitor
.visit_expr
(
upper_bound
)
}
PatWild
=>
(),
PatVec
(
ref
prepatterns
,
ref
slice_pattern
,
ref
postpatterns
)
=>
{
Pat
Kind
::
Wild
=>
(),
Pat
Kind
::
Vec
(
ref
prepatterns
,
ref
slice_pattern
,
ref
postpatterns
)
=>
{
walk_list!
(
visitor
,
visit_pat
,
prepatterns
);
walk_list!
(
visitor
,
visit_pat
,
slice_pattern
);
walk_list!
(
visitor
,
visit_pat
,
postpatterns
);
}
PatMac
(
ref
mac
)
=>
visitor
.visit_mac
(
mac
),
Pat
Kind
::
Mac
(
ref
mac
)
=>
visitor
.visit_mac
(
mac
),
}
}
...
...
src/libsyntax_ext/deriving/generic/mod.rs
浏览文件 @
14adc9bb
...
...
@@ -193,7 +193,7 @@
use
std
::
vec
;
use
syntax
::
abi
::
Abi
;
use
syntax
::
ast
::{
EnumDef
,
Expr
,
Ident
,
Generics
,
VariantData
,
BinOpKind
,
self
};
use
syntax
::
ast
::{
self
,
EnumDef
,
Expr
,
Ident
,
Generics
,
VariantData
,
BinOpKind
,
PatKind
};
use
syntax
::
ast_util
;
use
syntax
::
attr
;
use
syntax
::
attr
::
AttrMetaMethods
;
...
...
@@ -1142,7 +1142,7 @@ fn build_enum_match_tuple<'b>(
variant
,
self_arg_name
,
ast
::
Mutability
::
Immutable
);
(
cx
.pat
(
sp
,
ast
::
PatRegion
(
p
,
ast
::
Mutability
::
Immutable
)),
idents
)
(
cx
.pat
(
sp
,
PatKind
::
Ref
(
p
,
ast
::
Mutability
::
Immutable
)),
idents
)
};
// A single arm has form (&VariantK, &VariantK, ...) => BodyK
...
...
@@ -1472,7 +1472,7 @@ fn create_subpatterns(&self,
->
Vec
<
P
<
ast
::
Pat
>>
{
field_paths
.iter
()
.map
(|
path
|
{
cx
.pat
(
path
.span
,
ast
::
Pat
Ident
(
ast
::
BindingMode
::
ByRef
(
mutbl
),
(
*
path
)
.clone
(),
None
))
PatKind
::
Ident
(
ast
::
BindingMode
::
ByRef
(
mutbl
),
(
*
path
)
.clone
(),
None
))
})
.collect
()
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录