Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
7285b563
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,发现更多精彩内容 >>
提交
7285b563
编写于
2月 27, 2019
作者:
M
Matthew Jasper
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make migrate mode work at item level granularity
上级
913ad6d1
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
129 addition
and
25 deletion
+129
-25
src/librustc/middle/expr_use_visitor.rs
src/librustc/middle/expr_use_visitor.rs
+6
-2
src/librustc_borrowck/borrowck/gather_loans/mod.rs
src/librustc_borrowck/borrowck/gather_loans/mod.rs
+18
-0
src/librustc_mir/borrow_check/mod.rs
src/librustc_mir/borrow_check/mod.rs
+5
-23
src/test/ui/borrowck/issue-58776-borrowck-scans-children.ast.stderr
...i/borrowck/issue-58776-borrowck-scans-children.ast.stderr
+15
-0
src/test/ui/borrowck/issue-58776-borrowck-scans-children.migrate.stderr
...rrowck/issue-58776-borrowck-scans-children.migrate.stderr
+32
-0
src/test/ui/borrowck/issue-58776-borrowck-scans-children.nll.stderr
...i/borrowck/issue-58776-borrowck-scans-children.nll.stderr
+32
-0
src/test/ui/borrowck/issue-58776-borrowck-scans-children.rs
src/test/ui/borrowck/issue-58776-borrowck-scans-children.rs
+21
-0
未找到文件。
src/librustc/middle/expr_use_visitor.rs
浏览文件 @
7285b563
...
...
@@ -82,6 +82,9 @@ fn mutate(&mut self,
assignment_span
:
Span
,
assignee_cmt
:
&
mc
::
cmt_
<
'tcx
>
,
mode
:
MutateMode
);
// A nested closure or generator - only one layer deep.
fn
nested_body
(
&
mut
self
,
_
body_id
:
hir
::
BodyId
)
{}
}
#[derive(Copy,
Clone,
PartialEq,
Debug)]
...
...
@@ -531,8 +534,9 @@ pub fn walk_expr(&mut self, expr: &hir::Expr) {
self
.consume_expr
(
&
base
);
}
hir
::
ExprKind
::
Closure
(
..
,
fn_decl_span
,
_
)
=>
{
self
.walk_captures
(
expr
,
fn_decl_span
)
hir
::
ExprKind
::
Closure
(
_
,
_
,
body_id
,
fn_decl_span
,
_
)
=>
{
self
.delegate
.nested_body
(
body_id
);
self
.walk_captures
(
expr
,
fn_decl_span
);
}
hir
::
ExprKind
::
Box
(
ref
base
)
=>
{
...
...
src/librustc_borrowck/borrowck/gather_loans/mod.rs
浏览文件 @
7285b563
...
...
@@ -153,6 +153,24 @@ fn decl_without_init(&mut self, id: hir::HirId, _span: Span) {
.node_type
(
id
);
gather_moves
::
gather_decl
(
self
.bccx
,
&
self
.move_data
,
id
,
ty
);
}
fn
nested_body
(
&
mut
self
,
body_id
:
hir
::
BodyId
)
{
debug!
(
"nested_body(body_id={:?})"
,
body_id
);
// rust-lang/rust#58776: MIR and AST borrow check disagree on where
// certain closure errors are reported. As such migrate borrowck has to
// operate at the level of items, rather than bodies. Check if the
// contained closure had any errors and set `signalled_any_error` if it
// has.
let
bccx
=
self
.bccx
;
if
bccx
.tcx
.migrate_borrowck
()
{
if
let
SignalledError
::
NoErrorsSeen
=
bccx
.signalled_any_error
.get
()
{
let
closure_def_id
=
bccx
.tcx
.hir
()
.body_owner_def_id
(
body_id
);
debug!
(
"checking closure: {:?}"
,
closure_def_id
);
bccx
.signalled_any_error
.set
(
bccx
.tcx
.borrowck
(
closure_def_id
)
.signalled_any_error
);
}
}
}
}
/// Implements the A-* rules in README.md.
...
...
src/librustc_mir/borrow_check/mod.rs
浏览文件 @
7285b563
...
...
@@ -329,30 +329,12 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
// When borrowck=migrate, check if AST-borrowck would
// error on the given code.
// rust-lang/rust#55492: loop over parents to ensure that
// errors that AST-borrowck only detects in some parent of
// a closure still allows NLL to signal an error.
let
mut
curr_def_id
=
def_id
;
let
signalled_any_error
=
loop
{
match
tcx
.borrowck
(
curr_def_id
)
.signalled_any_error
{
SignalledError
::
NoErrorsSeen
=>
{
// keep traversing (and borrow-checking) parents
}
SignalledError
::
SawSomeError
=>
{
// stop search here
break
SignalledError
::
SawSomeError
;
}
}
if
tcx
.is_closure
(
curr_def_id
)
{
curr_def_id
=
tcx
.parent_def_id
(
curr_def_id
)
.expect
(
"a closure must have a parent_def_id"
);
}
else
{
break
SignalledError
::
NoErrorsSeen
;
}
};
// rust-lang/rust#55492, rust-lang/rust#58776 check the base def id
// for errors. AST borrowck is responsible for aggregating
// `signalled_any_error` from all of the nested closures here.
let
base_def_id
=
tcx
.closure_base_def_id
(
def_id
);
match
signalled_any_error
{
match
tcx
.borrowck
(
base_def_id
)
.
signalled_any_error
{
SignalledError
::
NoErrorsSeen
=>
{
// if AST-borrowck signalled no errors, then
// downgrade all the buffered MIR-borrowck errors
...
...
src/test/ui/borrowck/issue-58776-borrowck-scans-children.ast.stderr
0 → 100644
浏览文件 @
7285b563
error[E0597]: `**greeting` does not live long enough
--> $DIR/issue-58776-borrowck-scans-children.rs:10:24
|
LL | let res = (|| (|| &greeting)())();
| -- ^^^^^^^^ - borrowed value only lives until here
| | |
| | borrowed value does not live long enough
| capture occurs here
...
LL | }
| - borrowed value needs to live until here
error: aborting due to previous error
For more information about this error, try `rustc --explain E0597`.
src/test/ui/borrowck/issue-58776-borrowck-scans-children.migrate.stderr
0 → 100644
浏览文件 @
7285b563
error[E0506]: cannot assign to `greeting` because it is borrowed
--> $DIR/issue-58776-borrowck-scans-children.rs:13:5
|
LL | let res = (|| (|| &greeting)())();
| -- -------- borrow occurs due to use in closure
| |
| borrow of `greeting` occurs here
...
LL | greeting = "DEALLOCATED".to_string();
| ^^^^^^^^ assignment to borrowed `greeting` occurs here
...
LL | println!("thread result: {:?}", res);
| --- borrow later used here
error[E0505]: cannot move out of `greeting` because it is borrowed
--> $DIR/issue-58776-borrowck-scans-children.rs:16:10
|
LL | let res = (|| (|| &greeting)())();
| -- -------- borrow occurs due to use in closure
| |
| borrow of `greeting` occurs here
...
LL | drop(greeting);
| ^^^^^^^^ move out of `greeting` occurs here
...
LL | println!("thread result: {:?}", res);
| --- borrow later used here
error: aborting due to 2 previous errors
Some errors occurred: E0505, E0506.
For more information about an error, try `rustc --explain E0505`.
src/test/ui/borrowck/issue-58776-borrowck-scans-children.nll.stderr
0 → 100644
浏览文件 @
7285b563
error[E0506]: cannot assign to `greeting` because it is borrowed
--> $DIR/issue-58776-borrowck-scans-children.rs:13:5
|
LL | let res = (|| (|| &greeting)())();
| -- -------- borrow occurs due to use in closure
| |
| borrow of `greeting` occurs here
...
LL | greeting = "DEALLOCATED".to_string();
| ^^^^^^^^ assignment to borrowed `greeting` occurs here
...
LL | println!("thread result: {:?}", res);
| --- borrow later used here
error[E0505]: cannot move out of `greeting` because it is borrowed
--> $DIR/issue-58776-borrowck-scans-children.rs:16:10
|
LL | let res = (|| (|| &greeting)())();
| -- -------- borrow occurs due to use in closure
| |
| borrow of `greeting` occurs here
...
LL | drop(greeting);
| ^^^^^^^^ move out of `greeting` occurs here
...
LL | println!("thread result: {:?}", res);
| --- borrow later used here
error: aborting due to 2 previous errors
Some errors occurred: E0505, E0506.
For more information about an error, try `rustc --explain E0505`.
src/test/ui/borrowck/issue-58776-borrowck-scans-children.rs
0 → 100644
浏览文件 @
7285b563
// ignore-compare-mode-nll
// revisions: ast migrate nll
//[migrate]compile-flags: -Z borrowck=migrate
#![cfg_attr(nll,
feature(nll))]
fn
main
()
{
let
mut
greeting
=
"Hello world!"
.to_string
();
let
res
=
(||
(||
&
greeting
)())();
//[ast]~^ ERROR does not live long enough
greeting
=
"DEALLOCATED"
.to_string
();
//[migrate]~^ ERROR cannot assign
//[nll]~^^ ERROR cannot assign
drop
(
greeting
);
//[migrate]~^ ERROR cannot move
//[nll]~^^ ERROR cannot move
println!
(
"thread result: {:?}"
,
res
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录