Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
08ca2360
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,发现更多精彩内容 >>
提交
08ca2360
编写于
10月 04, 2019
作者:
J
jack-t
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add lint for unnecessary parens around types
上级
032a53a0
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
65 addition
and
27 deletion
+65
-27
src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs
...infer/error_reporting/nice_region_error/find_anon_type.rs
+1
-1
src/librustc_data_structures/owning_ref/mod.rs
src/librustc_data_structures/owning_ref/mod.rs
+4
-4
src/librustc_lint/unused.rs
src/librustc_lint/unused.rs
+19
-0
src/librustc_mir/borrow_check/prefixes.rs
src/librustc_mir/borrow_check/prefixes.rs
+1
-1
src/libstd/collections/hash/map.rs
src/libstd/collections/hash/map.rs
+3
-3
src/test/ui/alignment-gep-tup-like-1.rs
src/test/ui/alignment-gep-tup-like-1.rs
+1
-1
src/test/ui/as-precedence.rs
src/test/ui/as-precedence.rs
+1
-0
src/test/ui/close-over-big-then-small-data.rs
src/test/ui/close-over-big-then-small-data.rs
+1
-1
src/test/ui/functions-closures/closure-to-fn-coercion.rs
src/test/ui/functions-closures/closure-to-fn-coercion.rs
+1
-1
src/test/ui/lint/lint-unnecessary-parens.rs
src/test/ui/lint/lint-unnecessary-parens.rs
+12
-0
src/test/ui/lint/lint-unnecessary-parens.stderr
src/test/ui/lint/lint-unnecessary-parens.stderr
+18
-12
src/test/ui/single-use-lifetime/zero-uses-in-fn.fixed
src/test/ui/single-use-lifetime/zero-uses-in-fn.fixed
+1
-1
src/test/ui/single-use-lifetime/zero-uses-in-fn.rs
src/test/ui/single-use-lifetime/zero-uses-in-fn.rs
+1
-1
src/test/ui/single-use-lifetime/zero-uses-in-fn.stderr
src/test/ui/single-use-lifetime/zero-uses-in-fn.stderr
+1
-1
未找到文件。
src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs
浏览文件 @
08ca2360
...
...
@@ -62,7 +62,7 @@ fn find_component_for_bound_region(
&
self
,
arg
:
&
'tcx
hir
::
Ty
,
br
:
&
ty
::
BoundRegion
,
)
->
Option
<
(
&
'tcx
hir
::
Ty
)
>
{
)
->
Option
<
&
'tcx
hir
::
Ty
>
{
let
mut
nested_visitor
=
FindNestedTypeVisitor
{
tcx
:
self
.tcx
(),
bound_region
:
*
br
,
...
...
src/librustc_data_structures/owning_ref/mod.rs
浏览文件 @
08ca2360
...
...
@@ -1046,14 +1046,14 @@ unsafe impl<O, T: ?Sized> CloneStableAddress for OwningRef<O, T>
where
O
:
CloneStableAddress
{}
unsafe
impl
<
O
,
T
:
?
Sized
>
Send
for
OwningRef
<
O
,
T
>
where
O
:
Send
,
for
<
'a
>
(
&
'a
T
)
:
Send
{}
where
O
:
Send
,
for
<
'a
>
&
'a
T
:
Send
{}
unsafe
impl
<
O
,
T
:
?
Sized
>
Sync
for
OwningRef
<
O
,
T
>
where
O
:
Sync
,
for
<
'a
>
(
&
'a
T
)
:
Sync
{}
where
O
:
Sync
,
for
<
'a
>
&
'a
T
:
Sync
{}
unsafe
impl
<
O
,
T
:
?
Sized
>
Send
for
OwningRefMut
<
O
,
T
>
where
O
:
Send
,
for
<
'a
>
(
&
'a
mut
T
)
:
Send
{}
where
O
:
Send
,
for
<
'a
>
&
'a
mut
T
:
Send
{}
unsafe
impl
<
O
,
T
:
?
Sized
>
Sync
for
OwningRefMut
<
O
,
T
>
where
O
:
Sync
,
for
<
'a
>
(
&
'a
mut
T
)
:
Sync
{}
where
O
:
Sync
,
for
<
'a
>
&
'a
mut
T
:
Sync
{}
impl
Debug
for
dyn
Erased
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
<
'_
>
)
->
fmt
::
Result
{
...
...
src/librustc_lint/unused.rs
浏览文件 @
08ca2360
...
...
@@ -603,6 +603,25 @@ fn check_param(&mut self, cx: &EarlyContext<'_>, param: &ast::Param) {
fn
check_arm
(
&
mut
self
,
cx
:
&
EarlyContext
<
'_
>
,
arm
:
&
ast
::
Arm
)
{
self
.check_unused_parens_pat
(
cx
,
&
arm
.pat
,
false
,
false
);
}
fn
check_ty
(
&
mut
self
,
cx
:
&
EarlyContext
<
'_
>
,
ty
:
&
ast
::
Ty
)
{
if
let
&
ast
::
TyKind
::
Paren
(
ref
r
)
=
&
ty
.kind
{
match
&
r
.kind
{
&
ast
::
TyKind
::
TraitObject
(
..
)
=>
{}
&
ast
::
TyKind
::
ImplTrait
(
_
,
ref
bounds
)
if
bounds
.len
()
>
1
=>
{}
_
=>
{
let
pattern_text
=
if
let
Ok
(
snippet
)
=
cx
.sess
()
.source_map
()
.span_to_snippet
(
ty
.span
)
{
snippet
}
else
{
pprust
::
ty_to_string
(
ty
)
};
Self
::
remove_outer_parens
(
cx
,
ty
.span
,
&
pattern_text
,
"type"
,
(
false
,
false
));
}
}
}
}
}
declare_lint!
{
...
...
src/librustc_mir/borrow_check/prefixes.rs
浏览文件 @
08ca2360
...
...
@@ -29,7 +29,7 @@ pub(super) struct Prefixes<'cx, 'tcx> {
body
:
&
'cx
Body
<
'tcx
>
,
tcx
:
TyCtxt
<
'tcx
>
,
kind
:
PrefixSet
,
next
:
Option
<
(
PlaceRef
<
'cx
,
'tcx
>
)
>
,
next
:
Option
<
PlaceRef
<
'cx
,
'tcx
>
>
,
}
#[derive(Copy,
Clone,
PartialEq,
Eq,
Debug)]
...
...
src/libstd/collections/hash/map.rs
浏览文件 @
08ca2360
...
...
@@ -1818,7 +1818,7 @@ impl<'a, K, V> Iterator for Keys<'a, K, V> {
type
Item
=
&
'a
K
;
#[inline]
fn
next
(
&
mut
self
)
->
Option
<
(
&
'a
K
)
>
{
fn
next
(
&
mut
self
)
->
Option
<
&
'a
K
>
{
self
.inner
.next
()
.map
(|(
k
,
_
)|
k
)
}
#[inline]
...
...
@@ -1841,7 +1841,7 @@ impl<'a, K, V> Iterator for Values<'a, K, V> {
type
Item
=
&
'a
V
;
#[inline]
fn
next
(
&
mut
self
)
->
Option
<
(
&
'a
V
)
>
{
fn
next
(
&
mut
self
)
->
Option
<
&
'a
V
>
{
self
.inner
.next
()
.map
(|(
_
,
v
)|
v
)
}
#[inline]
...
...
@@ -1864,7 +1864,7 @@ impl<'a, K, V> Iterator for ValuesMut<'a, K, V> {
type
Item
=
&
'a
mut
V
;
#[inline]
fn
next
(
&
mut
self
)
->
Option
<
(
&
'a
mut
V
)
>
{
fn
next
(
&
mut
self
)
->
Option
<
&
'a
mut
V
>
{
self
.inner
.next
()
.map
(|(
_
,
v
)|
v
)
}
#[inline]
...
...
src/test/ui/alignment-gep-tup-like-1.rs
浏览文件 @
08ca2360
...
...
@@ -28,7 +28,7 @@ fn f<A:Clone + 'static>(a: A, b: u16) -> Box<dyn Invokable<A>+'static> {
box
Invoker
{
a
:
a
,
b
:
b
,
}
as
(
Box
<
dyn
Invokable
<
A
>+
'static
>
)
}
as
Box
<
dyn
Invokable
<
A
>+
'static
>
}
pub
fn
main
()
{
...
...
src/test/ui/as-precedence.rs
浏览文件 @
08ca2360
// run-pass
#[allow(unused_parens)]
fn
main
()
{
assert_eq!
(
3
as
usize
*
3
,
9
);
assert_eq!
(
3
as
(
usize
)
*
3
,
9
);
...
...
src/test/ui/close-over-big-then-small-data.rs
浏览文件 @
08ca2360
...
...
@@ -30,7 +30,7 @@ fn f<A:Clone + 'static>(a: A, b: u16) -> Box<dyn Invokable<A>+'static> {
box
Invoker
{
a
:
a
,
b
:
b
,
}
as
(
Box
<
dyn
Invokable
<
A
>+
'static
>
)
}
as
Box
<
dyn
Invokable
<
A
>+
'static
>
}
pub
fn
main
()
{
...
...
src/test/ui/functions-closures/closure-to-fn-coercion.rs
浏览文件 @
08ca2360
...
...
@@ -10,7 +10,7 @@
|
v
:
&
mut
u32
|
*
v
+=
3
,
|
v
:
&
mut
u32
|
*
v
+=
4
,
];
fn
func_specific
()
->
(
fn
()
->
u32
)
{
fn
func_specific
()
->
fn
()
->
u32
{
||
return
42
}
...
...
src/test/ui/lint/lint-unnecessary-parens.rs
浏览文件 @
08ca2360
...
...
@@ -13,6 +13,18 @@ fn bar(y: bool) -> X {
return
(
X
{
y
});
//~ ERROR unnecessary parentheses around `return` value
}
fn
unused_parens_around_return_type
()
->
(
u32
)
{
//~ ERROR unnecessary parentheses around type
panic!
()
}
trait
Trait
{
fn
test
(
&
self
);
}
fn
passes_unused_parens_lint
()
->
&
'static
(
dyn
Trait
)
{
panic!
()
}
fn
main
()
{
foo
();
bar
((
true
));
//~ ERROR unnecessary parentheses around function argument
...
...
src/test/ui/lint/lint-unnecessary-parens.stderr
浏览文件 @
08ca2360
...
...
@@ -16,26 +16,32 @@ error: unnecessary parentheses around `return` value
LL | return (X { y });
| ^^^^^^^^^ help: remove these parentheses
error: unnecessary parentheses around type
--> $DIR/lint-unnecessary-parens.rs:16:42
|
LL | fn unused_parens_around_return_type() -> (u32) {
| ^^^^^ help: remove these parentheses
error: unnecessary parentheses around function argument
--> $DIR/lint-unnecessary-parens.rs:
18
:9
--> $DIR/lint-unnecessary-parens.rs:
30
:9
|
LL | bar((true));
| ^^^^^^ help: remove these parentheses
error: unnecessary parentheses around `if` condition
--> $DIR/lint-unnecessary-parens.rs:
20
:8
--> $DIR/lint-unnecessary-parens.rs:
32
:8
|
LL | if (true) {}
| ^^^^^^ help: remove these parentheses
error: unnecessary parentheses around `while` condition
--> $DIR/lint-unnecessary-parens.rs:
21
:11
--> $DIR/lint-unnecessary-parens.rs:
33
:11
|
LL | while (true) {}
| ^^^^^^ help: remove these parentheses
warning: denote infinite loops with `loop { ... }`
--> $DIR/lint-unnecessary-parens.rs:
21
:5
--> $DIR/lint-unnecessary-parens.rs:
33
:5
|
LL | while (true) {}
| ^^^^^^^^^^^^ help: use `loop`
...
...
@@ -43,46 +49,46 @@ LL | while (true) {}
= note: `#[warn(while_true)]` on by default
error: unnecessary parentheses around `match` head expression
--> $DIR/lint-unnecessary-parens.rs:
23
:11
--> $DIR/lint-unnecessary-parens.rs:
35
:11
|
LL | match (true) {
| ^^^^^^ help: remove these parentheses
error: unnecessary parentheses around `let` head expression
--> $DIR/lint-unnecessary-parens.rs:
26
:16
--> $DIR/lint-unnecessary-parens.rs:
38
:16
|
LL | if let 1 = (1) {}
| ^^^ help: remove these parentheses
error: unnecessary parentheses around `let` head expression
--> $DIR/lint-unnecessary-parens.rs:
27
:19
--> $DIR/lint-unnecessary-parens.rs:
39
:19
|
LL | while let 1 = (2) {}
| ^^^ help: remove these parentheses
error: unnecessary parentheses around method argument
--> $DIR/lint-unnecessary-parens.rs:
41
:24
--> $DIR/lint-unnecessary-parens.rs:
53
:24
|
LL | X { y: false }.foo((true));
| ^^^^^^ help: remove these parentheses
error: unnecessary parentheses around assigned value
--> $DIR/lint-unnecessary-parens.rs:
43
:18
--> $DIR/lint-unnecessary-parens.rs:
55
:18
|
LL | let mut _a = (0);
| ^^^ help: remove these parentheses
error: unnecessary parentheses around assigned value
--> $DIR/lint-unnecessary-parens.rs:
44
:10
--> $DIR/lint-unnecessary-parens.rs:
56
:10
|
LL | _a = (0);
| ^^^ help: remove these parentheses
error: unnecessary parentheses around assigned value
--> $DIR/lint-unnecessary-parens.rs:
45
:11
--> $DIR/lint-unnecessary-parens.rs:
57
:11
|
LL | _a += (1);
| ^^^ help: remove these parentheses
error: aborting due to 1
2
previous errors
error: aborting due to 1
3
previous errors
src/test/ui/single-use-lifetime/zero-uses-in-fn.fixed
浏览文件 @
08ca2360
...
...
@@ -15,7 +15,7 @@ fn october<'b, T>(s: &'b T) -> &'b T {
s
}
fn november<'a>(s: &'a str) ->
(&'a str)
{
fn november<'a>(s: &'a str) ->
&'a str
{
//~^ ERROR lifetime parameter `'b` never used
//~| HELP elide the unused lifetime
s
...
...
src/test/ui/single-use-lifetime/zero-uses-in-fn.rs
浏览文件 @
08ca2360
...
...
@@ -15,7 +15,7 @@ fn october<'a, 'b, T>(s: &'b T) -> &'b T {
s
}
fn
november
<
'a
,
'b
>
(
s
:
&
'a
str
)
->
(
&
'a
str
)
{
fn
november
<
'a
,
'b
>
(
s
:
&
'a
str
)
->
&
'a
str
{
//~^ ERROR lifetime parameter `'b` never used
//~| HELP elide the unused lifetime
s
...
...
src/test/ui/single-use-lifetime/zero-uses-in-fn.stderr
浏览文件 @
08ca2360
...
...
@@ -21,7 +21,7 @@ LL | fn october<'a, 'b, T>(s: &'b T) -> &'b T {
error: lifetime parameter `'b` never used
--> $DIR/zero-uses-in-fn.rs:18:17
|
LL | fn november<'a, 'b>(s: &'a str) ->
(&'a str)
{
LL | fn november<'a, 'b>(s: &'a str) ->
&'a str
{
| --^^
| |
| help: elide the unused lifetime
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录