Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
1f850f61
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,发现更多精彩内容 >>
提交
1f850f61
编写于
11月 26, 2019
作者:
M
Matthew Jasper
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Record temporary static references in generator witnesses
上级
797fd926
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
45 addition
and
10 deletion
+45
-10
src/librustc/ty/util.rs
src/librustc/ty/util.rs
+17
-0
src/librustc_mir/hair/cx/expr.rs
src/librustc_mir/hair/cx/expr.rs
+1
-8
src/librustc_typeck/check/generator_interior.rs
src/librustc_typeck/check/generator_interior.rs
+11
-2
src/test/ui/generator/static-reference-across-yield.rs
src/test/ui/generator/static-reference-across-yield.rs
+16
-0
未找到文件。
src/librustc/ty/util.rs
浏览文件 @
1f850f61
...
...
@@ -682,6 +682,23 @@ pub fn is_mutable_static(&self, def_id: DefId) -> bool {
self
.static_mutability
(
def_id
)
==
Some
(
hir
::
Mutability
::
Mutable
)
}
/// Get the type of the pointer to the static that we use in MIR.
pub
fn
static_ptr_ty
(
&
self
,
def_id
:
DefId
)
->
Ty
<
'tcx
>
{
// Make sure that any constants in the static's type are evaluated.
let
static_ty
=
self
.normalize_erasing_regions
(
ty
::
ParamEnv
::
empty
(),
self
.type_of
(
def_id
),
);
if
self
.is_mutable_static
(
def_id
)
{
self
.mk_mut_ptr
(
static_ty
)
}
else
if
self
.is_foreign_item
(
def_id
)
{
self
.mk_imm_ptr
(
static_ty
)
}
else
{
self
.mk_imm_ref
(
self
.lifetimes.re_erased
,
static_ty
)
}
}
/// Expands the given impl trait type, stopping if the type is recursive.
pub
fn
try_expand_impl_trait_type
(
self
,
...
...
src/librustc_mir/hair/cx/expr.rs
浏览文件 @
1f850f61
...
...
@@ -933,14 +933,7 @@ fn convert_path_expr<'a, 'tcx>(
// We encode uses of statics as a `*&STATIC` where the `&STATIC` part is
// a constant reference (or constant raw pointer for `static mut`) in MIR
Res
::
Def
(
DefKind
::
Static
,
id
)
=>
{
let
ty
=
cx
.tcx
.type_of
(
id
);
let
ty
=
if
cx
.tcx
.is_mutable_static
(
id
)
{
cx
.tcx
.mk_mut_ptr
(
ty
)
}
else
if
cx
.tcx
.is_foreign_item
(
id
)
{
cx
.tcx
.mk_imm_ptr
(
ty
)
}
else
{
cx
.tcx
.mk_imm_ref
(
cx
.tcx.lifetimes.re_static
,
ty
)
};
let
ty
=
cx
.tcx
.static_ptr_ty
(
id
);
let
ptr
=
cx
.tcx.alloc_map
.lock
()
.create_static_alloc
(
id
);
let
temp_lifetime
=
cx
.region_scope_tree
.temporary_scope
(
expr
.hir_id.local_id
);
ExprKind
::
Deref
{
arg
:
Expr
{
...
...
src/librustc_typeck/check/generator_interior.rs
浏览文件 @
1f850f61
...
...
@@ -185,6 +185,8 @@ fn visit_pat(&mut self, pat: &'tcx Pat) {
}
fn
visit_expr
(
&
mut
self
,
expr
:
&
'tcx
Expr
)
{
let
scope
=
self
.region_scope_tree
.temporary_scope
(
expr
.hir_id.local_id
);
match
&
expr
.kind
{
ExprKind
::
Call
(
callee
,
args
)
=>
match
&
callee
.kind
{
ExprKind
::
Path
(
qpath
)
=>
{
...
...
@@ -210,13 +212,20 @@ fn visit_expr(&mut self, expr: &'tcx Expr) {
}
_
=>
intravisit
::
walk_expr
(
self
,
expr
),
}
ExprKind
::
Path
(
qpath
)
=>
{
let
res
=
self
.fcx.tables
.borrow
()
.qpath_res
(
qpath
,
expr
.hir_id
);
if
let
Res
::
Def
(
DefKind
::
Static
,
def_id
)
=
res
{
// Statics are lowered to temporary references or
// pointers in MIR, so record that type.
let
ptr_ty
=
self
.fcx.tcx
.static_ptr_ty
(
def_id
);
self
.record
(
ptr_ty
,
scope
,
Some
(
expr
),
expr
.span
);
}
}
_
=>
intravisit
::
walk_expr
(
self
,
expr
),
}
self
.expr_count
+=
1
;
let
scope
=
self
.region_scope_tree
.temporary_scope
(
expr
.hir_id.local_id
);
// If there are adjustments, then record the final type --
// this is the actual value that is being produced.
if
let
Some
(
adjusted_ty
)
=
self
.fcx.tables
.borrow
()
.expr_ty_adjusted_opt
(
expr
)
{
...
...
src/test/ui/generator/static-reference-across-yield.rs
0 → 100644
浏览文件 @
1f850f61
// build-pass
#![feature(generators)]
static
A
:
[
i32
;
5
]
=
[
1
,
2
,
3
,
4
,
5
];
fn
main
()
{
static
||
{
let
u
=
A
[{
yield
;
1
}];
};
static
||
{
match
A
{
i
if
{
yield
;
true
}
=>
(),
_
=>
(),
}
};
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录