Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
1713ac4b
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,发现更多精彩内容 >>
未验证
提交
1713ac4b
编写于
10月 19, 2018
作者:
V
varkor
提交者:
Dan Robertson
8月 17, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Initial implementation of or patterns
上级
ac60ca06
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
134 addition
and
26 deletion
+134
-26
src/librustc/cfg/construct.rs
src/librustc/cfg/construct.rs
+5
-0
src/librustc/hir/intravisit.rs
src/librustc/hir/intravisit.rs
+1
-0
src/librustc/hir/lowering.rs
src/librustc/hir/lowering.rs
+3
-0
src/librustc/hir/mod.rs
src/librustc/hir/mod.rs
+4
-0
src/librustc/hir/print.rs
src/librustc/hir/print.rs
+5
-1
src/librustc/middle/mem_categorization.rs
src/librustc/middle/mem_categorization.rs
+6
-0
src/librustc_mir/build/matches/mod.rs
src/librustc_mir/build/matches/mod.rs
+6
-0
src/librustc_mir/build/matches/simplify.rs
src/librustc_mir/build/matches/simplify.rs
+4
-0
src/librustc_mir/build/matches/test.rs
src/librustc_mir/build/matches/test.rs
+2
-0
src/librustc_mir/hair/pattern/_match.rs
src/librustc_mir/hair/pattern/_match.rs
+7
-3
src/librustc_mir/hair/pattern/mod.rs
src/librustc_mir/hair/pattern/mod.rs
+36
-11
src/librustc_typeck/check/_match.rs
src/librustc_typeck/check/_match.rs
+8
-0
src/librustdoc/clean/mod.rs
src/librustdoc/clean/mod.rs
+3
-0
src/libsyntax/ast.rs
src/libsyntax/ast.rs
+7
-3
src/libsyntax/mut_visit.rs
src/libsyntax/mut_visit.rs
+3
-2
src/libsyntax/print/pprust.rs
src/libsyntax/print/pprust.rs
+31
-2
src/libsyntax/visit.rs
src/libsyntax/visit.rs
+3
-4
未找到文件。
src/librustc/cfg/construct.rs
浏览文件 @
1713ac4b
...
...
@@ -140,6 +140,11 @@ fn pat(&mut self, pat: &hir::Pat, pred: CFGIndex) -> CFGIndex {
self
.add_ast_node
(
pat
.hir_id.local_id
,
&
[
pats_exit
])
}
PatKind
::
Or
(
ref
pats
)
=>
{
let
branches
:
Vec
<
_
>
=
pats
.iter
()
.map
(|
p
|
self
.pat
(
p
,
pred
))
.collect
();
self
.add_ast_node
(
pat
.hir_id.local_id
,
&
branches
)
}
PatKind
::
Slice
(
ref
pre
,
ref
vec
,
ref
post
)
=>
{
let
pre_exit
=
self
.pats_all
(
pre
.iter
(),
pred
);
let
vec_exit
=
self
.pats_all
(
vec
.iter
(),
pre_exit
);
...
...
src/librustc/hir/intravisit.rs
浏览文件 @
1713ac4b
...
...
@@ -709,6 +709,7 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
visitor
.visit_pat
(
&
field
.pat
)
}
}
PatKind
::
Or
(
ref
pats
)
=>
walk_list!
(
visitor
,
visit_pat
,
pats
),
PatKind
::
Tuple
(
ref
tuple_elements
,
_
)
=>
{
walk_list!
(
visitor
,
visit_pat
,
tuple_elements
);
}
...
...
src/librustc/hir/lowering.rs
浏览文件 @
1713ac4b
...
...
@@ -2669,6 +2669,9 @@ fn lower_pat(&mut self, p: &Pat) -> P<hir::Pat> {
let
(
pats
,
ddpos
)
=
self
.lower_pat_tuple
(
pats
,
"tuple struct"
);
hir
::
PatKind
::
TupleStruct
(
qpath
,
pats
,
ddpos
)
}
PatKind
::
Or
(
ref
pats
)
=>
{
hir
::
PatKind
::
Or
(
pats
.iter
()
.map
(|
x
|
self
.lower_pat
(
x
))
.collect
())
}
PatKind
::
Path
(
ref
qself
,
ref
path
)
=>
{
let
qpath
=
self
.lower_qpath
(
p
.id
,
...
...
src/librustc/hir/mod.rs
浏览文件 @
1713ac4b
...
...
@@ -882,6 +882,7 @@ fn walk_<G>(&self, it: &mut G) -> bool
PatKind
::
TupleStruct
(
_
,
ref
s
,
_
)
|
PatKind
::
Tuple
(
ref
s
,
_
)
=>
{
s
.iter
()
.all
(|
p
|
p
.walk_
(
it
))
}
PatKind
::
Or
(
ref
pats
)
=>
pats
.iter
()
.all
(|
p
|
p
.walk_
(
it
)),
PatKind
::
Box
(
ref
s
)
|
PatKind
::
Ref
(
ref
s
,
_
)
=>
{
s
.walk_
(
it
)
}
...
...
@@ -976,6 +977,9 @@ pub enum PatKind {
/// `0 <= position <= subpats.len()`
TupleStruct
(
QPath
,
HirVec
<
P
<
Pat
>>
,
Option
<
usize
>
),
/// An or-pattern `A | B | C`.
Or
(
Vec
<
P
<
Pat
>>
),
/// A path pattern for an unit struct/variant or a (maybe-associated) constant.
Path
(
QPath
),
...
...
src/librustc/hir/print.rs
浏览文件 @
1713ac4b
...
...
@@ -4,7 +4,7 @@
use
syntax
::
parse
::
ParseSess
;
use
syntax
::
print
::
pp
::{
self
,
Breaks
};
use
syntax
::
print
::
pp
::
Breaks
::{
Consistent
,
Inconsistent
};
use
syntax
::
print
::
pprust
::{
self
,
Comments
,
PrintState
};
use
syntax
::
print
::
pprust
::{
self
,
Comments
,
PrintState
,
SeparatorSpacing
};
use
syntax
::
symbol
::
kw
;
use
syntax
::
util
::
parser
::{
self
,
AssocOp
,
Fixity
};
use
syntax_pos
::{
self
,
BytePos
,
FileName
};
...
...
@@ -1687,6 +1687,10 @@ pub fn print_pat(&mut self, pat: &hir::Pat) {
self
.s
.space
();
self
.s
.word
(
"}"
);
}
PatKind
::
Or
(
ref
pats
)
=>
{
let
spacing
=
SeparatorSpacing
::
Both
;
self
.strsep
(
"|"
,
spacing
,
Inconsistent
,
&
pats
[
..
],
|
s
,
p
|
s
.print_pat
(
&
p
))
?
;
}
PatKind
::
Tuple
(
ref
elts
,
ddpos
)
=>
{
self
.popen
();
if
let
Some
(
ddpos
)
=
ddpos
{
...
...
src/librustc/middle/mem_categorization.rs
浏览文件 @
1713ac4b
...
...
@@ -1290,6 +1290,12 @@ fn cat_pattern_<F>(&self, mut cmt: cmt<'tcx>, pat: &hir::Pat, op: &mut F) -> McR
}
}
PatKind
::
Or
(
ref
pats
)
=>
{
for
pat
in
pats
{
self
.cat_pattern_
(
cmt
.clone
(),
&
pat
,
op
)
?
;
}
}
PatKind
::
Binding
(
..
,
Some
(
ref
subpat
))
=>
{
self
.cat_pattern_
(
cmt
,
&
subpat
,
op
)
?
;
}
...
...
src/librustc_mir/build/matches/mod.rs
浏览文件 @
1713ac4b
...
...
@@ -657,6 +657,12 @@ pub(super) fn visit_bindings(
self
.visit_bindings
(
&
subpattern
.pattern
,
subpattern_user_ty
,
f
);
}
}
PatternKind
::
Or
{
ref
pats
}
=>
{
// FIXME(#47184): extract or handle `pattern_user_ty` somehow
for
pat
in
pats
{
self
.visit_bindings
(
&
pat
,
&
pattern_user_ty
.clone
(),
f
);
}
}
}
}
}
...
...
src/librustc_mir/build/matches/simplify.rs
浏览文件 @
1713ac4b
...
...
@@ -195,6 +195,10 @@ fn simplify_match_pair<'pat>(&mut self,
candidate
.match_pairs
.push
(
MatchPair
::
new
(
place
,
subpattern
));
Ok
(())
}
PatternKind
::
Or
{
..
}
=>
{
Err
(
match_pair
)
}
}
}
}
src/librustc_mir/build/matches/test.rs
浏览文件 @
1713ac4b
...
...
@@ -87,6 +87,7 @@ pub fn test<'pat>(&mut self, match_pair: &MatchPair<'pat, 'tcx>) -> Test<'tcx> {
PatternKind
::
AscribeUserType
{
..
}
|
PatternKind
::
Array
{
..
}
|
PatternKind
::
Wild
|
PatternKind
::
Or
{
..
}
|
PatternKind
::
Binding
{
..
}
|
PatternKind
::
Leaf
{
..
}
|
PatternKind
::
Deref
{
..
}
=>
{
...
...
@@ -130,6 +131,7 @@ pub fn add_cases_to_switch<'pat>(&mut self,
PatternKind
::
Slice
{
..
}
|
PatternKind
::
Array
{
..
}
|
PatternKind
::
Wild
|
PatternKind
::
Or
{
..
}
|
PatternKind
::
Binding
{
..
}
|
PatternKind
::
AscribeUserType
{
..
}
|
PatternKind
::
Leaf
{
..
}
|
...
...
src/librustc_mir/hair/pattern/_match.rs
浏览文件 @
1713ac4b
...
...
@@ -75,9 +75,6 @@
/// D((r_1, p_(i,2), .., p_(i,n)))
/// D((r_2, p_(i,2), .., p_(i,n)))
///
/// Note that the OR-patterns are not always used directly in Rust, but are used to derive
/// the exhaustive integer matching rules, so they're written here for posterity.
///
/// The algorithm for computing `U`
/// -------------------------------
/// The algorithm is inductive (on the number of columns: i.e., components of tuple patterns).
...
...
@@ -1359,6 +1356,9 @@ fn pat_constructors<'tcx>(cx: &mut MatchCheckCtxt<'_, 'tcx>,
Some
(
vec!
[
Slice
(
pat_len
)])
}
}
PatternKind
::
Or
{
..
}
=>
{
bug!
(
"support for or-patterns has not been fully implemented yet."
);
}
}
}
...
...
@@ -1884,6 +1884,10 @@ fn specialize<'p, 'a: 'p, 'tcx>(
"unexpected ctor {:?} for slice pat"
,
constructor
)
}
}
PatternKind
::
Or
{
..
}
=>
{
bug!
(
"support for or-patterns has not been fully implemented yet."
);
}
};
debug!
(
"specialize({:#?}, {:#?}) = {:#?}"
,
r
[
0
],
wild_patterns
,
head
);
...
...
src/librustc_mir/hair/pattern/mod.rs
浏览文件 @
1713ac4b
...
...
@@ -175,6 +175,11 @@ pub enum PatternKind<'tcx> {
slice
:
Option
<
Pattern
<
'tcx
>>
,
suffix
:
Vec
<
Pattern
<
'tcx
>>
,
},
/// or-pattern
Or
{
pats
:
Vec
<
Pattern
<
'tcx
>>
,
},
}
#[derive(Copy,
Clone,
Debug,
PartialEq)]
...
...
@@ -186,6 +191,18 @@ pub struct PatternRange<'tcx> {
impl
<
'tcx
>
fmt
::
Display
for
Pattern
<
'tcx
>
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
<
'_
>
)
->
fmt
::
Result
{
// Printing lists is a chore.
let
mut
first
=
true
;
let
mut
start_or_continue
=
|
s
|
{
if
first
{
first
=
false
;
""
}
else
{
s
}
};
let
mut
start_or_comma
=
||
start_or_continue
(
", "
);
match
*
self
.kind
{
PatternKind
::
Wild
=>
write!
(
f
,
"_"
),
PatternKind
::
AscribeUserType
{
ref
subpattern
,
..
}
=>
...
...
@@ -224,9 +241,6 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
}
};
let
mut
first
=
true
;
let
mut
start_or_continue
=
||
if
first
{
first
=
false
;
""
}
else
{
", "
};
if
let
Some
(
variant
)
=
variant
{
write!
(
f
,
"{}"
,
variant
.ident
)
?
;
...
...
@@ -241,12 +255,12 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
continue
;
}
let
name
=
variant
.fields
[
p
.field
.index
()]
.ident
;
write!
(
f
,
"{}{}: {}"
,
start_or_co
ntinue
(),
name
,
p
.pattern
)
?
;
write!
(
f
,
"{}{}: {}"
,
start_or_co
mma
(),
name
,
p
.pattern
)
?
;
printed
+=
1
;
}
if
printed
<
variant
.fields
.len
()
{
write!
(
f
,
"{}.."
,
start_or_co
ntinue
())
?
;
write!
(
f
,
"{}.."
,
start_or_co
mma
())
?
;
}
return
write!
(
f
,
" }}"
);
...
...
@@ -257,7 +271,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if
num_fields
!=
0
||
variant
.is_none
()
{
write!
(
f
,
"("
)
?
;
for
i
in
0
..
num_fields
{
write!
(
f
,
"{}"
,
start_or_co
ntinue
())
?
;
write!
(
f
,
"{}"
,
start_or_co
mma
())
?
;
// Common case: the field is where we expect it.
if
let
Some
(
p
)
=
subpatterns
.get
(
i
)
{
...
...
@@ -305,14 +319,12 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
}
PatternKind
::
Slice
{
ref
prefix
,
ref
slice
,
ref
suffix
}
|
PatternKind
::
Array
{
ref
prefix
,
ref
slice
,
ref
suffix
}
=>
{
let
mut
first
=
true
;
let
mut
start_or_continue
=
||
if
first
{
first
=
false
;
""
}
else
{
", "
};
write!
(
f
,
"["
)
?
;
for
p
in
prefix
{
write!
(
f
,
"{}{}"
,
start_or_co
ntinue
(),
p
)
?
;
write!
(
f
,
"{}{}"
,
start_or_co
mma
(),
p
)
?
;
}
if
let
Some
(
ref
slice
)
=
*
slice
{
write!
(
f
,
"{}"
,
start_or_co
ntinue
())
?
;
write!
(
f
,
"{}"
,
start_or_co
mma
())
?
;
match
*
slice
.kind
{
PatternKind
::
Wild
=>
{}
_
=>
write!
(
f
,
"{}"
,
slice
)
?
...
...
@@ -320,10 +332,16 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!
(
f
,
".."
)
?
;
}
for
p
in
suffix
{
write!
(
f
,
"{}{}"
,
start_or_co
ntinue
(),
p
)
?
;
write!
(
f
,
"{}{}"
,
start_or_co
mma
(),
p
)
?
;
}
write!
(
f
,
"]"
)
}
PatternKind
::
Or
{
ref
pats
}
=>
{
for
pat
in
pats
{
write!
(
f
,
"{}{}"
,
start_or_continue
(
" | "
),
pat
)
?
;
}
Ok
(())
}
}
}
}
...
...
@@ -655,6 +673,12 @@ fn lower_pattern_unadjusted(&mut self, pat: &'tcx hir::Pat) -> Pattern<'tcx> {
self
.lower_variant_or_leaf
(
res
,
pat
.hir_id
,
pat
.span
,
ty
,
subpatterns
)
}
PatKind
::
Or
(
ref
pats
)
=>
{
PatternKind
::
Or
{
pats
:
pats
.iter
()
.map
(|
p
|
self
.lower_pattern
(
p
))
.collect
(),
}
}
};
Pattern
{
...
...
@@ -1436,6 +1460,7 @@ fn super_fold_with<F: PatternFolder<'tcx>>(&self, folder: &mut F) -> Self {
slice
:
slice
.fold_with
(
folder
),
suffix
:
suffix
.fold_with
(
folder
)
},
PatternKind
::
Or
{
ref
pats
}
=>
PatternKind
::
Or
{
pats
:
pats
.fold_with
(
folder
)
},
}
}
}
...
...
src/librustc_typeck/check/_match.rs
浏览文件 @
1713ac4b
...
...
@@ -53,6 +53,7 @@ pub fn check_pat_walk(
let
is_non_ref_pat
=
match
pat
.node
{
PatKind
::
Struct
(
..
)
|
PatKind
::
TupleStruct
(
..
)
|
PatKind
::
Or
(
_
)
|
PatKind
::
Tuple
(
..
)
|
PatKind
::
Box
(
_
)
|
PatKind
::
Range
(
..
)
|
...
...
@@ -309,6 +310,13 @@ pub fn check_pat_walk(
PatKind
::
Struct
(
ref
qpath
,
ref
fields
,
etc
)
=>
{
self
.check_pat_struct
(
pat
,
qpath
,
fields
,
etc
,
expected
,
def_bm
,
discrim_span
)
}
PatKind
::
Or
(
ref
pats
)
=>
{
let
expected_ty
=
self
.structurally_resolved_type
(
pat
.span
,
expected
);
for
pat
in
pats
{
self
.check_pat_walk
(
pat
,
expected
,
def_bm
,
false
);
}
expected_ty
}
PatKind
::
Tuple
(
ref
elements
,
ddpos
)
=>
{
let
mut
expected_len
=
elements
.len
();
if
ddpos
.is_some
()
{
...
...
src/librustdoc/clean/mod.rs
浏览文件 @
1713ac4b
...
...
@@ -4107,6 +4107,9 @@ fn name_from_pat(p: &hir::Pat) -> String {
if
etc
{
", .."
}
else
{
""
}
)
}
PatKind
::
Or
(
ref
pats
)
=>
{
pats
.iter
()
.map
(|
p
|
name_from_pat
(
&**
p
))
.collect
::
<
Vec
<
String
>>
()
.join
(
" | "
)
}
PatKind
::
Tuple
(
ref
elts
,
_
)
=>
format!
(
"({})"
,
elts
.iter
()
.map
(|
p
|
name_from_pat
(
&**
p
))
.collect
::
<
Vec
<
String
>>
()
.join
(
", "
)),
PatKind
::
Box
(
ref
p
)
=>
name_from_pat
(
&**
p
),
...
...
src/libsyntax/ast.rs
浏览文件 @
1713ac4b
...
...
@@ -572,9 +572,10 @@ pub fn walk<F>(&self, it: &mut F) -> bool
match
&
self
.node
{
PatKind
::
Ident
(
_
,
_
,
Some
(
p
))
=>
p
.walk
(
it
),
PatKind
::
Struct
(
_
,
fields
,
_
)
=>
fields
.iter
()
.all
(|
field
|
field
.pat
.walk
(
it
)),
PatKind
::
TupleStruct
(
_
,
s
)
|
PatKind
::
Tuple
(
s
)
|
PatKind
::
Slice
(
s
)
=>
{
s
.iter
()
.all
(|
p
|
p
.walk
(
it
))
}
PatKind
::
TupleStruct
(
_
,
s
)
|
PatKind
::
Tuple
(
s
)
|
PatKind
::
Slice
(
s
)
|
PatKind
::
Or
(
s
)
=>
s
.iter
()
.all
(|
p
|
p
.walk
(
it
)),
PatKind
::
Box
(
s
)
|
PatKind
::
Ref
(
s
,
_
)
|
PatKind
::
Paren
(
s
)
=>
s
.walk
(
it
),
PatKind
::
Wild
|
PatKind
::
Rest
...
...
@@ -648,6 +649,9 @@ pub enum PatKind {
/// A tuple struct/variant pattern (`Variant(x, y, .., z)`).
TupleStruct
(
Path
,
Vec
<
P
<
Pat
>>
),
/// An or-pattern `A | B | C`.
Or
(
Vec
<
P
<
Pat
>>
),
/// A possibly qualified path pattern.
/// Unqualified path patterns `A::B::C` can legally refer to variants, structs, constants
/// or associated constants. Qualified path patterns `<A>::B::C`/`<A as Trait>::B::C` can
...
...
src/libsyntax/mut_visit.rs
浏览文件 @
1713ac4b
...
...
@@ -1050,7 +1050,6 @@ pub fn noop_visit_pat<T: MutVisitor>(pat: &mut P<Pat>, vis: &mut T) {
vis
.visit_span
(
span
);
};
}
PatKind
::
Tuple
(
elems
)
=>
visit_vec
(
elems
,
|
elem
|
vis
.visit_pat
(
elem
)),
PatKind
::
Box
(
inner
)
=>
vis
.visit_pat
(
inner
),
PatKind
::
Ref
(
inner
,
_
mutbl
)
=>
vis
.visit_pat
(
inner
),
PatKind
::
Range
(
e1
,
e2
,
Spanned
{
span
:
_
,
node
:
_
})
=>
{
...
...
@@ -1058,7 +1057,9 @@ pub fn noop_visit_pat<T: MutVisitor>(pat: &mut P<Pat>, vis: &mut T) {
vis
.visit_expr
(
e2
);
vis
.visit_span
(
span
);
}
PatKind
::
Slice
(
elems
)
=>
visit_vec
(
elems
,
|
elem
|
vis
.visit_pat
(
elem
)),
PatKind
::
Tuple
(
elems
)
|
PatKind
::
Slice
(
elems
)
|
PatKind
::
Or
(
elems
)
=>
visit_vec
(
elems
,
|
elem
|
vis
.visit_pat
(
elem
)),
PatKind
::
Paren
(
inner
)
=>
vis
.visit_pat
(
inner
),
PatKind
::
Mac
(
mac
)
=>
vis
.visit_mac
(
mac
),
}
...
...
src/libsyntax/print/pprust.rs
浏览文件 @
1713ac4b
...
...
@@ -431,23 +431,48 @@ fn deref_mut(&mut self) -> &mut Self::Target {
}
}
pub
enum
SeparatorSpacing
{
After
,
Both
,
}
pub
trait
PrintState
<
'a
>
:
std
::
ops
::
Deref
<
Target
=
pp
::
Printer
>
+
std
::
ops
::
DerefMut
{
fn
comments
(
&
mut
self
)
->
&
mut
Option
<
Comments
<
'a
>>
;
fn
print_ident
(
&
mut
self
,
ident
:
ast
::
Ident
);
fn
print_generic_args
(
&
mut
self
,
args
:
&
ast
::
GenericArgs
,
colons_before_params
:
bool
);
fn
commasep
<
T
,
F
>
(
&
mut
self
,
b
:
Breaks
,
elts
:
&
[
T
],
mut
op
:
F
)
fn
strsep
<
T
,
F
>
(
&
mut
self
,
sep
:
&
'static
str
,
spacing
:
SeparatorSpacing
,
b
:
Breaks
,
elts
:
&
[
T
],
mut
op
:
F
)
->
io
::
Result
<
()
>
where
F
:
FnMut
(
&
mut
Self
,
&
T
),
{
self
.rbox
(
0
,
b
);
let
mut
first
=
true
;
for
elt
in
elts
{
if
first
{
first
=
false
;
}
else
{
self
.word_space
(
","
);
}
if
first
{
first
=
false
;
}
else
{
if
let
SeparatorSpacing
::
Both
=
spacing
{
self
.writer
()
.space
();
}
self
.word_space
(
sep
);
}
op
(
self
,
elt
);
}
self
.end
();
}
fn
commasep
<
T
,
F
>
(
&
mut
self
,
b
:
Breaks
,
elts
:
&
[
T
],
mut
op
:
F
)
where
F
:
FnMut
(
&
mut
Self
,
&
T
),
{
self
.strsep
(
","
,
SeparatorSpacing
::
After
,
b
,
elts
,
op
)
}
fn
maybe_print_comment
(
&
mut
self
,
pos
:
BytePos
)
{
while
let
Some
(
ref
cmnt
)
=
self
.next_comment
()
{
if
cmnt
.pos
<
pos
{
...
...
@@ -2353,6 +2378,10 @@ fn print_qpath(&mut self,
self
.commasep
(
Inconsistent
,
&
elts
[
..
],
|
s
,
p
|
s
.print_pat
(
p
));
self
.pclose
();
}
PatKind
::
Or
(
ref
pats
)
=>
{
let
spacing
=
SeparatorSpacing
::
Both
;
self
.strsep
(
"|"
,
spacing
,
Inconsistent
,
&
pats
[
..
],
|
s
,
p
|
s
.print_pat
(
p
))
?
;
}
PatKind
::
Path
(
None
,
ref
path
)
=>
{
self
.print_path
(
path
,
true
,
0
);
}
...
...
src/libsyntax/visit.rs
浏览文件 @
1713ac4b
...
...
@@ -447,9 +447,6 @@ pub fn walk_pat<'a, V: Visitor<'a>>(visitor: &mut V, pattern: &'a Pat) {
visitor
.visit_pat
(
&
field
.pat
)
}
}
PatKind
::
Tuple
(
ref
elems
)
=>
{
walk_list!
(
visitor
,
visit_pat
,
elems
);
}
PatKind
::
Box
(
ref
subpattern
)
|
PatKind
::
Ref
(
ref
subpattern
,
_
)
|
PatKind
::
Paren
(
ref
subpattern
)
=>
{
...
...
@@ -465,7 +462,9 @@ pub fn walk_pat<'a, V: Visitor<'a>>(visitor: &mut V, pattern: &'a Pat) {
visitor
.visit_expr
(
upper_bound
);
}
PatKind
::
Wild
|
PatKind
::
Rest
=>
{},
PatKind
::
Slice
(
ref
elems
)
=>
{
PatKind
::
Tuple
(
ref
elems
)
=>
{
|
PatKind
::
Slice
(
ref
elems
)
|
PatKind
::
Or
(
ref
elems
)
=>
{
walk_list!
(
visitor
,
visit_pat
,
elems
);
}
PatKind
::
Mac
(
ref
mac
)
=>
visitor
.visit_mac
(
mac
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录