Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
aed53f9b
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,发现更多精彩内容 >>
提交
aed53f9b
编写于
5月 30, 2013
作者:
A
Alex Crichton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Promote unreachable code to being a lint attribute
上级
237dce12
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
37 addition
and
21 deletion
+37
-21
src/librustc/middle/lint.rs
src/librustc/middle/lint.rs
+8
-0
src/librustc/middle/typeck/check/mod.rs
src/librustc/middle/typeck/check/mod.rs
+5
-2
src/test/compile-fail/dead-code-ret.rs
src/test/compile-fail/dead-code-ret.rs
+3
-7
src/test/compile-fail/issue-2150.rs
src/test/compile-fail/issue-2150.rs
+6
-3
src/test/compile-fail/issue-897-2.rs
src/test/compile-fail/issue-897-2.rs
+4
-2
src/test/compile-fail/issue-897.rs
src/test/compile-fail/issue-897.rs
+4
-2
src/test/compile-fail/liveness-break-uninit-2.rs
src/test/compile-fail/liveness-break-uninit-2.rs
+1
-1
src/test/compile-fail/liveness-break-uninit.rs
src/test/compile-fail/liveness-break-uninit.rs
+1
-1
src/test/compile-fail/unreachable-code.rs
src/test/compile-fail/unreachable-code.rs
+5
-3
未找到文件。
src/librustc/middle/lint.rs
浏览文件 @
aed53f9b
...
...
@@ -96,6 +96,7 @@ pub enum lint {
unnecessary_allocation
,
missing_doc
,
unreachable_code
,
}
pub
fn
level_to_str
(
lv
:
level
)
->
&
'static
str
{
...
...
@@ -273,6 +274,13 @@ enum LintSource {
desc
:
"detects missing documentation for public members"
,
default
:
allow
}),
(
"unreachable_code"
,
LintSpec
{
lint
:
unreachable_code
,
desc
:
"detects unreachable code"
,
default
:
warn
}),
];
/*
...
...
src/librustc/middle/typeck/check/mod.rs
浏览文件 @
aed53f9b
...
...
@@ -81,6 +81,7 @@
use
middle
::
const_eval
;
use
middle
::
pat_util
::
pat_id_map
;
use
middle
::
pat_util
;
use
middle
::
lint
::
unreachable_code
;
use
middle
::
ty
::{
FnSig
,
VariantInfo_
};
use
middle
::
ty
::{
ty_param_bounds_and_ty
,
ty_param_substs_and_ty
};
use
middle
::
ty
::{
substs
,
param_ty
};
...
...
@@ -2937,7 +2938,8 @@ pub fn check_block_with_expected(fcx: @mut FnCtxt,
let
mut
any_err
=
false
;
for
blk
.node.stmts.each
|
s
|
{
check_stmt
(
fcx
,
*
s
);
let
s_ty
=
fcx
.node_ty
(
ast_util
::
stmt_id
(
*
s
));
let
s_id
=
ast_util
::
stmt_id
(
*
s
);
let
s_ty
=
fcx
.node_ty
(
s_id
);
if
last_was_bot
&&
!
warned
&&
match
s
.node
{
ast
::
stmt_decl
(
@
codemap
::
spanned
{
node
:
ast
::
decl_local
(
_
),
_
},
_
)
|
...
...
@@ -2946,7 +2948,8 @@ pub fn check_block_with_expected(fcx: @mut FnCtxt,
}
_
=>
false
}
{
fcx
.ccx.tcx.sess
.span_warn
(
s
.span
,
"unreachable statement"
);
fcx
.ccx.tcx.sess
.add_lint
(
unreachable_code
,
s_id
,
s
.span
,
~
"unreachable statement"
);
warned
=
true
;
}
if
ty
::
type_is_bot
(
s_ty
)
{
...
...
src/test/compile-fail/dead-code-ret.rs
浏览文件 @
aed53f9b
...
...
@@ -9,13 +9,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn
f
(
caller
:
&
str
)
{
debug!
(
caller
);
let
x
:
uint
=
0u32
;
// induce type error //~ ERROR mismatched types
}
#[deny(unreachable_code)]
;
fn
main
()
{
return
f
(
"main"
)
;
debug!
(
"Paul is dead"
);
//~
WARNING
unreachable
return
;
debug!
(
"Paul is dead"
);
//~
ERROR:
unreachable
}
src/test/compile-fail/issue-2150.rs
浏览文件 @
aed53f9b
...
...
@@ -8,11 +8,14 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#[deny(unreachable_code)]
;
#[allow(unused_variable)]
;
fn
fail_len
(
v
:
~
[
int
])
->
uint
{
let
mut
i
=
fail
!
();
let
mut
i
=
3
;
fail
!
();
for
v
.each
|
x
|
{
i
+=
1u
;
}
//~^ WARNING unreachable statement
//~^^ ERROR the type of this value must be known
//~^ ERROR: unreachable statement
return
i
;
}
fn
main
()
{}
src/test/compile-fail/issue-897-2.rs
浏览文件 @
aed53f9b
...
...
@@ -8,9 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#[deny(unreachable_code)]
;
fn
g
()
->
!
{
fail
!
();
}
fn
f
()
->
!
{
return
42
i
;
//~ ERROR expected `!` but found `int`
g
();
//~
WARNING
unreachable statement
return
g
();
g
();
//~
ERROR:
unreachable statement
}
fn
main
()
{
}
src/test/compile-fail/issue-897.rs
浏览文件 @
aed53f9b
...
...
@@ -8,8 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#[deny(unreachable_code)]
;
fn
f
()
->
!
{
return
42
i
;
//~ ERROR expected `!` but found `int`
fail
!
();
//~
WARNING
unreachable statement
return
fail
!
();
fail
!
();
//~
ERROR:
unreachable statement
}
fn
main
()
{
}
src/test/compile-fail/liveness-break-uninit-2.rs
浏览文件 @
aed53f9b
...
...
@@ -13,7 +13,7 @@ fn foo() -> int {
while
1
!=
2
{
break
;
x
=
0
;
//~ WARNING unreachable statement
x
=
0
;
}
debug!
(
x
);
//~ ERROR use of possibly uninitialized variable: `x`
...
...
src/test/compile-fail/liveness-break-uninit.rs
浏览文件 @
aed53f9b
...
...
@@ -13,7 +13,7 @@ fn foo() -> int {
loop
{
break
;
x
=
0
;
//~ WARNING unreachable statement
x
=
0
;
}
debug!
(
x
);
//~ ERROR use of possibly uninitialized variable: `x`
...
...
src/test/compile-fail/unreachable-code.rs
浏览文件 @
aed53f9b
...
...
@@ -8,9 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern:unreachable statement
#[deny(unreachable_code)]
;
#[allow(unused_variable)]
;
fn
main
()
{
loop
{}
// red herring to make sure compilation fails
error!
(
42
==
'c'
);
let
a
=
3
;
//~ ERROR: unreachable statement
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录