Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
ca81d3dd
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,发现更多精彩内容 >>
提交
ca81d3dd
编写于
1月 13, 2016
作者:
B
Brian Anderson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rustc: Fix bugs in renamed and removed lints and re-add raw_pointer_derive
cc #30346
上级
b0eec55c
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
272 addition
and
38 deletion
+272
-38
src/librustc/lint/builtin.rs
src/librustc/lint/builtin.rs
+8
-1
src/librustc/lint/context.rs
src/librustc/lint/context.rs
+149
-35
src/librustc_lint/lib.rs
src/librustc_lint/lib.rs
+5
-2
src/test/compile-fail/lint-malformed.rs
src/test/compile-fail/lint-malformed.rs
+14
-0
src/test/compile-fail/lint-removed-cmdline.rs
src/test/compile-fail/lint-removed-cmdline.rs
+20
-0
src/test/compile-fail/lint-removed.rs
src/test/compile-fail/lint-removed.rs
+16
-0
src/test/compile-fail/lint-renamed-cmdline.rs
src/test/compile-fail/lint-renamed-cmdline.rs
+18
-0
src/test/compile-fail/lint-renamed.rs
src/test/compile-fail/lint-renamed.rs
+13
-0
src/test/compile-fail/lint-unknown-lint-cmdline.rs
src/test/compile-fail/lint-unknown-lint-cmdline.rs
+16
-0
src/test/compile-fail/lint-unknown-lint.rs
src/test/compile-fail/lint-unknown-lint.rs
+13
-0
未找到文件。
src/librustc/lint/builtin.rs
浏览文件 @
ca81d3dd
...
...
@@ -139,6 +139,12 @@
"unit struct or enum variant erroneously allowed to match via path::ident(..)"
}
declare_lint!
{
pub
RAW_POINTER_DERIVE
,
Warn
,
"uses of #[derive] with raw pointers are rarely correct"
}
/// Does nothing as a lint pass, but registers some `Lint`s
/// which are used by other parts of the compiler.
#[derive(Copy,
Clone)]
...
...
@@ -166,7 +172,8 @@ fn get_lints(&self) -> LintArray {
PRIVATE_IN_PUBLIC
,
INVALID_TYPE_PARAM_DEFAULT
,
MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT
,
CONST_ERR
CONST_ERR
,
RAW_POINTER_DERIVE
)
}
}
...
...
src/librustc/lint/context.rs
浏览文件 @
ca81d3dd
...
...
@@ -219,21 +219,10 @@ fn find_lint(&self, lint_name: &str, sess: &Session, span: Option<Span>)
{
match
self
.by_name
.get
(
lint_name
)
{
Some
(
&
Id
(
lint_id
))
=>
Ok
(
lint_id
),
Some
(
&
Renamed
(
ref
new_name
,
lint_id
))
=>
{
let
warning
=
format!
(
"lint {} has been renamed to {}"
,
lint_name
,
new_name
);
match
span
{
Some
(
span
)
=>
sess
.span_warn
(
span
,
&
warning
[
..
]),
None
=>
sess
.warn
(
&
warning
[
..
]),
};
Some
(
&
Renamed
(
_
,
lint_id
))
=>
{
Ok
(
lint_id
)
},
Some
(
&
Removed
(
ref
reason
))
=>
{
let
warning
=
format!
(
"lint {} has been removed: {}"
,
lint_name
,
reason
);
match
span
{
Some
(
span
)
=>
sess
.span_warn
(
span
,
&
warning
[
..
]),
None
=>
sess
.warn
(
&
warning
[
..
])
}
Err
(
FindLintError
::
Removed
)
},
None
=>
Err
(
FindLintError
::
NotFound
)
...
...
@@ -242,8 +231,12 @@ fn find_lint(&self, lint_name: &str, sess: &Session, span: Option<Span>)
pub
fn
process_command_line
(
&
mut
self
,
sess
:
&
Session
)
{
for
&
(
ref
lint_name
,
level
)
in
&
sess
.opts.lint_opts
{
check_lint_name_cmdline
(
sess
,
self
,
&
lint_name
[
..
],
level
);
match
self
.find_lint
(
&
lint_name
[
..
],
sess
,
None
)
{
Ok
(
lint_id
)
=>
self
.set_level
(
lint_id
,
(
level
,
CommandLine
)),
Err
(
FindLintError
::
Removed
)
=>
{
}
Err
(
_
)
=>
{
match
self
.lint_groups
.iter
()
.map
(|(
&
x
,
pair
)|
(
x
,
pair
.0
.clone
()))
.collect
::
<
FnvHashMap
<&
'static
str
,
...
...
@@ -255,8 +248,11 @@ pub fn process_command_line(&mut self, sess: &Session) {
self
.set_level
(
*
lint_id
,
(
level
,
CommandLine
)))
.collect
::
<
Vec
<
()
>>
();
}
None
=>
sess
.err
(
&
format!
(
"unknown {} flag: {}"
,
level
.as_str
(),
lint_name
)),
None
=>
{
// The lint or lint group doesn't exist.
// This is an error, but it was handled
// by check_lint_name_cmdline.
}
}
}
}
...
...
@@ -331,29 +327,39 @@ pub fn gather_attrs(attrs: &[ast::Attribute])
->
Vec
<
Result
<
(
InternedString
,
Level
,
Span
),
Span
>>
{
let
mut
out
=
vec!
();
for
attr
in
attrs
{
let
level
=
match
Level
::
from_str
(
&
attr
.name
())
{
None
=>
continue
,
Some
(
lvl
)
=>
lvl
,
};
let
r
=
gather_attr
(
attr
);
out
.extend
(
r
.into_iter
());
}
out
}
attr
::
mark_used
(
attr
);
pub
fn
gather_attr
(
attr
:
&
ast
::
Attribute
)
->
Vec
<
Result
<
(
InternedString
,
Level
,
Span
),
Span
>>
{
let
mut
out
=
vec!
();
let
meta
=
&
attr
.node.value
;
let
metas
=
match
meta
.node
{
ast
::
MetaList
(
_
,
ref
metas
)
=>
metas
,
_
=>
{
out
.push
(
Err
(
meta
.span
));
continue
;
}
};
let
level
=
match
Level
::
from_str
(
&
attr
.name
())
{
None
=>
return
out
,
Some
(
lvl
)
=>
lvl
,
};
for
meta
in
metas
{
out
.push
(
match
meta
.node
{
ast
::
MetaWord
(
ref
lint_name
)
=>
Ok
((
lint_name
.clone
(),
level
,
meta
.span
)),
_
=>
Err
(
meta
.span
),
});
attr
::
mark_used
(
attr
);
let
meta
=
&
attr
.node.value
;
let
metas
=
match
meta
.node
{
ast
::
MetaList
(
_
,
ref
metas
)
=>
metas
,
_
=>
{
out
.push
(
Err
(
meta
.span
));
return
out
;
}
};
for
meta
in
metas
{
out
.push
(
match
meta
.node
{
ast
::
MetaWord
(
ref
lint_name
)
=>
Ok
((
lint_name
.clone
(),
level
,
meta
.span
)),
_
=>
Err
(
meta
.span
),
});
}
out
}
...
...
@@ -555,9 +561,9 @@ fn with_lint_attrs<F>(&mut self,
(
*
lint_id
,
level
,
span
))
.collect
(),
None
=>
{
self
.span_lint
(
builtin
::
UNKNOWN_LINTS
,
span
,
&
format!
(
"unknown `{}` attribute: `{}`"
,
level
.as_str
(),
lint_name
));
// The lint or lint group doesn't exist.
// This is an error, but it was handled
// by check_lint_name_attribute.
continue
;
}
}
...
...
@@ -869,6 +875,7 @@ fn visit_path_list_item(&mut self, prefix: &hir::Path, item: &hir::PathListItem)
}
fn
visit_attribute
(
&
mut
self
,
attr
:
&
ast
::
Attribute
)
{
check_lint_name_attribute
(
self
,
attr
);
run_lints!
(
self
,
check_attribute
,
late_passes
,
attr
);
}
}
...
...
@@ -1082,6 +1089,113 @@ fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
}
}
enum
CheckLintNameResult
<
'a
>
{
Ok
,
// Lint doesn't exist
NoLint
,
// The lint is either renamed or removed and a warning was
// generated in the DiagnosticBuilder
Mentioned
(
DiagnosticBuilder
<
'a
>
)
}
/// Checks the name of a lint for its existence, and whether it was
/// renamed or removed. Generates a DiagnosticBuilder containing a
/// warning for renamed and removed lints. This is over both lint
/// names from attributes and those passed on the command line. Since
/// it emits non-fatal warnings and there are *two* lint passes that
/// inspect attributes, this is only run from the late pass to avoid
/// printing duplicate warnings.
fn
check_lint_name
<
'a
>
(
sess
:
&
'a
Session
,
lint_cx
:
&
LintStore
,
lint_name
:
&
str
,
span
:
Option
<
Span
>
)
->
CheckLintNameResult
<
'a
>
{
match
lint_cx
.by_name
.get
(
lint_name
)
{
Some
(
&
Renamed
(
ref
new_name
,
_
))
=>
{
let
warning
=
format!
(
"lint {} has been renamed to {}"
,
lint_name
,
new_name
);
let
db
=
match
span
{
Some
(
span
)
=>
sess
.struct_span_warn
(
span
,
&
warning
[
..
]),
None
=>
sess
.struct_warn
(
&
warning
[
..
]),
};
CheckLintNameResult
::
Mentioned
(
db
)
},
Some
(
&
Removed
(
ref
reason
))
=>
{
let
warning
=
format!
(
"lint {} has been removed: {}"
,
lint_name
,
reason
);
let
db
=
match
span
{
Some
(
span
)
=>
sess
.struct_span_warn
(
span
,
&
warning
[
..
]),
None
=>
sess
.struct_warn
(
&
warning
[
..
])
};
CheckLintNameResult
::
Mentioned
(
db
)
},
None
=>
{
match
lint_cx
.lint_groups
.get
(
lint_name
)
{
None
=>
{
CheckLintNameResult
::
NoLint
}
Some
(
_
)
=>
{
/* lint group exists */
CheckLintNameResult
::
Ok
}
}
}
Some
(
_
)
=>
{
/* lint exists */
CheckLintNameResult
::
Ok
}
}
}
// Checks the validity of lint names derived from attributes
fn
check_lint_name_attribute
(
cx
:
&
LateContext
,
attr
:
&
ast
::
Attribute
)
{
for
result
in
gather_attr
(
attr
)
{
match
result
{
Err
(
_
)
=>
{
// Malformed lint attr. Reported by with_lint_attrs
continue
;
}
Ok
((
lint_name
,
_
,
span
))
=>
{
match
check_lint_name
(
&
cx
.tcx.sess
,
&
cx
.lints
,
&
lint_name
[
..
],
Some
(
span
))
{
CheckLintNameResult
::
Ok
=>
(),
CheckLintNameResult
::
Mentioned
(
mut
db
)
=>
{
db
.emit
();
}
CheckLintNameResult
::
NoLint
=>
{
cx
.span_lint
(
builtin
::
UNKNOWN_LINTS
,
span
,
&
format!
(
"unknown lint: `{}`"
,
lint_name
));
}
}
}
}
}
}
// Checks the validity of lint names derived from the command line
fn
check_lint_name_cmdline
(
sess
:
&
Session
,
lint_cx
:
&
LintStore
,
lint_name
:
&
str
,
level
:
Level
)
{
let
db
=
match
check_lint_name
(
sess
,
lint_cx
,
lint_name
,
None
)
{
CheckLintNameResult
::
Ok
=>
None
,
CheckLintNameResult
::
Mentioned
(
db
)
=>
Some
(
db
),
CheckLintNameResult
::
NoLint
=>
{
Some
(
sess
.struct_err
(
&
format!
(
"unknown lint: `{}`"
,
lint_name
)))
}
};
if
let
Some
(
mut
db
)
=
db
{
let
msg
=
format!
(
"requested on the command line with `{} {}`"
,
match
level
{
Level
::
Allow
=>
"-A"
,
Level
::
Warn
=>
"-W"
,
Level
::
Deny
=>
"-D"
,
Level
::
Forbid
=>
"-F"
,
},
lint_name
);
db
.note
(
&
msg
);
db
.emit
();
}
}
/// Perform lint checking on a crate.
///
/// Consumes the `lint_store` field of the `Session`.
...
...
src/librustc_lint/lib.rs
浏览文件 @
ca81d3dd
...
...
@@ -151,9 +151,12 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
// We have one lint pass defined specially
store
.register_late_pass
(
sess
,
false
,
box
lint
::
GatherNodeLevels
);
//
Insert temporary renamings for a one-time deprecation
//
Register renamed and removed lints
store
.register_renamed
(
"unknown_features"
,
"unused_features"
);
store
.register_removed
(
"unsigned_negation"
,
"replaced by negate_unsigned feature gate"
);
store
.register_removed
(
"negate_unsigned"
,
"cast a signed value instead"
);
store
.register_removed
(
"raw_pointer_derive"
,
"using derive with raw pointers is ok"
);
// This was renamed to raw_pointer_derive, which was then removed,
// so it is also considered removed
store
.register_removed
(
"raw_pointer_deriving"
,
"using derive with raw pointers is ok"
);
}
src/test/compile-fail/lint-malformed.rs
0 → 100644
浏览文件 @
ca81d3dd
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![deny
=
"foo"
]
//~ ERR malformed lint attribute
#![allow(bar
=
"baz"
)]
//~ ERR malformed lint attribute
fn
main
()
{
}
src/test/compile-fail/lint-removed-cmdline.rs
0 → 100644
浏览文件 @
ca81d3dd
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// The raw_pointer_derived lint warns about its removal
// cc #30346
// compile-flags:-D raw_pointer_derive
// error-pattern:lint raw_pointer_derive has been removed
// error-pattern:requested on the command line with `-D raw_pointer_derive`
#[deny(warnings)]
fn
main
()
{
let
unused
=
();
}
src/test/compile-fail/lint-removed.rs
0 → 100644
浏览文件 @
ca81d3dd
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// The raw_pointer_derived lint only warns about its own removal
// cc #30346
#[deny(raw_pointer_derive)]
//~ WARN raw_pointer_derive has been removed
#[deny(warnings)]
fn
main
()
{
let
unused
=
();
}
//~ ERR unused
src/test/compile-fail/lint-renamed-cmdline.rs
0 → 100644
浏览文件 @
ca81d3dd
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// compile-flags:-D unknown_features
// error-pattern:lint unknown_features has been renamed to unused_features
// error-pattern:requested on the command line with `-D unknown_features`
// error-pattern:unused
#[deny(unused)]
fn
main
()
{
let
unused
=
();
}
src/test/compile-fail/lint-renamed.rs
0 → 100644
浏览文件 @
ca81d3dd
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#[deny(unknown_features)]
//~ WARN lint unknown_features has been renamed to unused_features
#[deny(unused)]
fn
main
()
{
let
unused
=
();
}
//~ ERR unused
src/test/compile-fail/lint-unknown-lint-cmdline.rs
0 → 100644
浏览文件 @
ca81d3dd
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// compile-flags:-D bogus
// error-pattern:unknown lint
// error-pattern:requested on the command line with `-D bogus`
fn
main
()
{
}
src/test/compile-fail/lint-unknown-lint.rs
0 → 100644
浏览文件 @
ca81d3dd
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![allow(not_a_real_lint)]
//~ WARN unknown lint
#![deny(unused)]
fn
main
()
{
let
unused
=
();
}
//~ ERR unused variable
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录