Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
78e987ab
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,发现更多精彩内容 >>
提交
78e987ab
编写于
8月 10, 2018
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
just check whether a variable is initialized
Don't iterate over all things that are initialized.
上级
a8a982bb
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
26 addition
and
31 deletion
+26
-31
src/librustc_mir/borrow_check/mod.rs
src/librustc_mir/borrow_check/mod.rs
+18
-20
src/test/ui/did_you_mean/issue-35937.nll.stderr
src/test/ui/did_you_mean/issue-35937.nll.stderr
+8
-11
未找到文件。
src/librustc_mir/borrow_check/mod.rs
浏览文件 @
78e987ab
...
...
@@ -1264,7 +1264,12 @@ fn mutate_place(
if
let
&
Place
::
Local
(
local
)
=
place_span
.0
{
if
let
Mutability
::
Not
=
self
.mir.local_decls
[
local
]
.mutability
{
// check for reassignments to immutable local variables
self
.check_if_reassignment_to_immutable_state
(
context
,
place_span
,
flow_state
);
self
.check_if_reassignment_to_immutable_state
(
context
,
local
,
place_span
,
flow_state
,
);
return
;
}
}
...
...
@@ -1575,27 +1580,20 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
fn
check_if_reassignment_to_immutable_state
(
&
mut
self
,
context
:
Context
,
(
place
,
span
):
(
&
Place
<
'tcx
>
,
Span
),
local
:
Local
,
place_span
:
(
&
Place
<
'tcx
>
,
Span
),
flow_state
:
&
Flows
<
'cx
,
'gcx
,
'tcx
>
,
)
{
debug!
(
"check_if_reassignment_to_immutable_state({:?})"
,
place
);
// determine if this path has a non-mut owner (and thus needs checking).
let
err_place
=
match
self
.is_mutable
(
place
,
LocalMutationIsAllowed
::
No
)
{
Ok
(
..
)
=>
return
,
Err
(
place
)
=>
place
,
};
debug!
(
"check_if_reassignment_to_immutable_state({:?}) - is an imm local"
,
place
);
for
i
in
flow_state
.ever_inits
.iter_incoming
()
{
let
init
=
self
.move_data.inits
[
i
];
let
init_place
=
&
self
.move_data.move_paths
[
init
.path
]
.place
;
if
places_conflict
::
places_conflict
(
self
.tcx
,
self
.mir
,
&
init_place
,
place
,
Deep
)
{
self
.report_illegal_reassignment
(
context
,
(
place
,
span
),
init
.span
,
err_place
);
break
;
}
debug!
(
"check_if_reassignment_to_immutable_state({:?})"
,
local
);
// Check if any of the initializiations of `local` have happened yet:
let
mpi
=
self
.move_data.rev_lookup
.find_local
(
local
);
let
init_indices
=
&
self
.move_data.init_path_map
[
mpi
];
let
first_init_index
=
init_indices
.iter
()
.find
(|
ii
|
flow_state
.ever_inits
.contains
(
ii
));
if
let
Some
(
&
init_index
)
=
first_init_index
{
// And, if so, report an error.
let
init
=
&
self
.move_data.inits
[
init_index
];
self
.report_illegal_reassignment
(
context
,
place_span
,
init
.span
,
place_span
.0
);
}
}
...
...
src/test/ui/did_you_mean/issue-35937.nll.stderr
浏览文件 @
78e987ab
...
...
@@ -6,26 +6,23 @@ LL | let f = Foo { v: Vec::new() };
LL | f.v.push("cat".to_string()); //~ ERROR cannot borrow
| ^^^ cannot borrow as mutable
error[E0
384]: cannot assign twice to immutable variable `s`
error[E0
594]: cannot assign to `s.x`, as `s` is not declared as mutable
--> $DIR/issue-35937.rs:26:5
|
LL | let s = S { x: 42 };
| -
| |
| first assignment to `s`
| consider changing this to `mut s`
| - help: consider changing this to be mutable: `mut s`
LL | s.x += 1; //~ ERROR cannot assign
| ^^^^^^^^ cannot assign
twice to immutable variable
| ^^^^^^^^ cannot assign
error[E0
384]: cannot assign to immutable argument `s`
error[E0
594]: cannot assign to `s.x`, as `s` is not declared as mutable
--> $DIR/issue-35937.rs:30:5
|
LL | fn bar(s: S) {
| -
consider changing this to
`mut s`
| -
help: consider changing this to be mutable:
`mut s`
LL | s.x += 1; //~ ERROR cannot assign
| ^^^^^^^^ cannot assign
to immutable argument
| ^^^^^^^^ cannot assign
error: aborting due to 3 previous errors
Some errors occurred: E0
38
4, E0596.
For more information about an error, try `rustc --explain E0
38
4`.
Some errors occurred: E0
59
4, E0596.
For more information about an error, try `rustc --explain E0
59
4`.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录