Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
25937942
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,发现更多精彩内容 >>
提交
25937942
编写于
1月 08, 2016
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revamp the "future incompatible" section to clarify the situation
better
上级
7cffc9b1
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
76 addition
and
21 deletion
+76
-21
src/librustc/lint/builtin.rs
src/librustc/lint/builtin.rs
+0
-3
src/librustc/lint/context.rs
src/librustc/lint/context.rs
+37
-6
src/librustc/lint/mod.rs
src/librustc/lint/mod.rs
+1
-1
src/librustc_lint/lib.rs
src/librustc_lint/lib.rs
+23
-3
src/librustc_privacy/lib.rs
src/librustc_privacy/lib.rs
+1
-1
src/librustc_typeck/check/_match.rs
src/librustc_typeck/check/_match.rs
+1
-5
src/librustc_typeck/collect.rs
src/librustc_typeck/collect.rs
+2
-2
src/libsyntax/errors/mod.rs
src/libsyntax/errors/mod.rs
+11
-0
未找到文件。
src/librustc/lint/builtin.rs
浏览文件 @
25937942
...
...
@@ -16,9 +16,6 @@
use
lint
::{
LintPass
,
LateLintPass
,
LintArray
};
// name of the future-incompatible group
pub
const
FUTURE_INCOMPATIBLE
:
&
'static
str
=
"future_incompatible"
;
declare_lint!
{
pub
CONST_ERR
,
Warn
,
...
...
src/librustc/lint/context.rs
浏览文件 @
25937942
...
...
@@ -75,10 +75,22 @@ pub struct LintStore {
/// is true if the lint group was added by a plugin.
lint_groups
:
FnvHashMap
<&
'static
str
,
(
Vec
<
LintId
>
,
bool
)
>
,
/// Extra info for future incompatibility lints, descibing the
/// issue or RFC that caused the incompatibility.
future_incompatible
:
FnvHashMap
<
LintId
,
FutureIncompatibleInfo
>
,
/// Maximum level a lint can be
lint_cap
:
Option
<
Level
>
,
}
/// Extra information for a future incompatibility lint. See the call
/// to `register_future_incompatible` in `librustc_lint/lib.rs` for
/// guidelines.
pub
struct
FutureIncompatibleInfo
{
pub
id
:
LintId
,
pub
reference
:
&
'static
str
// e.g., a URL for an issue/PR/RFC or error code
}
/// The targed of the `by_name` map, which accounts for renaming/deprecation.
enum
TargetLint
{
/// A direct lint target
...
...
@@ -123,6 +135,7 @@ pub fn new() -> LintStore {
late_passes
:
Some
(
vec!
()),
by_name
:
FnvHashMap
(),
levels
:
FnvHashMap
(),
future_incompatible
:
FnvHashMap
(),
lint_groups
:
FnvHashMap
(),
lint_cap
:
None
,
}
...
...
@@ -182,6 +195,20 @@ fn push_pass<P: LintPass + ?Sized + 'static>(&mut self,
}
}
pub
fn
register_future_incompatible
(
&
mut
self
,
sess
:
Option
<&
Session
>
,
lints
:
Vec
<
FutureIncompatibleInfo
>
)
{
let
ids
=
lints
.iter
()
.map
(|
f
|
f
.id
)
.collect
();
self
.register_group
(
sess
,
false
,
"future_incompatible"
,
ids
);
for
info
in
lints
{
self
.future_incompatible
.insert
(
info
.id
,
info
);
}
}
pub
fn
future_incompatible
(
&
self
,
id
:
LintId
)
->
Option
<&
FutureIncompatibleInfo
>
{
self
.future_incompatible
.get
(
&
id
)
}
pub
fn
register_group
(
&
mut
self
,
sess
:
Option
<&
Session
>
,
from_plugin
:
bool
,
name
:
&
'static
str
,
to
:
Vec
<
LintId
>
)
{
...
...
@@ -417,14 +444,18 @@ pub fn raw_struct_lint<'a>(sess: &'a Session,
};
// Check for future incompatibility lints and issue a stronger warning.
let
future_incompat_lints
=
&
lints
.lint_groups
[
builtin
::
FUTURE_INCOMPATIBLE
];
let
this_id
=
LintId
::
of
(
lint
);
if
future_incompat_lints
.0
.iter
()
.any
(|
&
id
|
id
==
this_id
)
{
let
msg
=
"this lint will become a HARD ERROR in a future release!"
;
if
let
Some
(
future_incompatible
)
=
lints
.future_incompatible
(
LintId
::
of
(
lint
))
{
let
explanation
=
format!
(
"this was previously accepted by the compiler
\
but is being phased out,
\
and will become a HARD ERROR in a future release!"
);
let
citation
=
format!
(
"for more information, see {}"
,
future_incompatible
.reference
);
if
let
Some
(
sp
)
=
span
{
err
.span_note
(
sp
,
msg
);
err
.span_warn
(
sp
,
&
explanation
);
err
.span_note
(
sp
,
&
citation
);
}
else
{
err
.note
(
msg
);
err
.warn
(
&
explanation
);
err
.note
(
&
citation
);
}
}
...
...
src/librustc/lint/mod.rs
浏览文件 @
25937942
...
...
@@ -41,7 +41,7 @@
pub
use
lint
::
context
::{
LateContext
,
EarlyContext
,
LintContext
,
LintStore
,
raw_emit_lint
,
check_crate
,
check_ast_crate
,
gather_attrs
,
raw_struct_lint
,
GatherNodeLevels
};
raw_struct_lint
,
GatherNodeLevels
,
FutureIncompatibleInfo
};
/// Specification of a single lint.
#[derive(Copy,
Clone,
Debug)]
...
...
src/librustc_lint/lib.rs
浏览文件 @
25937942
...
...
@@ -54,6 +54,7 @@
use
session
::
Session
;
use
lint
::
LintId
;
use
lint
::
FutureIncompatibleInfo
;
mod
bad_style
;
mod
builtin
;
...
...
@@ -144,9 +145,28 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
UNUSED_MUT
,
UNREACHABLE_CODE
,
UNUSED_MUST_USE
,
UNUSED_UNSAFE
,
PATH_STATEMENTS
,
UNUSED_ATTRIBUTES
);
add_lint_group!
(
sess
,
FUTURE_INCOMPATIBLE
,
PRIVATE_IN_PUBLIC
,
INVALID_TYPE_PARAM_DEFAULT
,
MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT
);
// Guidelines for creating a future incompatibility lint:
//
// - Create a lint defaulting to warn as normal, with ideally the same error
// message you would normally give
// - Add a suitable reference, typically an RFC or tracking issue. Go ahead
// and include the full URL.
// - Later, change lint to error
// - Eventually, remove lint
store
.register_future_incompatible
(
sess
,
vec!
[
FutureIncompatibleInfo
{
id
:
LintId
::
of
(
PRIVATE_IN_PUBLIC
),
reference
:
"the explanation for E0446 (`--explain E0446`)"
,
},
FutureIncompatibleInfo
{
id
:
LintId
::
of
(
INVALID_TYPE_PARAM_DEFAULT
),
reference
:
"PR 30742 <https://github.com/rust-lang/rust/pull/30724>"
,
},
FutureIncompatibleInfo
{
id
:
LintId
::
of
(
MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT
),
reference
:
"RFC 218 <https://github.com/rust-lang/rfcs/blob/master/text/0218-empty-struct-with-braces.md>"
,
},
]);
// We have one lint pass defined specially
store
.register_late_pass
(
sess
,
false
,
box
lint
::
GatherNodeLevels
);
...
...
src/librustc_privacy/lib.rs
浏览文件 @
25937942
...
...
@@ -1528,7 +1528,7 @@ fn visit_ty(&mut self, ty: &hir::Ty) {
lint
::
builtin
::
PRIVATE_IN_PUBLIC
,
node_id
,
ty
.span
,
"private type in public interface (error E0446)"
.to_string
()
format!
(
"private type in public interface"
),
);
}
}
...
...
src/librustc_typeck/check/_match.rs
浏览文件 @
25937942
...
...
@@ -595,14 +595,10 @@ fn bad_struct_kind_err(sess: &Session, pat: &hir::Pat, path: &hir::Path, lint: b
let
name
=
pprust
::
path_to_string
(
path
);
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
);
msg
);
}
else
{
span_err!
(
sess
,
pat
.span
,
E0164
,
"{}"
,
msg
);
}
...
...
src/librustc_typeck/collect.rs
浏览文件 @
25937942
...
...
@@ -1917,8 +1917,8 @@ fn get_or_create_type_parameter_def<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
lint
::
builtin
::
INVALID_TYPE_PARAM_DEFAULT
,
param
.id
,
param
.span
,
format!
(
"defaults for type parameters are only allowed
\
on `struct` or `enum` definitions (see issue #27336)
"
));
format!
(
"defaults for type parameters are only allowed
on type definitions,
\
like `struct` or `enum`
"
));
}
}
...
...
src/libsyntax/errors/mod.rs
浏览文件 @
25937942
...
...
@@ -160,6 +160,17 @@ pub fn span_note(&mut self ,
self
.sub
(
Level
::
Note
,
msg
,
Some
(
sp
),
None
);
self
}
pub
fn
warn
(
&
mut
self
,
msg
:
&
str
)
->
&
mut
DiagnosticBuilder
<
'a
>
{
self
.sub
(
Level
::
Warning
,
msg
,
None
,
None
);
self
}
pub
fn
span_warn
(
&
mut
self
,
sp
:
Span
,
msg
:
&
str
)
->
&
mut
DiagnosticBuilder
<
'a
>
{
self
.sub
(
Level
::
Warning
,
msg
,
Some
(
sp
),
None
);
self
}
pub
fn
help
(
&
mut
self
,
msg
:
&
str
)
->
&
mut
DiagnosticBuilder
<
'a
>
{
self
.sub
(
Level
::
Help
,
msg
,
None
,
None
);
self
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录