Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
7732ad85
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
7732ad85
编写于
9月 03, 2015
作者:
M
Manish Goregaokar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move lints to HIR
上级
16619470
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
328 addition
and
337 deletion
+328
-337
src/librustc/lint/context.rs
src/librustc/lint/context.rs
+44
-47
src/librustc/lint/mod.rs
src/librustc/lint/mod.rs
+32
-31
src/librustc_driver/driver.rs
src/librustc_driver/driver.rs
+1
-1
src/librustc_lint/builtin.rs
src/librustc_lint/builtin.rs
+242
-248
src/test/auxiliary/lint_for_crate.rs
src/test/auxiliary/lint_for_crate.rs
+3
-3
src/test/auxiliary/lint_group_plugin_test.rs
src/test/auxiliary/lint_group_plugin_test.rs
+3
-3
src/test/auxiliary/lint_plugin_test.rs
src/test/auxiliary/lint_plugin_test.rs
+3
-4
未找到文件。
src/librustc/lint/context.rs
浏览文件 @
7732ad85
...
...
@@ -37,12 +37,14 @@
use
std
::
cmp
;
use
std
::
mem
;
use
syntax
::
ast_util
::
IdVisitingOperation
;
use
syntax
::
attr
::
AttrMetaMethods
;
use
syntax
::
attr
;
use
rustc_front
::
attr
::{
self
,
AttrMetaMethods
}
;
use
rustc_front
::
util
;
use
syntax
::
codemap
::
Span
;
use
syntax
::
visit
::{
Visitor
,
FnKind
};
use
syntax
::
parse
::
token
::
InternedString
;
use
syntax
::{
ast
,
ast_util
,
visit
};
use
syntax
::
ast
;
use
rustc_front
::
hir
;
use
rustc_front
::
visit
::{
self
,
Visitor
,
FnKind
};
use
syntax
::
visit
::
Visitor
as
SyntaxVisitor
;
use
syntax
::
diagnostic
;
/// Information about the registered lints.
...
...
@@ -252,7 +254,7 @@ pub struct Context<'a, 'tcx: 'a> {
pub
tcx
:
&
'a
ty
::
ctxt
<
'tcx
>
,
/// The crate being checked.
pub
krate
:
&
'a
ast
::
Crate
,
pub
krate
:
&
'a
hir
::
Crate
,
/// Items exported from the crate being checked.
pub
exported_items
:
&
'a
ExportedItems
,
...
...
@@ -284,7 +286,7 @@ pub struct Context<'a, 'tcx: 'a> {
/// Parse the lint attributes into a vector, with `Err`s for malformed lint
/// attributes. Writing this as an iterator is an enormous mess.
// See also the hir version just below.
pub
fn
gather_attrs
(
attrs
:
&
[
ast
::
Attribute
])
pub
fn
gather_attrs
(
attrs
:
&
[
hir
::
Attribute
])
->
Vec
<
Result
<
(
InternedString
,
Level
,
Span
),
Span
>>
{
let
mut
out
=
vec!
();
for
attr
in
attrs
{
...
...
@@ -297,7 +299,7 @@ pub fn gather_attrs(attrs: &[ast::Attribute])
let
meta
=
&
attr
.node.value
;
let
metas
=
match
meta
.node
{
ast
::
MetaList
(
_
,
ref
metas
)
=>
metas
,
hir
::
MetaList
(
_
,
ref
metas
)
=>
metas
,
_
=>
{
out
.push
(
Err
(
meta
.span
));
continue
;
...
...
@@ -306,7 +308,7 @@ pub fn gather_attrs(attrs: &[ast::Attribute])
for
meta
in
metas
{
out
.push
(
match
meta
.node
{
ast
::
MetaWord
(
ref
lint_name
)
=>
Ok
((
lint_name
.clone
(),
level
,
meta
.span
)),
hir
::
MetaWord
(
ref
lint_name
)
=>
Ok
((
lint_name
.clone
(),
level
,
meta
.span
)),
_
=>
Err
(
meta
.span
),
});
}
...
...
@@ -398,7 +400,7 @@ pub fn raw_emit_lint(sess: &Session, lint: &'static Lint,
impl
<
'a
,
'tcx
>
Context
<
'a
,
'tcx
>
{
fn
new
(
tcx
:
&
'a
ty
::
ctxt
<
'tcx
>
,
krate
:
&
'a
ast
::
Crate
,
krate
:
&
'a
hir
::
Crate
,
exported_items
:
&
'a
ExportedItems
)
->
Context
<
'a
,
'tcx
>
{
// We want to own the lint store, so move it out of the session.
let
lint_store
=
mem
::
replace
(
&
mut
*
tcx
.sess.lint_store
.borrow_mut
(),
...
...
@@ -452,7 +454,7 @@ pub fn span_lint(&self, lint: &'static Lint, span: Span, msg: &str) {
/// current lint context, call the provided function, then reset the
/// lints in effect to their previous state.
fn
with_lint_attrs
<
F
>
(
&
mut
self
,
attrs
:
&
[
ast
::
Attribute
],
attrs
:
&
[
hir
::
Attribute
],
f
:
F
)
where
F
:
FnOnce
(
&
mut
Context
),
{
...
...
@@ -519,9 +521,9 @@ fn with_lint_attrs<F>(&mut self,
}
fn
visit_ids
<
F
>
(
&
mut
self
,
f
:
F
)
where
F
:
FnOnce
(
&
mut
ast_
util
::
IdVisitor
<
Context
>
)
F
:
FnOnce
(
&
mut
util
::
IdVisitor
<
Context
>
)
{
let
mut
v
=
ast_
util
::
IdVisitor
{
let
mut
v
=
util
::
IdVisitor
{
operation
:
self
,
pass_through_items
:
false
,
visited_outermost
:
false
,
...
...
@@ -531,7 +533,7 @@ fn visit_ids<F>(&mut self, f: F) where
}
impl
<
'a
,
'tcx
,
'v
>
Visitor
<
'v
>
for
Context
<
'a
,
'tcx
>
{
fn
visit_item
(
&
mut
self
,
it
:
&
ast
::
Item
)
{
fn
visit_item
(
&
mut
self
,
it
:
&
hir
::
Item
)
{
self
.with_lint_attrs
(
&
it
.attrs
,
|
cx
|
{
run_lints!
(
cx
,
check_item
,
it
);
cx
.visit_ids
(|
v
|
v
.visit_item
(
it
));
...
...
@@ -539,52 +541,52 @@ fn visit_item(&mut self, it: &ast::Item) {
})
}
fn
visit_foreign_item
(
&
mut
self
,
it
:
&
ast
::
ForeignItem
)
{
fn
visit_foreign_item
(
&
mut
self
,
it
:
&
hir
::
ForeignItem
)
{
self
.with_lint_attrs
(
&
it
.attrs
,
|
cx
|
{
run_lints!
(
cx
,
check_foreign_item
,
it
);
visit
::
walk_foreign_item
(
cx
,
it
);
})
}
fn
visit_pat
(
&
mut
self
,
p
:
&
ast
::
Pat
)
{
fn
visit_pat
(
&
mut
self
,
p
:
&
hir
::
Pat
)
{
run_lints!
(
self
,
check_pat
,
p
);
visit
::
walk_pat
(
self
,
p
);
}
fn
visit_expr
(
&
mut
self
,
e
:
&
ast
::
Expr
)
{
fn
visit_expr
(
&
mut
self
,
e
:
&
hir
::
Expr
)
{
run_lints!
(
self
,
check_expr
,
e
);
visit
::
walk_expr
(
self
,
e
);
}
fn
visit_stmt
(
&
mut
self
,
s
:
&
ast
::
Stmt
)
{
fn
visit_stmt
(
&
mut
self
,
s
:
&
hir
::
Stmt
)
{
run_lints!
(
self
,
check_stmt
,
s
);
visit
::
walk_stmt
(
self
,
s
);
}
fn
visit_fn
(
&
mut
self
,
fk
:
FnKind
<
'v
>
,
decl
:
&
'v
ast
::
FnDecl
,
body
:
&
'v
ast
::
Block
,
span
:
Span
,
id
:
ast
::
NodeId
)
{
fn
visit_fn
(
&
mut
self
,
fk
:
FnKind
<
'v
>
,
decl
:
&
'v
hir
::
FnDecl
,
body
:
&
'v
hir
::
Block
,
span
:
Span
,
id
:
ast
::
NodeId
)
{
run_lints!
(
self
,
check_fn
,
fk
,
decl
,
body
,
span
,
id
);
visit
::
walk_fn
(
self
,
fk
,
decl
,
body
,
span
);
}
fn
visit_struct_def
(
&
mut
self
,
s
:
&
ast
::
StructDef
,
s
:
&
hir
::
StructDef
,
ident
:
ast
::
Ident
,
g
:
&
ast
::
Generics
,
g
:
&
hir
::
Generics
,
id
:
ast
::
NodeId
)
{
run_lints!
(
self
,
check_struct_def
,
s
,
ident
,
g
,
id
);
visit
::
walk_struct_def
(
self
,
s
);
run_lints!
(
self
,
check_struct_def_post
,
s
,
ident
,
g
,
id
);
}
fn
visit_struct_field
(
&
mut
self
,
s
:
&
ast
::
StructField
)
{
fn
visit_struct_field
(
&
mut
self
,
s
:
&
hir
::
StructField
)
{
self
.with_lint_attrs
(
&
s
.node.attrs
,
|
cx
|
{
run_lints!
(
cx
,
check_struct_field
,
s
);
visit
::
walk_struct_field
(
cx
,
s
);
})
}
fn
visit_variant
(
&
mut
self
,
v
:
&
ast
::
Variant
,
g
:
&
ast
::
Generics
)
{
fn
visit_variant
(
&
mut
self
,
v
:
&
hir
::
Variant
,
g
:
&
hir
::
Generics
)
{
self
.with_lint_attrs
(
&
v
.node.attrs
,
|
cx
|
{
run_lints!
(
cx
,
check_variant
,
v
,
g
);
visit
::
walk_variant
(
cx
,
v
,
g
);
...
...
@@ -592,7 +594,7 @@ fn visit_variant(&mut self, v: &ast::Variant, g: &ast::Generics) {
})
}
fn
visit_ty
(
&
mut
self
,
t
:
&
ast
::
Ty
)
{
fn
visit_ty
(
&
mut
self
,
t
:
&
hir
::
Ty
)
{
run_lints!
(
self
,
check_ty
,
t
);
visit
::
walk_ty
(
self
,
t
);
}
...
...
@@ -601,41 +603,41 @@ fn visit_ident(&mut self, sp: Span, id: ast::Ident) {
run_lints!
(
self
,
check_ident
,
sp
,
id
);
}
fn
visit_mod
(
&
mut
self
,
m
:
&
ast
::
Mod
,
s
:
Span
,
n
:
ast
::
NodeId
)
{
fn
visit_mod
(
&
mut
self
,
m
:
&
hir
::
Mod
,
s
:
Span
,
n
:
ast
::
NodeId
)
{
run_lints!
(
self
,
check_mod
,
m
,
s
,
n
);
visit
::
walk_mod
(
self
,
m
);
}
fn
visit_local
(
&
mut
self
,
l
:
&
ast
::
Local
)
{
fn
visit_local
(
&
mut
self
,
l
:
&
hir
::
Local
)
{
run_lints!
(
self
,
check_local
,
l
);
visit
::
walk_local
(
self
,
l
);
}
fn
visit_block
(
&
mut
self
,
b
:
&
ast
::
Block
)
{
fn
visit_block
(
&
mut
self
,
b
:
&
hir
::
Block
)
{
run_lints!
(
self
,
check_block
,
b
);
visit
::
walk_block
(
self
,
b
);
}
fn
visit_arm
(
&
mut
self
,
a
:
&
ast
::
Arm
)
{
fn
visit_arm
(
&
mut
self
,
a
:
&
hir
::
Arm
)
{
run_lints!
(
self
,
check_arm
,
a
);
visit
::
walk_arm
(
self
,
a
);
}
fn
visit_decl
(
&
mut
self
,
d
:
&
ast
::
Decl
)
{
fn
visit_decl
(
&
mut
self
,
d
:
&
hir
::
Decl
)
{
run_lints!
(
self
,
check_decl
,
d
);
visit
::
walk_decl
(
self
,
d
);
}
fn
visit_expr_post
(
&
mut
self
,
e
:
&
ast
::
Expr
)
{
fn
visit_expr_post
(
&
mut
self
,
e
:
&
hir
::
Expr
)
{
run_lints!
(
self
,
check_expr_post
,
e
);
}
fn
visit_generics
(
&
mut
self
,
g
:
&
ast
::
Generics
)
{
fn
visit_generics
(
&
mut
self
,
g
:
&
hir
::
Generics
)
{
run_lints!
(
self
,
check_generics
,
g
);
visit
::
walk_generics
(
self
,
g
);
}
fn
visit_trait_item
(
&
mut
self
,
trait_item
:
&
ast
::
TraitItem
)
{
fn
visit_trait_item
(
&
mut
self
,
trait_item
:
&
hir
::
TraitItem
)
{
self
.with_lint_attrs
(
&
trait_item
.attrs
,
|
cx
|
{
run_lints!
(
cx
,
check_trait_item
,
trait_item
);
cx
.visit_ids
(|
v
|
v
.visit_trait_item
(
trait_item
));
...
...
@@ -643,7 +645,7 @@ fn visit_trait_item(&mut self, trait_item: &ast::TraitItem) {
});
}
fn
visit_impl_item
(
&
mut
self
,
impl_item
:
&
ast
::
ImplItem
)
{
fn
visit_impl_item
(
&
mut
self
,
impl_item
:
&
hir
::
ImplItem
)
{
self
.with_lint_attrs
(
&
impl_item
.attrs
,
|
cx
|
{
run_lints!
(
cx
,
check_impl_item
,
impl_item
);
cx
.visit_ids
(|
v
|
v
.visit_impl_item
(
impl_item
));
...
...
@@ -651,34 +653,29 @@ fn visit_impl_item(&mut self, impl_item: &ast::ImplItem) {
});
}
fn
visit_opt_lifetime_ref
(
&
mut
self
,
sp
:
Span
,
lt
:
&
Option
<
ast
::
Lifetime
>
)
{
fn
visit_opt_lifetime_ref
(
&
mut
self
,
sp
:
Span
,
lt
:
&
Option
<
hir
::
Lifetime
>
)
{
run_lints!
(
self
,
check_opt_lifetime_ref
,
sp
,
lt
);
}
fn
visit_lifetime_ref
(
&
mut
self
,
lt
:
&
ast
::
Lifetime
)
{
fn
visit_lifetime_ref
(
&
mut
self
,
lt
:
&
hir
::
Lifetime
)
{
run_lints!
(
self
,
check_lifetime_ref
,
lt
);
}
fn
visit_lifetime_def
(
&
mut
self
,
lt
:
&
ast
::
LifetimeDef
)
{
fn
visit_lifetime_def
(
&
mut
self
,
lt
:
&
hir
::
LifetimeDef
)
{
run_lints!
(
self
,
check_lifetime_def
,
lt
);
}
fn
visit_explicit_self
(
&
mut
self
,
es
:
&
ast
::
ExplicitSelf
)
{
fn
visit_explicit_self
(
&
mut
self
,
es
:
&
hir
::
ExplicitSelf
)
{
run_lints!
(
self
,
check_explicit_self
,
es
);
visit
::
walk_explicit_self
(
self
,
es
);
}
fn
visit_mac
(
&
mut
self
,
mac
:
&
ast
::
Mac
)
{
run_lints!
(
self
,
check_mac
,
mac
);
visit
::
walk_mac
(
self
,
mac
);
}
fn
visit_path
(
&
mut
self
,
p
:
&
ast
::
Path
,
id
:
ast
::
NodeId
)
{
fn
visit_path
(
&
mut
self
,
p
:
&
hir
::
Path
,
id
:
ast
::
NodeId
)
{
run_lints!
(
self
,
check_path
,
p
,
id
);
visit
::
walk_path
(
self
,
p
);
}
fn
visit_attribute
(
&
mut
self
,
attr
:
&
ast
::
Attribute
)
{
fn
visit_attribute
(
&
mut
self
,
attr
:
&
hir
::
Attribute
)
{
run_lints!
(
self
,
check_attribute
,
attr
);
}
}
...
...
@@ -709,9 +706,9 @@ fn get_lints(&self) -> LintArray {
lint_array!
()
}
fn
check_item
(
&
mut
self
,
cx
:
&
Context
,
it
:
&
ast
::
Item
)
{
fn
check_item
(
&
mut
self
,
cx
:
&
Context
,
it
:
&
hir
::
Item
)
{
match
it
.node
{
ast
::
ItemEnum
(
..
)
=>
{
hir
::
ItemEnum
(
..
)
=>
{
let
lint_id
=
LintId
::
of
(
builtin
::
VARIANT_SIZE_DIFFERENCES
);
let
lvlsrc
=
cx
.lints
.get_level_source
(
lint_id
);
match
lvlsrc
{
...
...
@@ -731,7 +728,7 @@ fn check_item(&mut self, cx: &Context, it: &ast::Item) {
///
/// Consumes the `lint_store` field of the `Session`.
pub
fn
check_crate
(
tcx
:
&
ty
::
ctxt
,
krate
:
&
ast
::
Crate
,
krate
:
&
hir
::
Crate
,
exported_items
:
&
ExportedItems
)
{
let
mut
cx
=
Context
::
new
(
tcx
,
krate
,
exported_items
);
...
...
src/librustc/lint/mod.rs
浏览文件 @
7732ad85
...
...
@@ -34,8 +34,9 @@
use
std
::
hash
;
use
std
::
ascii
::
AsciiExt
;
use
syntax
::
codemap
::
Span
;
use
syntax
::
visit
::
FnKind
;
use
rustc_front
::
visit
::
FnKind
;
use
syntax
::
ast
;
use
rustc_front
::
hir
;
pub
use
lint
::
context
::{
Context
,
LintStore
,
raw_emit_lint
,
check_crate
,
gather_attrs
,
gather_attrs_from_hir
,
GatherNodeLevels
};
...
...
@@ -125,46 +126,46 @@ pub trait LintPass {
/// `Lint`, make it a private `static` item in its own module.
fn
get_lints
(
&
self
)
->
LintArray
;
fn
check_crate
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
Crate
)
{
}
fn
check_crate
(
&
mut
self
,
_
:
&
Context
,
_
:
&
hir
::
Crate
)
{
}
fn
check_ident
(
&
mut
self
,
_
:
&
Context
,
_
:
Span
,
_
:
ast
::
Ident
)
{
}
fn
check_mod
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
Mod
,
_
:
Span
,
_
:
ast
::
NodeId
)
{
}
fn
check_foreign_item
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
ForeignItem
)
{
}
fn
check_item
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
Item
)
{
}
fn
check_local
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
Local
)
{
}
fn
check_block
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
Block
)
{
}
fn
check_stmt
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
Stmt
)
{
}
fn
check_arm
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
Arm
)
{
}
fn
check_pat
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
Pat
)
{
}
fn
check_decl
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
Decl
)
{
}
fn
check_expr
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
Expr
)
{
}
fn
check_expr_post
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
Expr
)
{
}
fn
check_ty
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
Ty
)
{
}
fn
check_generics
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
Generics
)
{
}
fn
check_mod
(
&
mut
self
,
_
:
&
Context
,
_
:
&
hir
::
Mod
,
_
:
Span
,
_
:
ast
::
NodeId
)
{
}
fn
check_foreign_item
(
&
mut
self
,
_
:
&
Context
,
_
:
&
hir
::
ForeignItem
)
{
}
fn
check_item
(
&
mut
self
,
_
:
&
Context
,
_
:
&
hir
::
Item
)
{
}
fn
check_local
(
&
mut
self
,
_
:
&
Context
,
_
:
&
hir
::
Local
)
{
}
fn
check_block
(
&
mut
self
,
_
:
&
Context
,
_
:
&
hir
::
Block
)
{
}
fn
check_stmt
(
&
mut
self
,
_
:
&
Context
,
_
:
&
hir
::
Stmt
)
{
}
fn
check_arm
(
&
mut
self
,
_
:
&
Context
,
_
:
&
hir
::
Arm
)
{
}
fn
check_pat
(
&
mut
self
,
_
:
&
Context
,
_
:
&
hir
::
Pat
)
{
}
fn
check_decl
(
&
mut
self
,
_
:
&
Context
,
_
:
&
hir
::
Decl
)
{
}
fn
check_expr
(
&
mut
self
,
_
:
&
Context
,
_
:
&
hir
::
Expr
)
{
}
fn
check_expr_post
(
&
mut
self
,
_
:
&
Context
,
_
:
&
hir
::
Expr
)
{
}
fn
check_ty
(
&
mut
self
,
_
:
&
Context
,
_
:
&
hir
::
Ty
)
{
}
fn
check_generics
(
&
mut
self
,
_
:
&
Context
,
_
:
&
hir
::
Generics
)
{
}
fn
check_fn
(
&
mut
self
,
_
:
&
Context
,
_
:
FnKind
,
_
:
&
ast
::
FnDecl
,
_
:
&
ast
::
Block
,
_
:
Span
,
_
:
ast
::
NodeId
)
{
}
fn
check_trait_item
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
TraitItem
)
{
}
fn
check_impl_item
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
ImplItem
)
{
}
_
:
FnKind
,
_
:
&
hir
::
FnDecl
,
_
:
&
hir
::
Block
,
_
:
Span
,
_
:
ast
::
NodeId
)
{
}
fn
check_trait_item
(
&
mut
self
,
_
:
&
Context
,
_
:
&
hir
::
TraitItem
)
{
}
fn
check_impl_item
(
&
mut
self
,
_
:
&
Context
,
_
:
&
hir
::
ImplItem
)
{
}
fn
check_struct_def
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
StructDef
,
_
:
ast
::
Ident
,
_
:
&
ast
::
Generics
,
_
:
ast
::
NodeId
)
{
}
_
:
&
hir
::
StructDef
,
_
:
ast
::
Ident
,
_
:
&
hir
::
Generics
,
_
:
ast
::
NodeId
)
{
}
fn
check_struct_def_post
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
StructDef
,
_
:
ast
::
Ident
,
_
:
&
ast
::
Generics
,
_
:
ast
::
NodeId
)
{
}
fn
check_struct_field
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
StructField
)
{
}
fn
check_variant
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
Variant
,
_
:
&
ast
::
Generics
)
{
}
fn
check_variant_post
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
Variant
,
_
:
&
ast
::
Generics
)
{
}
fn
check_opt_lifetime_ref
(
&
mut
self
,
_
:
&
Context
,
_
:
Span
,
_
:
&
Option
<
ast
::
Lifetime
>
)
{
}
fn
check_lifetime_ref
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
Lifetime
)
{
}
fn
check_lifetime_def
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
LifetimeDef
)
{
}
fn
check_explicit_self
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
ExplicitSelf
)
{
}
_
:
&
hir
::
StructDef
,
_
:
ast
::
Ident
,
_
:
&
hir
::
Generics
,
_
:
ast
::
NodeId
)
{
}
fn
check_struct_field
(
&
mut
self
,
_
:
&
Context
,
_
:
&
hir
::
StructField
)
{
}
fn
check_variant
(
&
mut
self
,
_
:
&
Context
,
_
:
&
hir
::
Variant
,
_
:
&
hir
::
Generics
)
{
}
fn
check_variant_post
(
&
mut
self
,
_
:
&
Context
,
_
:
&
hir
::
Variant
,
_
:
&
hir
::
Generics
)
{
}
fn
check_opt_lifetime_ref
(
&
mut
self
,
_
:
&
Context
,
_
:
Span
,
_
:
&
Option
<
hir
::
Lifetime
>
)
{
}
fn
check_lifetime_ref
(
&
mut
self
,
_
:
&
Context
,
_
:
&
hir
::
Lifetime
)
{
}
fn
check_lifetime_def
(
&
mut
self
,
_
:
&
Context
,
_
:
&
hir
::
LifetimeDef
)
{
}
fn
check_explicit_self
(
&
mut
self
,
_
:
&
Context
,
_
:
&
hir
::
ExplicitSelf
)
{
}
fn
check_mac
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
Mac
)
{
}
fn
check_path
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
Path
,
_
:
ast
::
NodeId
)
{
}
fn
check_attribute
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
Attribute
)
{
}
fn
check_path
(
&
mut
self
,
_
:
&
Context
,
_
:
&
hir
::
Path
,
_
:
ast
::
NodeId
)
{
}
fn
check_attribute
(
&
mut
self
,
_
:
&
Context
,
_
:
&
hir
::
Attribute
)
{
}
/// Called when entering a syntax node that can have lint attributes such
/// as `#[allow(...)]`. Called with *all* the attributes of that node.
fn
enter_lint_attrs
(
&
mut
self
,
_
:
&
Context
,
_
:
&
[
ast
::
Attribute
])
{
}
fn
enter_lint_attrs
(
&
mut
self
,
_
:
&
Context
,
_
:
&
[
hir
::
Attribute
])
{
}
/// Counterpart to `enter_lint_attrs`.
fn
exit_lint_attrs
(
&
mut
self
,
_
:
&
Context
,
_
:
&
[
ast
::
Attribute
])
{
}
fn
exit_lint_attrs
(
&
mut
self
,
_
:
&
Context
,
_
:
&
[
hir
::
Attribute
])
{
}
}
/// A lint pass boxed up as a trait object.
...
...
src/librustc_driver/driver.rs
浏览文件 @
7732ad85
...
...
@@ -761,7 +761,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: Session,
&
tcx
.sess
,
lib_features_used
));
time
(
time_passes
,
"lint checking"
,
||
lint
::
check_crate
(
tcx
,
ast_crate
,
&
exported_items
));
lint
::
check_crate
(
tcx
,
&
lower_crate
(
ast_crate
)
,
&
exported_items
));
// The above three passes generate errors w/o aborting
tcx
.sess
.abort_if_errors
();
...
...
src/librustc_lint/builtin.rs
浏览文件 @
7732ad85
此差异已折叠。
点击以展开。
src/test/auxiliary/lint_for_crate.rs
浏览文件 @
7732ad85
...
...
@@ -13,12 +13,12 @@
#![feature(plugin_registrar,
rustc_private)]
#![feature(box_syntax)]
extern
crate
syntax
;
#[macro_use]
extern
crate
rustc
;
extern
crate
rustc_front
;
use
syntax
::{
ast
,
attr
};
use
rustc
::
lint
::{
Context
,
LintPass
,
LintPassObject
,
LintArray
};
use
rustc
::
plugin
::
Registry
;
use
rustc_front
::{
hir
,
attr
};
declare_lint!
(
CRATE_NOT_OKAY
,
Warn
,
"crate not marked with #![crate_okay]"
);
...
...
@@ -29,7 +29,7 @@ fn get_lints(&self) -> LintArray {
lint_array!
(
CRATE_NOT_OKAY
)
}
fn
check_crate
(
&
mut
self
,
cx
:
&
Context
,
krate
:
&
ast
::
Crate
)
{
fn
check_crate
(
&
mut
self
,
cx
:
&
Context
,
krate
:
&
hir
::
Crate
)
{
if
!
attr
::
contains_name
(
&
krate
.attrs
,
"crate_okay"
)
{
cx
.span_lint
(
CRATE_NOT_OKAY
,
krate
.span
,
"crate is not marked with #![crate_okay]"
);
...
...
src/test/auxiliary/lint_group_plugin_test.rs
浏览文件 @
7732ad85
...
...
@@ -13,13 +13,13 @@
#![feature(plugin_registrar)]
#![feature(box_syntax,
rustc_private)]
extern
crate
syntax
;
extern
crate
rustc_front
;
// Load rustc as a plugin to get macros
#[macro_use]
extern
crate
rustc
;
use
syntax
::
ast
;
use
rustc_front
::
hir
;
use
rustc
::
lint
::{
Context
,
LintPass
,
LintPassObject
,
LintArray
};
use
rustc
::
plugin
::
Registry
;
...
...
@@ -34,7 +34,7 @@ fn get_lints(&self) -> LintArray {
lint_array!
(
TEST_LINT
,
PLEASE_LINT
)
}
fn
check_item
(
&
mut
self
,
cx
:
&
Context
,
it
:
&
ast
::
Item
)
{
fn
check_item
(
&
mut
self
,
cx
:
&
Context
,
it
:
&
hir
::
Item
)
{
match
&*
it
.ident.name
.as_str
()
{
"lintme"
=>
cx
.span_lint
(
TEST_LINT
,
it
.span
,
"item is named 'lintme'"
),
"pleaselintme"
=>
cx
.span_lint
(
PLEASE_LINT
,
it
.span
,
"item is named 'pleaselintme'"
),
...
...
src/test/auxiliary/lint_plugin_test.rs
浏览文件 @
7732ad85
...
...
@@ -13,16 +13,15 @@
#![feature(plugin_registrar)]
#![feature(box_syntax,
rustc_private)]
extern
crate
syntax
;
extern
crate
rustc_front
;
// Load rustc as a plugin to get macros
#[macro_use]
extern
crate
rustc
;
use
syntax
::
ast
;
use
rustc
::
lint
::{
Context
,
LintPass
,
LintPassObject
,
LintArray
};
use
rustc
::
plugin
::
Registry
;
use
rustc_front
::
hir
;
declare_lint!
(
TEST_LINT
,
Warn
,
"Warn about items named 'lintme'"
);
struct
Pass
;
...
...
@@ -32,7 +31,7 @@ fn get_lints(&self) -> LintArray {
lint_array!
(
TEST_LINT
)
}
fn
check_item
(
&
mut
self
,
cx
:
&
Context
,
it
:
&
ast
::
Item
)
{
fn
check_item
(
&
mut
self
,
cx
:
&
Context
,
it
:
&
hir
::
Item
)
{
if
it
.ident.name
==
"lintme"
{
cx
.span_lint
(
TEST_LINT
,
it
.span
,
"item is named 'lintme'"
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录