Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
5532e9de
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,发现更多精彩内容 >>
未验证
提交
5532e9de
编写于
8月 07, 2018
作者:
D
David Wood
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improved how upvars are detected when presenting errors using prefixes.
上级
2c6b0e5c
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
68 addition
and
27 deletion
+68
-27
src/librustc/mir/tcx.rs
src/librustc/mir/tcx.rs
+1
-16
src/librustc_mir/borrow_check/move_errors.rs
src/librustc_mir/borrow_check/move_errors.rs
+18
-11
src/test/ui/borrowck/borrowck-move-by-capture.nll.stderr
src/test/ui/borrowck/borrowck-move-by-capture.nll.stderr
+3
-0
src/test/ui/issues/issue-4335.nll.stderr
src/test/ui/issues/issue-4335.nll.stderr
+2
-0
src/test/ui/moves/moves-based-on-type-move-out-of-closure-env-issue-1965.nll.stderr
...sed-on-type-move-out-of-closure-env-issue-1965.nll.stderr
+2
-0
src/test/ui/nll/issue-52663-span-decl-captured-variable.rs
src/test/ui/nll/issue-52663-span-decl-captured-variable.rs
+23
-0
src/test/ui/nll/issue-52663-span-decl-captured-variable.stderr
...est/ui/nll/issue-52663-span-decl-captured-variable.stderr
+11
-0
src/test/ui/unboxed-closures/unboxed-closure-illegal-move.nll.stderr
.../unboxed-closures/unboxed-closure-illegal-move.nll.stderr
+8
-0
未找到文件。
src/librustc/mir/tcx.rs
浏览文件 @
5532e9de
...
...
@@ -151,25 +151,10 @@ pub fn is_upvar_field_projection<'cx, 'gcx>(&self, mir: &'cx Mir<'tcx>,
}
},
_
=>
None
,
}
,
}
_
=>
None
,
}
}
/// Strip the deref projections from a `Place`. For example, given `(*(*((*_1).0: &&T)))`, this
/// will return `((*_1).0)`. Once stripped of any deref projections, places can then be
/// checked as upvar field projections using `is_upvar_field_projection`.
pub
fn
strip_deref_projections
(
&
self
)
->
&
Place
<
'tcx
>
{
let
mut
current
=
self
;
while
let
Place
::
Projection
(
ref
proj
)
=
current
{
if
let
ProjectionElem
::
Deref
=
proj
.elem
{
current
=
&
proj
.base
;
}
else
{
break
;
}
}
current
}
}
pub
enum
RvalueInitializationState
{
...
...
src/librustc_mir/borrow_check/move_errors.rs
浏览文件 @
5532e9de
...
...
@@ -16,6 +16,7 @@
use
syntax_pos
::
Span
;
use
borrow_check
::
MirBorrowckCtxt
;
use
borrow_check
::
prefixes
::
PrefixSet
;
use
dataflow
::
move_paths
::{
IllegalMoveOrigin
,
IllegalMoveOriginKind
};
use
dataflow
::
move_paths
::{
LookupResult
,
MoveError
,
MovePathIndex
};
use
util
::
borrowck_errors
::{
BorrowckErrors
,
Origin
};
...
...
@@ -254,15 +255,16 @@ fn report(&mut self, error: GroupedMoveError<'tcx>) {
// borrow to provide feedback about why this
// was a move rather than a copy.
let
ty
=
place
.ty
(
self
.mir
,
self
.tcx
)
.to_ty
(
self
.tcx
);
let
is_upvar_field_projection
=
self
.prefixes
(
&
original_path
,
PrefixSet
::
All
)
.any
(|
p
|
p
.is_upvar_field_projection
(
self
.mir
,
&
self
.tcx
)
.is_some
());
match
ty
.sty
{
ty
::
TyArray
(
..
)
|
ty
::
TySlice
(
..
)
=>
self
.tcx
.cannot_move_out_of_interior_noncopy
(
span
,
ty
,
None
,
origin
),
ty
::
TyClosure
(
def_id
,
closure_substs
)
if
!
self
.mir.upvar_decls
.is_empty
()
&&
original_path
.strip_deref_projections
()
.is_upvar_field_projection
(
self
.mir
,
&
self
.tcx
)
.is_some
()
if
!
self
.mir.upvar_decls
.is_empty
()
&&
is_upvar_field_projection
=>
{
let
closure_kind_ty
=
closure_substs
.closure_kind_ty
(
def_id
,
self
.tcx
);
...
...
@@ -286,13 +288,18 @@ fn report(&mut self, error: GroupedMoveError<'tcx>) {
let
mut
diag
=
self
.tcx
.cannot_move_out_of
(
span
,
place_description
,
origin
);
if
let
Some
(
field
)
=
original_path
.is_upvar_field_projection
(
self
.mir
,
&
self
.tcx
)
{
let
upvar_decl
=
&
self
.mir.upvar_decls
[
field
.index
()];
let
upvar_hir_id
=
upvar_decl
.var_hir_id
.assert_crate_local
();
let
upvar_node_id
=
self
.tcx.hir
.hir_to_node_id
(
upvar_hir_id
);
let
upvar_span
=
self
.tcx.hir
.span
(
upvar_node_id
);
diag
.span_label
(
upvar_span
,
"captured outer variable"
);
for
prefix
in
self
.prefixes
(
&
original_path
,
PrefixSet
::
All
)
{
if
let
Some
(
field
)
=
prefix
.is_upvar_field_projection
(
self
.mir
,
&
self
.tcx
)
{
let
upvar_decl
=
&
self
.mir.upvar_decls
[
field
.index
()];
let
upvar_hir_id
=
upvar_decl
.var_hir_id
.assert_crate_local
();
let
upvar_node_id
=
self
.tcx.hir
.hir_to_node_id
(
upvar_hir_id
);
let
upvar_span
=
self
.tcx.hir
.span
(
upvar_node_id
);
diag
.span_label
(
upvar_span
,
"captured outer variable"
);
break
;
}
}
diag
...
...
src/test/ui/borrowck/borrowck-move-by-capture.nll.stderr
浏览文件 @
5532e9de
error[E0507]: cannot move out of captured variable in an `FnMut` closure
--> $DIR/borrowck-move-by-capture.rs:19:29
|
LL | let bar: Box<_> = box 3;
| --- captured outer variable
LL | let _g = to_fn_mut(|| {
LL | let _h = to_fn_once(move || -> isize { *bar }); //~ ERROR cannot move out of
| ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of captured variable in an `FnMut` closure
...
...
src/test/ui/issues/issue-4335.nll.stderr
浏览文件 @
5532e9de
error[E0507]: cannot move out of captured variable in an `FnMut` closure
--> $DIR/issue-4335.rs:16:20
|
LL | fn f<'r, T>(v: &'r T) -> Box<FnMut() -> T + 'r> {
| - captured outer variable
LL | id(Box::new(|| *v))
| ^^ cannot move out of captured variable in an `FnMut` closure
...
...
src/test/ui/moves/moves-based-on-type-move-out-of-closure-env-issue-1965.nll.stderr
浏览文件 @
5532e9de
error[E0507]: cannot move out of captured variable in an `Fn` closure
--> $DIR/moves-based-on-type-move-out-of-closure-env-issue-1965.rs:21:28
|
LL | let i = box 3;
| - captured outer variable
LL | let _f = to_fn(|| test(i)); //~ ERROR cannot move out
| ^ cannot move out of captured variable in an `Fn` closure
...
...
src/test/ui/nll/issue-52663-span-decl-captured-variable.rs
0 → 100644
浏览文件 @
5532e9de
// Copyright 2017 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.
#![feature(nll)]
fn
expect_fn
<
F
>
(
f
:
F
)
where
F
:
Fn
()
{
f
();
}
fn
main
()
{
{
let
x
=
(
vec!
[
22
],
vec!
[
44
]);
expect_fn
(||
drop
(
x
.0
));
//~^ ERROR cannot move out of captured variable in an `Fn` closure [E0507]
}
}
src/test/ui/nll/issue-52663-span-decl-captured-variable.stderr
0 → 100644
浏览文件 @
5532e9de
error[E0507]: cannot move out of captured variable in an `Fn` closure
--> $DIR/issue-52663-span-decl-captured-variable.rs:20:26
|
LL | let x = (vec![22], vec![44]);
| - captured outer variable
LL | expect_fn(|| drop(x.0));
| ^^^ cannot move out of captured variable in an `Fn` closure
error: aborting due to previous error
For more information about this error, try `rustc --explain E0507`.
src/test/ui/unboxed-closures/unboxed-closure-illegal-move.nll.stderr
浏览文件 @
5532e9de
error[E0507]: cannot move out of captured variable in an `Fn` closure
--> $DIR/unboxed-closure-illegal-move.rs:25:31
|
LL | let x = Box::new(0);
| - captured outer variable
LL | let f = to_fn(|| drop(x)); //~ ERROR cannot move
| ^ cannot move out of captured variable in an `Fn` closure
error[E0507]: cannot move out of captured variable in an `FnMut` closure
--> $DIR/unboxed-closure-illegal-move.rs:29:35
|
LL | let x = Box::new(0);
| - captured outer variable
LL | let f = to_fn_mut(|| drop(x)); //~ ERROR cannot move
| ^ cannot move out of captured variable in an `FnMut` closure
error[E0507]: cannot move out of captured variable in an `Fn` closure
--> $DIR/unboxed-closure-illegal-move.rs:38:36
|
LL | let x = Box::new(0);
| - captured outer variable
LL | let f = to_fn(move || drop(x)); //~ ERROR cannot move
| ^ cannot move out of captured variable in an `Fn` closure
error[E0507]: cannot move out of captured variable in an `FnMut` closure
--> $DIR/unboxed-closure-illegal-move.rs:42:40
|
LL | let x = Box::new(0);
| - captured outer variable
LL | let f = to_fn_mut(move || drop(x)); //~ ERROR cannot move
| ^ cannot move out of captured variable in an `FnMut` closure
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录