Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
8d9f4a12
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,发现更多精彩内容 >>
提交
8d9f4a12
编写于
5月 04, 2019
作者:
E
Eduard-Mihai Burtescu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rustc: rename all occurences of "freevar" to "upvar".
上级
125dc60d
变更
20
隐藏空白更改
内联
并排
Showing
20 changed file
with
94 addition
and
94 deletion
+94
-94
src/librustc/hir/def.rs
src/librustc/hir/def.rs
+1
-1
src/librustc/hir/mod.rs
src/librustc/hir/mod.rs
+8
-8
src/librustc/infer/error_reporting/note.rs
src/librustc/infer/error_reporting/note.rs
+2
-2
src/librustc/infer/mod.rs
src/librustc/infer/mod.rs
+3
-3
src/librustc/middle/expr_use_visitor.rs
src/librustc/middle/expr_use_visitor.rs
+7
-7
src/librustc/middle/liveness.rs
src/librustc/middle/liveness.rs
+8
-8
src/librustc/mir/mod.rs
src/librustc/mir/mod.rs
+6
-6
src/librustc/query/mod.rs
src/librustc/query/mod.rs
+1
-1
src/librustc/ty/context.rs
src/librustc/ty/context.rs
+4
-4
src/librustc/ty/mod.rs
src/librustc/ty/mod.rs
+2
-2
src/librustc/ty/print/pretty.rs
src/librustc/ty/print/pretty.rs
+4
-4
src/librustc_interface/passes.rs
src/librustc_interface/passes.rs
+2
-2
src/librustc_mir/borrow_check/error_reporting.rs
src/librustc_mir/borrow_check/error_reporting.rs
+4
-4
src/librustc_mir/hair/cx/expr.rs
src/librustc_mir/hair/cx/expr.rs
+9
-9
src/librustc_mir/interpret/validity.rs
src/librustc_mir/interpret/validity.rs
+1
-1
src/librustc_passes/rvalue_promotion.rs
src/librustc_passes/rvalue_promotion.rs
+1
-1
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+8
-8
src/librustc_typeck/check/coercion.rs
src/librustc_typeck/check/coercion.rs
+1
-1
src/librustc_typeck/check/upvar.rs
src/librustc_typeck/check/upvar.rs
+20
-20
src/librustc_typeck/collect.rs
src/librustc_typeck/collect.rs
+2
-2
未找到文件。
src/librustc/hir/def.rs
浏览文件 @
8d9f4a12
...
...
@@ -140,7 +140,7 @@ pub enum Res<Id = hir::HirId> {
SelfCtor
(
DefId
/* impl */
),
// `DefId` refers to the impl
Local
(
Id
),
Upvar
(
Id
,
// `HirId` of closed over local
usize
,
// index in the `
free
vars` list of the closure
usize
,
// index in the `
up
vars` list of the closure
ast
::
NodeId
),
// expr node that creates the closure
// Macro namespace
...
...
src/librustc/hir/mod.rs
浏览文件 @
8d9f4a12
...
...
@@ -2476,19 +2476,19 @@ pub fn descriptive_variant(&self) -> &str {
}
}
/// A
free variable referred to in a function
.
/// A
variable captured by a closure
.
#[derive(Debug,
Copy,
Clone,
RustcEncodable,
RustcDecodable,
HashStable)]
pub
struct
Free
var
<
Id
=
HirId
>
{
/// The variable being
accessed free
.
pub
struct
Up
var
<
Id
=
HirId
>
{
/// The variable being
captured
.
pub
res
:
Res
<
Id
>
,
// First span where it is accessed (there can be multiple).
pub
span
:
Span
}
impl
<
Id
:
fmt
::
Debug
+
Copy
>
Free
var
<
Id
>
{
pub
fn
map_id
<
R
>
(
self
,
map
:
impl
FnMut
(
Id
)
->
R
)
->
Free
var
<
R
>
{
Free
var
{
impl
<
Id
:
fmt
::
Debug
+
Copy
>
Up
var
<
Id
>
{
pub
fn
map_id
<
R
>
(
self
,
map
:
impl
FnMut
(
Id
)
->
R
)
->
Up
var
<
R
>
{
Up
var
{
res
:
self
.res
.map_id
(
map
),
span
:
self
.span
,
}
...
...
@@ -2497,12 +2497,12 @@ pub fn map_id<R>(self, map: impl FnMut(Id) -> R) -> Freevar<R> {
pub
fn
var_id
(
&
self
)
->
Id
{
match
self
.res
{
Res
::
Local
(
id
)
|
Res
::
Upvar
(
id
,
..
)
=>
id
,
_
=>
bug!
(
"
Free
var::var_id: bad res ({:?})"
,
self
.res
)
_
=>
bug!
(
"
Up
var::var_id: bad res ({:?})"
,
self
.res
)
}
}
}
pub
type
FreevarMap
=
NodeMap
<
Vec
<
Free
var
<
ast
::
NodeId
>>>
;
pub
type
UpvarMap
=
NodeMap
<
Vec
<
Up
var
<
ast
::
NodeId
>>>
;
pub
type
CaptureModeMap
=
NodeMap
<
CaptureClause
>
;
...
...
src/librustc/infer/error_reporting/note.rs
浏览文件 @
8d9f4a12
...
...
@@ -46,7 +46,7 @@ pub(super) fn note_region_origin(&self,
err
.span_note
(
span
,
"...so that pointer is not dereferenced outside its lifetime"
);
}
infer
::
FreeVariabl
e
(
span
,
id
)
=>
{
infer
::
ClosureCaptur
e
(
span
,
id
)
=>
{
err
.span_note
(
span
,
&
format!
(
"...so that captured variable `{}` does not outlive the
\
enclosing closure"
,
...
...
@@ -214,7 +214,7 @@ pub(super) fn report_concrete_failure(&self,
"the reference is only valid for "
,
sup
,
""
);
err
}
infer
::
FreeVariabl
e
(
span
,
id
)
=>
{
infer
::
ClosureCaptur
e
(
span
,
id
)
=>
{
let
mut
err
=
struct_span_err!
(
self
.tcx.sess
,
span
,
E0474
,
...
...
src/librustc/infer/mod.rs
浏览文件 @
8d9f4a12
...
...
@@ -264,8 +264,8 @@ pub enum SubregionOrigin<'tcx> {
/// Dereference of reference must be within its lifetime
DerefPointer
(
Span
),
/// Closure bound must not outlive captured
free
variables
FreeVariabl
e
(
Span
,
ast
::
NodeId
),
/// Closure bound must not outlive captured variables
ClosureCaptur
e
(
Span
,
ast
::
NodeId
),
/// Index into slice must be within its lifetime
IndexSlice
(
Span
),
...
...
@@ -1660,7 +1660,7 @@ pub fn span(&self) -> Span {
InfStackClosure
(
a
)
=>
a
,
InvokeClosure
(
a
)
=>
a
,
DerefPointer
(
a
)
=>
a
,
FreeVariabl
e
(
a
,
_
)
=>
a
,
ClosureCaptur
e
(
a
,
_
)
=>
a
,
IndexSlice
(
a
)
=>
a
,
RelateObjectBound
(
a
)
=>
a
,
RelateParamBound
(
a
,
_
)
=>
a
,
...
...
src/librustc/middle/expr_use_visitor.rs
浏览文件 @
8d9f4a12
...
...
@@ -931,9 +931,9 @@ fn walk_captures(&mut self, closure_expr: &hir::Expr, fn_decl_span: Span) {
debug!
(
"walk_captures({:?})"
,
closure_expr
);
let
closure_def_id
=
self
.tcx
()
.hir
()
.local_def_id_from_hir_id
(
closure_expr
.hir_id
);
if
let
Some
(
freevars
)
=
self
.tcx
()
.free
vars
(
closure_def_id
)
{
for
freevar
in
free
vars
.iter
()
{
let
var_hir_id
=
free
var
.var_id
();
if
let
Some
(
upvars
)
=
self
.tcx
()
.up
vars
(
closure_def_id
)
{
for
upvar
in
up
vars
.iter
()
{
let
var_hir_id
=
up
var
.var_id
();
let
upvar_id
=
ty
::
UpvarId
{
var_path
:
ty
::
UpvarPath
{
hir_id
:
var_hir_id
},
closure_expr_id
:
closure_def_id
.to_local
(),
...
...
@@ -941,14 +941,14 @@ fn walk_captures(&mut self, closure_expr: &hir::Expr, fn_decl_span: Span) {
let
upvar_capture
=
self
.mc.tables
.upvar_capture
(
upvar_id
);
let
cmt_var
=
return_if_err!
(
self
.cat_captured_var
(
closure_expr
.hir_id
,
fn_decl_span
,
free
var
));
up
var
));
match
upvar_capture
{
ty
::
UpvarCapture
::
ByValue
=>
{
let
mode
=
copy_or_move
(
&
self
.mc
,
self
.param_env
,
&
cmt_var
,
CaptureMove
);
self
.delegate
.consume
(
closure_expr
.hir_id
,
free
var
.span
,
&
cmt_var
,
mode
);
self
.delegate
.consume
(
closure_expr
.hir_id
,
up
var
.span
,
&
cmt_var
,
mode
);
}
ty
::
UpvarCapture
::
ByRef
(
upvar_borrow
)
=>
{
self
.delegate
.borrow
(
closure_expr
.hir_id
,
...
...
@@ -956,7 +956,7 @@ fn walk_captures(&mut self, closure_expr: &hir::Expr, fn_decl_span: Span) {
&
cmt_var
,
upvar_borrow
.region
,
upvar_borrow
.kind
,
ClosureCapture
(
free
var
.span
));
ClosureCapture
(
up
var
.span
));
}
}
}
...
...
@@ -966,7 +966,7 @@ fn walk_captures(&mut self, closure_expr: &hir::Expr, fn_decl_span: Span) {
fn
cat_captured_var
(
&
mut
self
,
closure_hir_id
:
hir
::
HirId
,
closure_span
:
Span
,
upvar
:
&
hir
::
Free
var
)
upvar
:
&
hir
::
Up
var
)
->
mc
::
McResult
<
mc
::
cmt_
<
'tcx
>>
{
// Create the cmt for the variable being borrowed, from the
// caller's perspective
...
...
src/librustc/middle/liveness.rs
浏览文件 @
8d9f4a12
...
...
@@ -144,7 +144,7 @@ fn get(&self) -> usize { self.0 as usize }
#[derive(Copy,
Clone,
PartialEq,
Debug)]
enum
LiveNodeKind
{
FreeV
arNode
(
Span
),
Upv
arNode
(
Span
),
ExprNode
(
Span
),
VarDefNode
(
Span
),
ExitNode
...
...
@@ -153,8 +153,8 @@ enum LiveNodeKind {
fn
live_node_kind_to_string
(
lnk
:
LiveNodeKind
,
tcx
:
TyCtxt
<
'_
,
'_
,
'_
>
)
->
String
{
let
cm
=
tcx
.sess
.source_map
();
match
lnk
{
FreeV
arNode
(
s
)
=>
{
format!
(
"
Free
var node [{}]"
,
cm
.span_to_string
(
s
))
Upv
arNode
(
s
)
=>
{
format!
(
"
Up
var node [{}]"
,
cm
.span_to_string
(
s
))
}
ExprNode
(
s
)
=>
{
format!
(
"Expr node [{}]"
,
cm
.span_to_string
(
s
))
...
...
@@ -484,11 +484,11 @@ fn visit_expr<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, expr: &'tcx Expr) {
// construction site.
let
mut
call_caps
=
Vec
::
new
();
let
closure_def_id
=
ir
.tcx
.hir
()
.local_def_id_from_hir_id
(
expr
.hir_id
);
if
let
Some
(
freevars
)
=
ir
.tcx
.free
vars
(
closure_def_id
)
{
call_caps
.extend
(
freevars
.iter
()
.filter_map
(|
free
var
|
{
if
let
Res
::
Local
(
rv
)
=
free
var
.res
{
let
freevar_ln
=
ir
.add_live_node
(
FreeVarNode
(
free
var
.span
));
Some
(
CaptureInfo
{
ln
:
free
var_ln
,
var_hid
:
rv
})
if
let
Some
(
upvars
)
=
ir
.tcx
.up
vars
(
closure_def_id
)
{
call_caps
.extend
(
upvars
.iter
()
.filter_map
(|
up
var
|
{
if
let
Res
::
Local
(
rv
)
=
up
var
.res
{
let
upvar_ln
=
ir
.add_live_node
(
UpvarNode
(
up
var
.span
));
Some
(
CaptureInfo
{
ln
:
up
var_ln
,
var_hid
:
rv
})
}
else
{
None
}
...
...
src/librustc/mir/mod.rs
浏览文件 @
8d9f4a12
...
...
@@ -2572,9 +2572,9 @@ fn fmt_tuple(fmt: &mut Formatter<'_>, places: &[Operand<'_>]) -> fmt::Result {
};
let
mut
struct_fmt
=
fmt
.debug_struct
(
&
name
);
if
let
Some
(
freevars
)
=
tcx
.free
vars
(
def_id
)
{
for
(
freevar
,
place
)
in
free
vars
.iter
()
.zip
(
places
)
{
let
var_name
=
tcx
.hir
()
.name_by_hir_id
(
free
var
.var_id
());
if
let
Some
(
upvars
)
=
tcx
.up
vars
(
def_id
)
{
for
(
upvar
,
place
)
in
up
vars
.iter
()
.zip
(
places
)
{
let
var_name
=
tcx
.hir
()
.name_by_hir_id
(
up
var
.var_id
());
struct_fmt
.field
(
&
var_name
.as_str
(),
place
);
}
}
...
...
@@ -2591,9 +2591,9 @@ fn fmt_tuple(fmt: &mut Formatter<'_>, places: &[Operand<'_>]) -> fmt::Result {
tcx
.hir
()
.span_by_hir_id
(
hir_id
));
let
mut
struct_fmt
=
fmt
.debug_struct
(
&
name
);
if
let
Some
(
freevars
)
=
tcx
.free
vars
(
def_id
)
{
for
(
freevar
,
place
)
in
free
vars
.iter
()
.zip
(
places
)
{
let
var_name
=
tcx
.hir
()
.name_by_hir_id
(
free
var
.var_id
());
if
let
Some
(
upvars
)
=
tcx
.up
vars
(
def_id
)
{
for
(
upvar
,
place
)
in
up
vars
.iter
()
.zip
(
places
)
{
let
var_name
=
tcx
.hir
()
.name_by_hir_id
(
up
var
.var_id
());
struct_fmt
.field
(
&
var_name
.as_str
(),
place
);
}
}
...
...
src/librustc/query/mod.rs
浏览文件 @
8d9f4a12
...
...
@@ -824,7 +824,7 @@
desc
{
"generating a postorder list of CrateNums"
}
}
query
freevars
(
_
:
DefId
)
->
Option
<
Lrc
<
Vec
<
hir
::
Free
var
>>>
{
query
upvars
(
_
:
DefId
)
->
Option
<
Lrc
<
Vec
<
hir
::
Up
var
>>>
{
eval_always
}
query
maybe_unused_trait_import
(
_
:
DefId
)
->
bool
{
...
...
src/librustc/ty/context.rs
浏览文件 @
8d9f4a12
...
...
@@ -1071,10 +1071,10 @@ pub struct GlobalCtxt<'tcx> {
pub
queries
:
query
::
Queries
<
'tcx
>
,
// Records the
free
variables referenced by every closure
// Records the
captured
variables referenced by every closure
// expression. Do not track deps for this, just recompute it from
// scratch every time.
freevars
:
FxHashMap
<
DefId
,
Lrc
<
Vec
<
hir
::
Free
var
>>>
,
upvars
:
FxHashMap
<
DefId
,
Lrc
<
Vec
<
hir
::
Up
var
>>>
,
maybe_unused_trait_imports
:
FxHashSet
<
DefId
>
,
maybe_unused_extern_crates
:
Vec
<
(
DefId
,
Span
)
>
,
...
...
@@ -1317,7 +1317,7 @@ pub fn create_global_ctxt(
})
.collect
();
(
k
,
Lrc
::
new
(
exports
))
})
.collect
(),
freevars
:
resolutions
.free
vars
.into_iter
()
.map
(|(
k
,
v
)|
{
upvars
:
resolutions
.up
vars
.into_iter
()
.map
(|(
k
,
v
)|
{
let
vars
:
Vec
<
_
>
=
v
.into_iter
()
.map
(|
e
|
{
e
.map_id
(|
id
|
hir
.node_to_hir_id
(
id
))
})
.collect
();
...
...
@@ -3055,7 +3055,7 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
assert_eq!
(
id
,
LOCAL_CRATE
);
Lrc
::
new
(
middle
::
lang_items
::
collect
(
tcx
))
};
providers
.
freevars
=
|
tcx
,
id
|
tcx
.gcx.free
vars
.get
(
&
id
)
.cloned
();
providers
.
upvars
=
|
tcx
,
id
|
tcx
.gcx.up
vars
.get
(
&
id
)
.cloned
();
providers
.maybe_unused_trait_import
=
|
tcx
,
id
|
{
tcx
.maybe_unused_trait_imports
.contains
(
&
id
)
};
...
...
src/librustc/ty/mod.rs
浏览文件 @
8d9f4a12
...
...
@@ -8,7 +8,7 @@
pub
use
self
::
IntVarValue
::
*
;
pub
use
self
::
fold
::
TypeFoldable
;
use
crate
::
hir
::{
map
as
hir_map
,
Free
varMap
,
GlobMap
,
TraitMap
};
use
crate
::
hir
::{
map
as
hir_map
,
Up
varMap
,
GlobMap
,
TraitMap
};
use
crate
::
hir
::
Node
;
use
crate
::
hir
::
def
::{
Res
,
DefKind
,
CtorOf
,
CtorKind
,
ExportMap
};
use
crate
::
hir
::
def_id
::{
CrateNum
,
DefId
,
LocalDefId
,
CRATE_DEF_INDEX
,
LOCAL_CRATE
};
...
...
@@ -122,7 +122,7 @@
#[derive(Clone)]
pub
struct
Resolutions
{
pub
freevars
:
Free
varMap
,
pub
upvars
:
Up
varMap
,
pub
trait_map
:
TraitMap
,
pub
maybe_unused_trait_imports
:
NodeSet
,
pub
maybe_unused_extern_crates
:
Vec
<
(
NodeId
,
Span
)
>
,
...
...
src/librustc/ty/print/pretty.rs
浏览文件 @
8d9f4a12
...
...
@@ -582,7 +582,7 @@ fn pretty_print_type(
if
let
Some
(
hir_id
)
=
self
.tcx
()
.hir
()
.as_local_hir_id
(
did
)
{
p!
(
write
(
"@{:?}"
,
self
.tcx
()
.hir
()
.span_by_hir_id
(
hir_id
)));
let
mut
sep
=
" "
;
for
(
freevar
,
upvar_ty
)
in
self
.tcx
()
.free
vars
(
did
)
for
(
upvar
,
upvar_ty
)
in
self
.tcx
()
.up
vars
(
did
)
.as_ref
()
.map_or
(
&
[][
..
],
|
v
|
&
v
[
..
])
.iter
()
...
...
@@ -591,7 +591,7 @@ fn pretty_print_type(
p!
(
write
(
"{}{}:"
,
sep
,
self
.tcx
()
.hir
()
.name_by_hir_id
(
free
var
.var_id
())),
self
.tcx
()
.hir
()
.name_by_hir_id
(
up
var
.var_id
())),
print
(
upvar_ty
));
sep
=
", "
;
}
...
...
@@ -625,7 +625,7 @@ fn pretty_print_type(
p!
(
write
(
"@{:?}"
,
self
.tcx
()
.hir
()
.span_by_hir_id
(
hir_id
)));
}
let
mut
sep
=
" "
;
for
(
freevar
,
upvar_ty
)
in
self
.tcx
()
.free
vars
(
did
)
for
(
upvar
,
upvar_ty
)
in
self
.tcx
()
.up
vars
(
did
)
.as_ref
()
.map_or
(
&
[][
..
],
|
v
|
&
v
[
..
])
.iter
()
...
...
@@ -634,7 +634,7 @@ fn pretty_print_type(
p!
(
write
(
"{}{}:"
,
sep
,
self
.tcx
()
.hir
()
.name_by_hir_id
(
free
var
.var_id
())),
self
.tcx
()
.hir
()
.name_by_hir_id
(
up
var
.var_id
())),
print
(
upvar_ty
));
sep
=
", "
;
}
...
...
src/librustc_interface/passes.rs
浏览文件 @
8d9f4a12
...
...
@@ -180,7 +180,7 @@ fn from_owned_resolver(
ExpansionResult
{
defs
:
Steal
::
new
(
resolver
.definitions
),
resolutions
:
Steal
::
new
(
Resolutions
{
freevars
:
resolver
.free
vars
,
upvars
:
resolver
.up
vars
,
export_map
:
resolver
.export_map
,
trait_map
:
resolver
.trait_map
,
glob_map
:
resolver
.glob_map
,
...
...
@@ -199,7 +199,7 @@ pub fn from_resolver_ref(
ExpansionResult
{
defs
:
Steal
::
new
(
resolver
.definitions
.clone
()),
resolutions
:
Steal
::
new
(
Resolutions
{
freevars
:
resolver
.free
vars
.clone
(),
upvars
:
resolver
.up
vars
.clone
(),
export_map
:
resolver
.export_map
.clone
(),
trait_map
:
resolver
.trait_map
.clone
(),
glob_map
:
resolver
.glob_map
.clone
(),
...
...
src/librustc_mir/borrow_check/error_reporting.rs
浏览文件 @
8d9f4a12
...
...
@@ -1814,12 +1814,12 @@ fn describe_field_from_ty(
ty
::
Array
(
ty
,
_
)
|
ty
::
Slice
(
ty
)
=>
self
.describe_field_from_ty
(
&
ty
,
field
,
variant_index
),
ty
::
Closure
(
def_id
,
_
)
|
ty
::
Generator
(
def_id
,
_
,
_
)
=>
{
// `tcx.
free
vars(def_id)` returns an `Option`, which is `None` in case
// `tcx.
up
vars(def_id)` returns an `Option`, which is `None` in case
// the closure comes from another crate. But in that case we wouldn't
// be borrowck'ing it, so we can just unwrap:
let
freevar
=
self
.infcx.tcx
.free
vars
(
def_id
)
.unwrap
()[
field
.index
()];
let
upvar
=
self
.infcx.tcx
.up
vars
(
def_id
)
.unwrap
()[
field
.index
()];
self
.infcx.tcx
.hir
()
.name_by_hir_id
(
free
var
.var_id
())
.to_string
()
self
.infcx.tcx
.hir
()
.name_by_hir_id
(
up
var
.var_id
())
.to_string
()
}
_
=>
{
// Might need a revision when the fields in trait RFC is implemented
...
...
@@ -2609,7 +2609,7 @@ fn closure_span(
if
let
hir
::
ExprKind
::
Closure
(
..
,
args_span
,
_
)
=
expr
{
for
(
v
,
place
)
in
self
.infcx.tcx
.
free
vars
(
def_id
)
?
.iter
()
.zip
(
places
)
{
for
(
v
,
place
)
in
self
.infcx.tcx
.
up
vars
(
def_id
)
?
.iter
()
.zip
(
places
)
{
match
place
{
Operand
::
Copy
(
place
)
|
Operand
::
Move
(
place
)
if
target_place
==
place
=>
{
...
...
src/librustc_mir/hair/cx/expr.rs
浏览文件 @
8d9f4a12
...
...
@@ -516,10 +516,10 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
span_bug!
(
expr
.span
,
"closure expr w/o closure type: {:?}"
,
closure_ty
);
}
};
let
upvars
=
cx
.tcx
.
free
vars
(
def_id
)
.iter
()
.flat_map
(|
freevars
|
free
vars
.iter
())
let
upvars
=
cx
.tcx
.
up
vars
(
def_id
)
.iter
()
.flat_map
(|
upvars
|
up
vars
.iter
())
.zip
(
substs
.upvar_tys
(
def_id
,
cx
.tcx
))
.map
(|(
freevar
,
ty
)|
capture_freevar
(
cx
,
expr
,
free
var
,
ty
))
.map
(|(
upvar
,
ty
)|
capture_upvar
(
cx
,
expr
,
up
var
,
ty
))
.collect
();
ExprKind
::
Closure
{
closure_id
:
def_id
,
...
...
@@ -1184,12 +1184,12 @@ fn overloaded_place<'a, 'gcx, 'tcx>(
ExprKind
::
Deref
{
arg
:
ref_expr
.to_ref
()
}
}
fn
capture_
free
var
<
'a
,
'gcx
,
'tcx
>
(
cx
:
&
mut
Cx
<
'a
,
'gcx
,
'tcx
>
,
fn
capture_
up
var
<
'a
,
'gcx
,
'tcx
>
(
cx
:
&
mut
Cx
<
'a
,
'gcx
,
'tcx
>
,
closure_expr
:
&
'tcx
hir
::
Expr
,
freevar
:
&
hir
::
Free
var
,
free
var_ty
:
Ty
<
'tcx
>
)
upvar
:
&
hir
::
Up
var
,
up
var_ty
:
Ty
<
'tcx
>
)
->
ExprRef
<
'tcx
>
{
let
var_hir_id
=
free
var
.var_id
();
let
var_hir_id
=
up
var
.var_id
();
let
upvar_id
=
ty
::
UpvarId
{
var_path
:
ty
::
UpvarPath
{
hir_id
:
var_hir_id
},
closure_expr_id
:
cx
.tcx
.hir
()
.local_def_id_from_hir_id
(
closure_expr
.hir_id
)
.to_local
(),
...
...
@@ -1201,7 +1201,7 @@ fn capture_freevar<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
temp_lifetime
,
ty
:
var_ty
,
span
:
closure_expr
.span
,
kind
:
convert_var
(
cx
,
closure_expr
,
free
var
.res
),
kind
:
convert_var
(
cx
,
closure_expr
,
up
var
.res
),
};
match
upvar_capture
{
ty
::
UpvarCapture
::
ByValue
=>
captured_var
.to_ref
(),
...
...
@@ -1213,7 +1213,7 @@ fn capture_freevar<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
};
Expr
{
temp_lifetime
,
ty
:
free
var_ty
,
ty
:
up
var_ty
,
span
:
closure_expr
.span
,
kind
:
ExprKind
::
Borrow
{
borrow_kind
,
...
...
src/librustc_mir/interpret/validity.rs
浏览文件 @
8d9f4a12
...
...
@@ -170,7 +170,7 @@ fn aggregate_field_path_elem(
if
def_id
.is_local
()
{
let
tables
=
self
.ecx.tcx
.typeck_tables_of
(
def_id
);
if
let
Some
(
upvars
)
=
tables
.upvar_list
.get
(
&
def_id
)
{
// Sometimes the index is beyond the number of
free
vars (seen
// Sometimes the index is beyond the number of
up
vars (seen
// for a generator).
if
let
Some
(
upvar_id
)
=
upvars
.get
(
field
)
{
let
var_hir_id
=
upvar_id
.var_path.hir_id
;
...
...
src/librustc_passes/rvalue_promotion.rs
浏览文件 @
8d9f4a12
...
...
@@ -450,7 +450,7 @@ fn check_expr_kind<'a, 'tcx>(
// Paths in constant contexts cannot refer to local variables,
// as there are none, and thus closures can't have upvars there.
let
closure_def_id
=
v
.tcx
.hir
()
.local_def_id_from_hir_id
(
e
.hir_id
);
if
!
v
.tcx
.
free
vars
(
closure_def_id
)
.map_or
(
true
,
|
v
|
v
.is_empty
())
{
if
!
v
.tcx
.
up
vars
(
closure_def_id
)
.map_or
(
true
,
|
v
|
v
.is_empty
())
{
NotPromotable
}
else
{
nested_body_promotable
...
...
src/librustc_resolve/lib.rs
浏览文件 @
8d9f4a12
...
...
@@ -29,7 +29,7 @@
};
use
rustc
::
hir
::
def
::
Namespace
::
*
;
use
rustc
::
hir
::
def_id
::{
CRATE_DEF_INDEX
,
LOCAL_CRATE
,
DefId
};
use
rustc
::
hir
::{
Freevar
,
Free
varMap
,
TraitCandidate
,
TraitMap
,
GlobMap
};
use
rustc
::
hir
::{
Upvar
,
Up
varMap
,
TraitCandidate
,
TraitMap
,
GlobMap
};
use
rustc
::
ty
::{
self
,
DefIdTree
};
use
rustc
::
util
::
nodemap
::{
NodeMap
,
NodeSet
,
FxHashMap
,
FxHashSet
,
DefIdMap
};
use
rustc
::{
bug
,
span_bug
};
...
...
@@ -1668,8 +1668,8 @@ pub struct Resolver<'a> {
/// Resolutions for labels (node IDs of their corresponding blocks or loops).
label_res_map
:
NodeMap
<
NodeId
>
,
pub
freevars
:
Free
varMap
,
free
vars_seen
:
NodeMap
<
NodeMap
<
usize
>>
,
pub
upvars
:
Up
varMap
,
up
vars_seen
:
NodeMap
<
NodeMap
<
usize
>>
,
pub
export_map
:
ExportMap
<
NodeId
>
,
pub
trait_map
:
TraitMap
,
...
...
@@ -2033,8 +2033,8 @@ pub fn new(session: &'a Session,
partial_res_map
:
Default
::
default
(),
import_res_map
:
Default
::
default
(),
label_res_map
:
Default
::
default
(),
free
vars
:
Default
::
default
(),
free
vars_seen
:
Default
::
default
(),
up
vars
:
Default
::
default
(),
up
vars_seen
:
Default
::
default
(),
export_map
:
FxHashMap
::
default
(),
trait_map
:
Default
::
default
(),
module_map
,
...
...
@@ -4054,21 +4054,21 @@ fn adjust_local_res(&mut self,
ClosureRibKind
(
function_id
)
=>
{
let
prev_res
=
res
;
let
seen
=
self
.
free
vars_seen
let
seen
=
self
.
up
vars_seen
.entry
(
function_id
)
.or_default
();
if
let
Some
(
&
index
)
=
seen
.get
(
&
node_id
)
{
res
=
Res
::
Upvar
(
node_id
,
index
,
function_id
);
continue
;
}
let
vec
=
self
.
free
vars
let
vec
=
self
.
up
vars
.entry
(
function_id
)
.or_default
();
let
depth
=
vec
.len
();
res
=
Res
::
Upvar
(
node_id
,
depth
,
function_id
);
if
record_used
{
vec
.push
(
Free
var
{
vec
.push
(
Up
var
{
res
:
prev_res
,
span
,
});
...
...
src/librustc_typeck/check/coercion.rs
浏览文件 @
8d9f4a12
...
...
@@ -722,7 +722,7 @@ fn coerce_closure_to_fn(&self,
let
b
=
self
.shallow_resolve
(
b
);
match
b
.sty
{
ty
::
FnPtr
(
fn_ty
)
if
self
.tcx
.
free
vars
(
def_id_a
)
.map_or
(
true
,
|
v
|
v
.is_empty
())
=>
{
ty
::
FnPtr
(
fn_ty
)
if
self
.tcx
.
up
vars
(
def_id_a
)
.map_or
(
true
,
|
v
|
v
.is_empty
())
=>
{
// We coerce the closure, which has fn type
// `extern "rust-call" fn((arg0,arg1,...)) -> _`
// to
...
...
src/librustc_typeck/check/upvar.rs
浏览文件 @
8d9f4a12
...
...
@@ -121,28 +121,28 @@ fn analyze_closure(
None
};
if
let
Some
(
freevars
)
=
self
.tcx
.free
vars
(
closure_def_id
)
{
let
mut
freevar_list
:
Vec
<
ty
::
UpvarId
>
=
Vec
::
with_capacity
(
free
vars
.len
());
for
freevar
in
free
vars
.iter
()
{
if
let
Some
(
upvars
)
=
self
.tcx
.up
vars
(
closure_def_id
)
{
let
mut
upvar_list
:
Vec
<
ty
::
UpvarId
>
=
Vec
::
with_capacity
(
up
vars
.len
());
for
upvar
in
up
vars
.iter
()
{
let
upvar_id
=
ty
::
UpvarId
{
var_path
:
ty
::
UpvarPath
{
hir_id
:
free
var
.var_id
(),
hir_id
:
up
var
.var_id
(),
},
closure_expr_id
:
LocalDefId
::
from_def_id
(
closure_def_id
),
};
debug!
(
"seed upvar_id {:?}"
,
upvar_id
);
// Adding the upvar Id to the list of Upvars, which will be added
// to the map for the closure at the end of the for loop.
free
var_list
.push
(
upvar_id
);
up
var_list
.push
(
upvar_id
);
let
capture_kind
=
match
capture_clause
{
hir
::
CaptureByValue
=>
ty
::
UpvarCapture
::
ByValue
,
hir
::
CaptureByRef
=>
{
let
origin
=
UpvarRegion
(
upvar_id
,
span
);
let
free
var_region
=
self
.next_region_var
(
origin
);
let
up
var_region
=
self
.next_region_var
(
origin
);
let
upvar_borrow
=
ty
::
UpvarBorrow
{
kind
:
ty
::
ImmBorrow
,
region
:
free
var_region
,
region
:
up
var_region
,
};
ty
::
UpvarCapture
::
ByRef
(
upvar_borrow
)
}
...
...
@@ -153,14 +153,14 @@ fn analyze_closure(
.upvar_capture_map
.insert
(
upvar_id
,
capture_kind
);
}
// Add the vector of
free
vars to the map keyed with the closure id.
// Add the vector of
up
vars to the map keyed with the closure id.
// This gives us an easier access to them without having to call
// tcx.
free
vars again..
if
!
free
var_list
.is_empty
()
{
// tcx.
up
vars again..
if
!
up
var_list
.is_empty
()
{
self
.tables
.borrow_mut
()
.upvar_list
.insert
(
closure_def_id
,
free
var_list
);
.insert
(
closure_def_id
,
up
var_list
);
}
}
...
...
@@ -246,12 +246,12 @@ fn final_upvar_tys(&self, closure_id: hir::HirId) -> Vec<Ty<'tcx>> {
let
tcx
=
self
.tcx
;
let
closure_def_id
=
tcx
.hir
()
.local_def_id_from_hir_id
(
closure_id
);
tcx
.
freevars
(
closure_def_id
)
.iter
()
.flat_map
(|
free
vars
|
{
free
vars
tcx
.
upvars
(
closure_def_id
)
.iter
()
.flat_map
(|
up
vars
|
{
up
vars
.iter
()
.map
(|
free
var
|
{
let
var_hir_id
=
free
var
.var_id
();
let
free
var_ty
=
self
.node_ty
(
var_hir_id
);
.map
(|
up
var
|
{
let
var_hir_id
=
up
var
.var_id
();
let
up
var_ty
=
self
.node_ty
(
var_hir_id
);
let
upvar_id
=
ty
::
UpvarId
{
var_path
:
ty
::
UpvarPath
{
hir_id
:
var_hir_id
},
closure_expr_id
:
LocalDefId
::
from_def_id
(
closure_def_id
),
...
...
@@ -259,16 +259,16 @@ fn final_upvar_tys(&self, closure_id: hir::HirId) -> Vec<Ty<'tcx>> {
let
capture
=
self
.tables
.borrow
()
.upvar_capture
(
upvar_id
);
debug!
(
"var_id={:?}
free
var_ty={:?} capture={:?}"
,
var_hir_id
,
free
var_ty
,
capture
"var_id={:?}
up
var_ty={:?} capture={:?}"
,
var_hir_id
,
up
var_ty
,
capture
);
match
capture
{
ty
::
UpvarCapture
::
ByValue
=>
free
var_ty
,
ty
::
UpvarCapture
::
ByValue
=>
up
var_ty
,
ty
::
UpvarCapture
::
ByRef
(
borrow
)
=>
tcx
.mk_ref
(
borrow
.region
,
ty
::
TypeAndMut
{
ty
:
free
var_ty
,
ty
:
up
var_ty
,
mutbl
:
borrow
.kind
.to_mutbl_lossy
(),
},
),
...
...
src/librustc_typeck/collect.rs
浏览文件 @
8d9f4a12
...
...
@@ -1093,8 +1093,8 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty
}),
);
if
let
Some
(
freevars
)
=
tcx
.free
vars
(
def_id
)
{
params
.extend
(
free
vars
.iter
()
.zip
((
dummy_args
.len
()
as
u32
)
..
)
.map
(|(
_
,
i
)|
{
if
let
Some
(
upvars
)
=
tcx
.up
vars
(
def_id
)
{
params
.extend
(
up
vars
.iter
()
.zip
((
dummy_args
.len
()
as
u32
)
..
)
.map
(|(
_
,
i
)|
{
ty
::
GenericParamDef
{
index
:
type_start
+
i
,
name
:
Symbol
::
intern
(
"<upvar>"
)
.as_interned_str
(),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录