Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
fba1926a
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,发现更多精彩内容 >>
提交
fba1926a
编写于
11月 11, 2015
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix hygiene regression in patterns
上级
b8eaa160
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
65 addition
and
14 deletion
+65
-14
src/librustc/middle/pat_util.rs
src/librustc/middle/pat_util.rs
+3
-2
src/librustc_driver/driver.rs
src/librustc_driver/driver.rs
+2
-1
src/librustc_mir/hair/cx/expr.rs
src/librustc_mir/hair/cx/expr.rs
+3
-2
src/librustc_mir/hair/cx/pattern.rs
src/librustc_mir/hair/cx/pattern.rs
+2
-1
src/librustc_trans/trans/_match.rs
src/librustc_trans/trans/_match.rs
+8
-7
src/librustc_typeck/check/_match.rs
src/librustc_typeck/check/_match.rs
+2
-1
src/test/run-pass/issue-29746.rs
src/test/run-pass/issue-29746.rs
+45
-0
未找到文件。
src/librustc/middle/pat_util.rs
浏览文件 @
fba1926a
...
...
@@ -14,6 +14,7 @@
use
util
::
nodemap
::
FnvHashMap
;
use
syntax
::
ast
;
use
syntax
::
ext
::
mtwt
;
use
rustc_front
::
hir
;
use
rustc_front
::
util
::
walk_pat
;
use
syntax
::
codemap
::{
respan
,
Span
,
Spanned
,
DUMMY_SP
};
...
...
@@ -26,8 +27,8 @@
// use the NodeId of their namesake in the first pattern.
pub
fn
pat_id_map
(
dm
:
&
RefCell
<
DefMap
>
,
pat
:
&
hir
::
Pat
)
->
PatIdMap
{
let
mut
map
=
FnvHashMap
();
pat_bindings
(
dm
,
pat
,
|
_
bm
,
p_id
,
_
s
,
path1
|
{
map
.insert
(
path1
.node
,
p_id
);
pat_bindings
_hygienic
(
dm
,
pat
,
|
_
bm
,
p_id
,
_
s
,
path1
|
{
map
.insert
(
mtwt
::
resolve
(
path1
.node
)
,
p_id
);
});
map
}
...
...
src/librustc_driver/driver.rs
浏览文件 @
fba1926a
...
...
@@ -678,8 +678,9 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
||
resolve
::
resolve_crate
(
sess
,
&
ast_map
,
make_glob_map
));
// Discard MTWT tables that aren't required past resolution.
// FIXME: get rid of uses of MTWT tables in typeck, mir and trans and clear them
if
!
sess
.opts.debugging_opts.keep_mtwt_tables
{
syntax
::
ext
::
mtwt
::
clear_tables
();
//
syntax::ext::mtwt::clear_tables();
}
let
named_region_map
=
time
(
time_passes
,
...
...
src/librustc_mir/hair/cx/expr.rs
浏览文件 @
fba1926a
...
...
@@ -22,6 +22,7 @@
use
rustc
::
middle
::
ty
::{
self
,
VariantDef
,
Ty
};
use
rustc_front
::
hir
;
use
rustc_front
::
util
as
hir_util
;
use
syntax
::
ext
::
mtwt
;
use
syntax
::
parse
::
token
;
use
syntax
::
ptr
::
P
;
...
...
@@ -490,8 +491,8 @@ fn convert_arm<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>, arm: &'tcx hir::Arm) -> Arm<
None
}
else
{
map
=
FnvHashMap
();
pat_util
::
pat_bindings
(
&
cx
.tcx.def_map
,
&
arm
.pats
[
0
],
|
_
,
p_id
,
_
,
path
|
{
map
.insert
(
path
.node
,
p_id
);
pat_util
::
pat_bindings
_hygienic
(
&
cx
.tcx.def_map
,
&
arm
.pats
[
0
],
|
_
,
p_id
,
_
,
path
|
{
map
.insert
(
mtwt
::
resolve
(
path
.node
)
,
p_id
);
});
Some
(
&
map
)
};
...
...
src/librustc_mir/hair/cx/pattern.rs
浏览文件 @
fba1926a
...
...
@@ -19,6 +19,7 @@
use
rustc
::
middle
::
ty
::{
self
,
Ty
};
use
rustc_front
::
hir
;
use
syntax
::
ast
;
use
syntax
::
ext
::
mtwt
;
use
syntax
::
ptr
::
P
;
/// When there are multiple patterns in a single arm, each one has its
...
...
@@ -161,7 +162,7 @@ fn to_pat(&mut self, pat: &'tcx hir::Pat) -> Pattern<'tcx> {
{
let
id
=
match
self
.binding_map
{
None
=>
pat
.id
,
Some
(
ref
map
)
=>
map
[
&
ident
.node.name
],
Some
(
ref
map
)
=>
map
[
&
mtwt
::
resolve
(
ident
.node
)
],
};
let
var_ty
=
self
.cx.tcx
.node_id_to_type
(
pat
.id
);
let
region
=
match
var_ty
.sty
{
...
...
src/librustc_trans/trans/_match.rs
浏览文件 @
fba1926a
...
...
@@ -228,6 +228,7 @@
use
std
::
rc
::
Rc
;
use
rustc_front
::
hir
;
use
syntax
::
ast
::{
self
,
DUMMY_NODE_ID
,
NodeId
};
use
syntax
::
ext
::
mtwt
;
use
syntax
::
codemap
::
Span
;
use
rustc_front
::
fold
::
Folder
;
use
syntax
::
ptr
::
P
;
...
...
@@ -477,7 +478,7 @@ fn expand_nested_bindings<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
loop
{
pat
=
match
pat
.node
{
hir
::
PatIdent
(
_
,
ref
path
,
Some
(
ref
inner
))
=>
{
bound_ptrs
.push
((
path
.node.name
,
val
.val
));
bound_ptrs
.push
((
mtwt
::
resolve
(
path
.node
)
,
val
.val
));
&**
inner
},
_
=>
break
...
...
@@ -518,7 +519,7 @@ fn enter_match<'a, 'b, 'p, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
match
this
.node
{
hir
::
PatIdent
(
_
,
ref
path
,
None
)
=>
{
if
pat_is_binding
(
&
dm
.borrow
(),
&*
this
)
{
bound_ptrs
.push
((
path
.node.name
,
val
.val
));
bound_ptrs
.push
((
mtwt
::
resolve
(
path
.node
)
,
val
.val
));
}
}
hir
::
PatVec
(
ref
before
,
Some
(
ref
slice
),
ref
after
)
=>
{
...
...
@@ -526,7 +527,7 @@ fn enter_match<'a, 'b, 'p, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
let
subslice_val
=
bind_subslice_pat
(
bcx
,
this
.id
,
val
,
before
.len
(),
after
.len
());
bound_ptrs
.push
((
path
.node.name
,
subslice_val
));
bound_ptrs
.push
((
mtwt
::
resolve
(
path
.node
)
,
subslice_val
));
}
}
_
=>
{}
...
...
@@ -1127,8 +1128,8 @@ fn compile_submatch<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
}
None
=>
{
let
data
=
&
m
[
0
]
.data
;
for
&
(
ref
ident
,
ref
value_ptr
)
in
&
m
[
0
]
.bound_ptrs
{
let
binfo
=
*
data
.bindings_map
.get
(
ident
)
.unwrap
();
for
&
(
ref
name
,
ref
value_ptr
)
in
&
m
[
0
]
.bound_ptrs
{
let
binfo
=
*
data
.bindings_map
.get
(
name
)
.unwrap
();
call_lifetime_start
(
bcx
,
binfo
.llmatch
);
if
binfo
.trmode
==
TrByRef
&&
type_is_fat_ptr
(
bcx
.tcx
(),
binfo
.ty
)
{
expr
::
copy_fat_ptr
(
bcx
,
*
value_ptr
,
binfo
.llmatch
);
...
...
@@ -1526,8 +1527,8 @@ fn create_bindings_map<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, pat: &hir::Pat,
let
tcx
=
bcx
.tcx
();
let
reassigned
=
is_discr_reassigned
(
bcx
,
discr
,
body
);
let
mut
bindings_map
=
FnvHashMap
();
pat_bindings
(
&
tcx
.def_map
,
&*
pat
,
|
bm
,
p_id
,
span
,
path1
|
{
let
name
=
path1
.node
;
pat_bindings
_hygienic
(
&
tcx
.def_map
,
&*
pat
,
|
bm
,
p_id
,
span
,
path1
|
{
let
name
=
mtwt
::
resolve
(
path1
.node
)
;
let
variable_ty
=
node_id_type
(
bcx
,
p_id
);
let
llvariable_ty
=
type_of
::
type_of
(
ccx
,
variable_ty
);
let
tcx
=
bcx
.tcx
();
...
...
src/librustc_typeck/check/_match.rs
浏览文件 @
fba1926a
...
...
@@ -25,6 +25,7 @@
use
std
::
cmp
;
use
std
::
collections
::
hash_map
::
Entry
::{
Occupied
,
Vacant
};
use
syntax
::
ast
;
use
syntax
::
ext
::
mtwt
;
use
syntax
::
codemap
::{
Span
,
Spanned
};
use
syntax
::
ptr
::
P
;
...
...
@@ -179,7 +180,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
// if there are multiple arms, make sure they all agree on
// what the type of the binding `x` ought to be
let
canon_id
=
*
pcx
.map
.get
(
&
path
.node.name
)
.unwrap
();
let
canon_id
=
*
pcx
.map
.get
(
&
mtwt
::
resolve
(
path
.node
)
)
.unwrap
();
if
canon_id
!=
pat
.id
{
let
ct
=
fcx
.local_ty
(
pat
.span
,
canon_id
);
demand
::
eqtype
(
fcx
,
pat
.span
,
ct
,
typ
);
...
...
src/test/run-pass/issue-29746.rs
0 → 100644
浏览文件 @
fba1926a
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// zip!(a1,a2,a3,a4) is equivalent to:
// a1.zip(a2).zip(a3).zip(a4).map(|(((x1,x2),x3),x4)| (x1,x2,x3,x4))
macro_rules!
zip
{
// Entry point
([
$a:expr
,
$b:expr
,
$
(
$rest:expr
),
*
])
=>
{
zip!
([
$
(
$rest
),
*
],
$a
.zip
(
$b
),
(
x
,
y
),
[
x
,
y
])
};
// Intermediate steps to build the zipped expression, the match pattern, and
// and the output tuple of the closure, using macro hygene to repeatedly
// introduce new variables named 'x'.
([
$a:expr
,
$
(
$rest:expr
),
*
],
$zip:expr
,
$pat:pat
,
[
$
(
$flat:expr
),
*
])
=>
{
zip!
([
$
(
$rest
),
*
],
$zip
.zip
(
$a
),
(
$pat
,
x
),
[
$
(
$flat
),
*
,
x
])
};
// Final step
([],
$zip:expr
,
$pat:pat
,
[
$
(
$flat:expr
),
+
])
=>
{
$zip
.map
(|
$pat
|
(
$
(
$flat
),
+
))
};
// Comma
([
$a:expr
],
$zip:expr
,
$pat:pat
,
[
$
(
$flat:expr
),
*
])
=>
{
zip!
([
$a
,],
$zip
,
$pat
,
[
$
(
$flat
),
*
])
};
}
fn
main
()
{
let
p1
=
vec!
[
1i32
,
2
]
.into_iter
();
let
p2
=
vec!
[
"10"
,
"20"
]
.into_iter
();
let
p3
=
vec!
[
100u16
,
200
]
.into_iter
();
let
p4
=
vec!
[
1000i64
,
2000
]
.into_iter
();
let
e
=
zip!
([
p1
,
p2
,
p3
,
p4
])
.collect
::
<
Vec
<
_
>>
();
assert_eq!
(
e
[
0
],
(
1i32
,
"10"
,
100u16
,
1000i64
));
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录