Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
40e2ac28
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,发现更多精彩内容 >>
提交
40e2ac28
编写于
1月 08, 2016
作者:
F
Felix S. Klock II
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added proper lint for the unit variant/struct warning.
上级
8aed830e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
27 addition
and
16 deletion
+27
-16
src/librustc/lint/builtin.rs
src/librustc/lint/builtin.rs
+7
-0
src/librustc_lint/lib.rs
src/librustc_lint/lib.rs
+2
-1
src/librustc_typeck/check/_match.rs
src/librustc_typeck/check/_match.rs
+18
-15
未找到文件。
src/librustc/lint/builtin.rs
浏览文件 @
40e2ac28
...
...
@@ -133,6 +133,12 @@
"type parameter default erroneously allowed in invalid location"
}
declare_lint!
{
pub
MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT
,
Warn
,
"unit struct or enum variant erroneously allowed to match via path::ident(..)"
}
/// Does nothing as a lint pass, but registers some `Lint`s
/// which are used by other parts of the compiler.
#[derive(Copy,
Clone)]
...
...
@@ -159,6 +165,7 @@ fn get_lints(&self) -> LintArray {
TRIVIAL_NUMERIC_CASTS
,
PRIVATE_IN_PUBLIC
,
INVALID_TYPE_PARAM_DEFAULT
,
MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT
,
CONST_ERR
)
}
...
...
src/librustc_lint/lib.rs
浏览文件 @
40e2ac28
...
...
@@ -144,7 +144,8 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
UNUSED_UNSAFE
,
PATH_STATEMENTS
,
UNUSED_ATTRIBUTES
);
add_lint_group!
(
sess
,
FUTURE_INCOMPATIBLE
,
PRIVATE_IN_PUBLIC
,
INVALID_TYPE_PARAM_DEFAULT
);
PRIVATE_IN_PUBLIC
,
INVALID_TYPE_PARAM_DEFAULT
,
MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT
);
// We have one lint pass defined specially
store
.register_late_pass
(
sess
,
false
,
box
lint
::
GatherNodeLevels
);
...
...
src/librustc_typeck/check/_match.rs
浏览文件 @
40e2ac28
...
...
@@ -19,6 +19,7 @@
use
check
::{
check_expr_coercable_to_type
,
demand
,
FnCtxt
,
Expectation
};
use
check
::{
check_expr_with_lvalue_pref
};
use
check
::{
instantiate_path
,
resolve_ty_and_def_ufcs
,
structurally_resolved_type
};
use
lint
;
use
require_same_types
;
use
util
::
nodemap
::
FnvHashMap
;
use
session
::
Session
;
...
...
@@ -138,7 +139,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
if
pat_is_resolved_const
(
&
tcx
.def_map
.borrow
(),
pat
)
=>
{
if
let
hir
::
PatEnum
(
ref
path
,
ref
subpats
)
=
pat
.node
{
if
!
(
subpats
.is_some
()
&&
subpats
.as_ref
()
.unwrap
()
.is_empty
())
{
bad_struct_kind_err
(
tcx
.sess
,
pat
.span
,
path
,
false
);
bad_struct_kind_err
(
tcx
.sess
,
pat
,
path
,
false
);
return
;
}
}
...
...
@@ -590,10 +591,21 @@ pub fn check_pat_struct<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, pat: &'tcx hir::Pat,
}
// This function exists due to the warning "diagnostic code E0164 already used"
fn
bad_struct_kind_err
(
sess
:
&
Session
,
span
:
Span
,
path
:
&
hir
::
Path
,
is_warning
:
bool
)
{
fn
bad_struct_kind_err
(
sess
:
&
Session
,
pat
:
&
hir
::
Pat
,
path
:
&
hir
::
Path
,
lint
:
bool
)
{
let
name
=
pprust
::
path_to_string
(
path
);
span_err_or_warn!
(
is_warning
,
sess
,
span
,
E0164
,
"`{}` does not name a tuple variant or a tuple struct"
,
name
);
let
msg
=
format!
(
"`{}` does not name a tuple variant or a tuple struct"
,
name
);
if
lint
{
let
expanded_msg
=
format!
(
"{}; RFC 218 disallowed matching of unit variants or unit structs via {}(..)"
,
msg
,
name
);
sess
.add_lint
(
lint
::
builtin
::
MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT
,
pat
.id
,
pat
.span
,
expanded_msg
);
}
else
{
span_err!
(
sess
,
pat
.span
,
E0164
,
"{}"
,
msg
);
}
}
pub
fn
check_pat_enum
<
'a
,
'tcx
>
(
pcx
:
&
pat_ctxt
<
'a
,
'tcx
>
,
...
...
@@ -657,17 +669,8 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
opt_ty
,
def
,
pat
.span
,
pat
.id
);
let
report_bad_struct_kind
=
|
is_warning
|
{
bad_struct_kind_err
(
tcx
.sess
,
pat
.span
,
path
,
is_warning
);
if
is_warning
{
// Boo! Too painful to attach this to the actual warning,
// it should go away at some point though.
tcx
.sess
.span_note_without_error
(
pat
.span
,
"this warning will become a HARD ERROR in a future release.
\
See RFC 218 for details."
);
return
;
}
bad_struct_kind_err
(
tcx
.sess
,
pat
,
path
,
is_warning
);
if
is_warning
{
return
;
}
fcx
.write_error
(
pat
.id
);
if
let
Some
(
subpats
)
=
subpats
{
for
pat
in
subpats
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录