Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
28d0312b
R
Rust
项目概览
int
/
Rust
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
28d0312b
编写于
10月 11, 2022
作者:
K
Kevin Per
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement assertions and fixes to not emit empty spans without suggestions
上级
4b8f4319
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
81 addition
and
117 deletion
+81
-117
compiler/rustc_errors/src/diagnostic.rs
compiler/rustc_errors/src/diagnostic.rs
+25
-0
compiler/rustc_expand/src/base.rs
compiler/rustc_expand/src/base.rs
+3
-2
compiler/rustc_hir_analysis/src/astconv/mod.rs
compiler/rustc_hir_analysis/src/astconv/mod.rs
+14
-11
compiler/rustc_parse/src/parser/diagnostics.rs
compiler/rustc_parse/src/parser/diagnostics.rs
+9
-1
src/tools/clippy/clippy_lints/src/manual_assert.rs
src/tools/clippy/clippy_lints/src/manual_assert.rs
+7
-5
src/tools/clippy/clippy_lints/src/needless_late_init.rs
src/tools/clippy/clippy_lints/src/needless_late_init.rs
+7
-4
src/tools/clippy/tests/ui/manual_assert.edition2018.stderr
src/tools/clippy/tests/ui/manual_assert.edition2018.stderr
+8
-47
src/tools/clippy/tests/ui/manual_assert.edition2021.stderr
src/tools/clippy/tests/ui/manual_assert.edition2021.stderr
+8
-47
未找到文件。
compiler/rustc_errors/src/diagnostic.rs
浏览文件 @
28d0312b
...
...
@@ -567,6 +567,11 @@ pub fn multipart_suggestion_with_style(
style
:
SuggestionStyle
,
)
->
&
mut
Self
{
assert
!
(
!
suggestion
.is_empty
());
debug_assert!
(
!
(
suggestion
.iter
()
.any
(|(
sp
,
text
)|
sp
.is_empty
()
&&
text
.is_empty
())),
"Span must not be empty and have no suggestion"
);
self
.push_suggestion
(
CodeSuggestion
{
substitutions
:
vec!
[
Substitution
{
parts
:
suggestion
...
...
@@ -644,6 +649,10 @@ pub fn span_suggestion_with_style(
applicability
:
Applicability
,
style
:
SuggestionStyle
,
)
->
&
mut
Self
{
debug_assert!
(
!
(
sp
.is_empty
()
&&
suggestion
.to_string
()
.is_empty
()),
"Span must not be empty and have no suggestion"
);
self
.push_suggestion
(
CodeSuggestion
{
substitutions
:
vec!
[
Substitution
{
parts
:
vec!
[
SubstitutionPart
{
snippet
:
suggestion
.to_string
(),
span
:
sp
}],
...
...
@@ -684,6 +693,12 @@ pub fn span_suggestions(
)
->
&
mut
Self
{
let
mut
suggestions
:
Vec
<
_
>
=
suggestions
.collect
();
suggestions
.sort
();
debug_assert!
(
!
(
sp
.is_empty
()
&&
suggestions
.iter
()
.any
(|
suggestion
|
suggestion
.is_empty
())),
"Span must not be empty and have no suggestion"
);
let
substitutions
=
suggestions
.into_iter
()
.map
(|
snippet
|
Substitution
{
parts
:
vec!
[
SubstitutionPart
{
snippet
,
span
:
sp
}]
})
...
...
@@ -705,8 +720,18 @@ pub fn multipart_suggestions(
suggestions
:
impl
Iterator
<
Item
=
Vec
<
(
Span
,
String
)
>>
,
applicability
:
Applicability
,
)
->
&
mut
Self
{
let
suggestions
:
Vec
<
_
>
=
suggestions
.collect
();
debug_assert!
(
!
(
suggestions
.iter
()
.flat_map
(|
suggs
|
suggs
)
.any
(|(
sp
,
suggestion
)|
sp
.is_empty
()
&&
suggestion
.is_empty
())),
"Span must not be empty and have no suggestion"
);
self
.push_suggestion
(
CodeSuggestion
{
substitutions
:
suggestions
.into_iter
()
.map
(|
sugg
|
Substitution
{
parts
:
sugg
.into_iter
()
...
...
compiler/rustc_expand/src/base.rs
浏览文件 @
28d0312b
...
...
@@ -22,7 +22,7 @@
use
rustc_span
::
hygiene
::{
AstPass
,
ExpnData
,
ExpnKind
,
LocalExpnId
};
use
rustc_span
::
source_map
::
SourceMap
;
use
rustc_span
::
symbol
::{
kw
,
sym
,
Ident
,
Symbol
};
use
rustc_span
::{
FileName
,
Span
,
DUMMY_SP
};
use
rustc_span
::{
BytePos
,
FileName
,
Span
,
DUMMY_SP
};
use
smallvec
::{
smallvec
,
SmallVec
};
use
std
::
default
::
Default
;
...
...
@@ -1228,8 +1228,9 @@ pub fn expr_to_spanned_string<'a>(
ast
::
LitKind
::
Str
(
s
,
style
)
=>
return
Ok
((
s
,
style
,
expr
.span
)),
ast
::
LitKind
::
ByteStr
(
_
)
=>
{
let
mut
err
=
cx
.struct_span_err
(
l
.span
,
err_msg
);
let
span
=
expr
.span
.shrink_to_lo
();
err
.span_suggestion
(
expr
.span
.shrink_to_lo
(
),
span
.with_hi
(
span
.lo
()
+
BytePos
(
1
)
),
"consider removing the leading `b`"
,
""
,
Applicability
::
MaybeIncorrect
,
...
...
compiler/rustc_hir_analysis/src/astconv/mod.rs
浏览文件 @
28d0312b
...
...
@@ -3051,24 +3051,27 @@ fn maybe_lint_bare_trait(&self, self_ty: &hir::Ty<'_>, in_path: bool) {
.map_or
(
false
,
|
s
|
s
.trim_end
()
.ends_with
(
'<'
));
let
is_global
=
poly_trait_ref
.trait_ref.path
.is_global
();
let
sugg
=
Vec
::
from_iter
([
(
self_ty
.span
.shrink_to_lo
(),
format!
(
"{}dyn {}"
,
if
needs_bracket
{
"<"
}
else
{
""
},
if
is_global
{
"("
}
else
{
""
},
),
let
mut
sugg
=
Vec
::
from_iter
([(
self_ty
.span
.shrink_to_lo
(),
format!
(
"{}dyn {}"
,
if
needs_bracket
{
"<"
}
else
{
""
},
if
is_global
{
"("
}
else
{
""
},
),
(
)]);
if
is_global
||
needs_bracket
{
sugg
.push
((
self_ty
.span
.shrink_to_hi
(),
format!
(
"{}{}"
,
if
is_global
{
")"
}
else
{
""
},
if
needs_bracket
{
">"
}
else
{
""
},
),
),
]);
));
}
if
self_ty
.span
.edition
()
>=
Edition
::
Edition2021
{
let
msg
=
"trait objects must include the `dyn` keyword"
;
let
label
=
"add `dyn` keyword before this trait"
;
...
...
compiler/rustc_parse/src/parser/diagnostics.rs
浏览文件 @
28d0312b
...
...
@@ -1374,9 +1374,17 @@ fn inc_dec_standalone_suggest(
kind
:
IncDecRecovery
,
(
pre_span
,
post_span
):
(
Span
,
Span
),
)
->
MultiSugg
{
let
mut
patches
=
Vec
::
new
();
if
!
pre_span
.is_empty
()
{
patches
.push
((
pre_span
,
String
::
new
()));
}
patches
.push
((
post_span
,
format!
(
" {}= 1"
,
kind
.op
.chr
())));
MultiSugg
{
msg
:
format!
(
"use `{}= 1` instead"
,
kind
.op
.chr
()),
patches
:
vec!
[(
pre_span
,
String
::
new
()),
(
post_span
,
format!
(
" {}= 1"
,
kind
.op
.chr
()))]
,
patches
,
applicability
:
Applicability
::
MachineApplicable
,
}
}
...
...
src/tools/clippy/clippy_lints/src/manual_assert.rs
浏览文件 @
28d0312b
...
...
@@ -69,11 +69,13 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'tcx>) {
"only a `panic!` in `if`-then statement"
,
|
diag
|
{
// comments can be noisy, do not show them to the user
diag
.tool_only_span_suggestion
(
expr
.span
.shrink_to_lo
(),
"add comments back"
,
comments
,
applicability
);
if
!
comments
.is_empty
()
{
diag
.tool_only_span_suggestion
(
expr
.span
.shrink_to_lo
(),
"add comments back"
,
comments
,
applicability
);
}
diag
.span_suggestion
(
expr
.span
,
"try instead"
,
...
...
src/tools/clippy/clippy_lints/src/needless_late_init.rs
浏览文件 @
28d0312b
...
...
@@ -180,10 +180,13 @@ fn assignment_suggestions<'tcx>(
let
suggestions
=
assignments
.iter
()
.flat_map
(|
assignment
|
{
[
assignment
.span
.until
(
assignment
.rhs_span
),
assignment
.rhs_span
.shrink_to_hi
()
.with_hi
(
assignment
.span
.hi
()),
]
let
mut
spans
=
vec!
[
assignment
.span
.until
(
assignment
.rhs_span
)];
if
assignment
.rhs_span
.hi
()
!=
assignment
.span
.hi
()
{
spans
.push
(
assignment
.rhs_span
.shrink_to_hi
()
.with_hi
(
assignment
.span
.hi
()));
}
spans
})
.map
(|
span
|
(
span
,
String
::
new
()))
.collect
::
<
Vec
<
(
Span
,
String
)
>>
();
...
...
src/tools/clippy/tests/ui/manual_assert.edition2018.stderr
浏览文件 @
28d0312b
...
...
@@ -4,13 +4,9 @@ error: only a `panic!` in `if`-then statement
LL | / if !a.is_empty() {
LL | | panic!("qaqaq{:?}", a);
LL | | }
| |_____^
| |_____^
help: try instead: `assert!(a.is_empty(), "qaqaq{:?}", a);`
|
= note: `-D clippy::manual-assert` implied by `-D warnings`
help: try instead
|
LL | assert!(a.is_empty(), "qaqaq{:?}", a);
|
error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:34:5
...
...
@@ -18,12 +14,7 @@ error: only a `panic!` in `if`-then statement
LL | / if !a.is_empty() {
LL | | panic!("qwqwq");
LL | | }
| |_____^
|
help: try instead
|
LL | assert!(a.is_empty(), "qwqwq");
|
| |_____^ help: try instead: `assert!(a.is_empty(), "qwqwq");`
error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:51:5
...
...
@@ -31,12 +22,7 @@ error: only a `panic!` in `if`-then statement
LL | / if b.is_empty() {
LL | | panic!("panic1");
LL | | }
| |_____^
|
help: try instead
|
LL | assert!(!b.is_empty(), "panic1");
|
| |_____^ help: try instead: `assert!(!b.is_empty(), "panic1");`
error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:54:5
...
...
@@ -44,12 +30,7 @@ error: only a `panic!` in `if`-then statement
LL | / if b.is_empty() && a.is_empty() {
LL | | panic!("panic2");
LL | | }
| |_____^
|
help: try instead
|
LL | assert!(!(b.is_empty() && a.is_empty()), "panic2");
|
| |_____^ help: try instead: `assert!(!(b.is_empty() && a.is_empty()), "panic2");`
error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:57:5
...
...
@@ -57,12 +38,7 @@ error: only a `panic!` in `if`-then statement
LL | / if a.is_empty() && !b.is_empty() {
LL | | panic!("panic3");
LL | | }
| |_____^
|
help: try instead
|
LL | assert!(!(a.is_empty() && !b.is_empty()), "panic3");
|
| |_____^ help: try instead: `assert!(!(a.is_empty() && !b.is_empty()), "panic3");`
error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:60:5
...
...
@@ -70,12 +46,7 @@ error: only a `panic!` in `if`-then statement
LL | / if b.is_empty() || a.is_empty() {
LL | | panic!("panic4");
LL | | }
| |_____^
|
help: try instead
|
LL | assert!(!(b.is_empty() || a.is_empty()), "panic4");
|
| |_____^ help: try instead: `assert!(!(b.is_empty() || a.is_empty()), "panic4");`
error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:63:5
...
...
@@ -83,12 +54,7 @@ error: only a `panic!` in `if`-then statement
LL | / if a.is_empty() || !b.is_empty() {
LL | | panic!("panic5");
LL | | }
| |_____^
|
help: try instead
|
LL | assert!(!(a.is_empty() || !b.is_empty()), "panic5");
|
| |_____^ help: try instead: `assert!(!(a.is_empty() || !b.is_empty()), "panic5");`
error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:66:5
...
...
@@ -96,12 +62,7 @@ error: only a `panic!` in `if`-then statement
LL | / if a.is_empty() {
LL | | panic!("with expansion {}", one!())
LL | | }
| |_____^
|
help: try instead
|
LL | assert!(!a.is_empty(), "with expansion {}", one!());
|
| |_____^ help: try instead: `assert!(!a.is_empty(), "with expansion {}", one!());`
error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:73:5
...
...
src/tools/clippy/tests/ui/manual_assert.edition2021.stderr
浏览文件 @
28d0312b
...
...
@@ -4,13 +4,9 @@ error: only a `panic!` in `if`-then statement
LL | / if !a.is_empty() {
LL | | panic!("qaqaq{:?}", a);
LL | | }
| |_____^
| |_____^
help: try instead: `assert!(a.is_empty(), "qaqaq{:?}", a);`
|
= note: `-D clippy::manual-assert` implied by `-D warnings`
help: try instead
|
LL | assert!(a.is_empty(), "qaqaq{:?}", a);
|
error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:34:5
...
...
@@ -18,12 +14,7 @@ error: only a `panic!` in `if`-then statement
LL | / if !a.is_empty() {
LL | | panic!("qwqwq");
LL | | }
| |_____^
|
help: try instead
|
LL | assert!(a.is_empty(), "qwqwq");
|
| |_____^ help: try instead: `assert!(a.is_empty(), "qwqwq");`
error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:51:5
...
...
@@ -31,12 +22,7 @@ error: only a `panic!` in `if`-then statement
LL | / if b.is_empty() {
LL | | panic!("panic1");
LL | | }
| |_____^
|
help: try instead
|
LL | assert!(!b.is_empty(), "panic1");
|
| |_____^ help: try instead: `assert!(!b.is_empty(), "panic1");`
error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:54:5
...
...
@@ -44,12 +30,7 @@ error: only a `panic!` in `if`-then statement
LL | / if b.is_empty() && a.is_empty() {
LL | | panic!("panic2");
LL | | }
| |_____^
|
help: try instead
|
LL | assert!(!(b.is_empty() && a.is_empty()), "panic2");
|
| |_____^ help: try instead: `assert!(!(b.is_empty() && a.is_empty()), "panic2");`
error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:57:5
...
...
@@ -57,12 +38,7 @@ error: only a `panic!` in `if`-then statement
LL | / if a.is_empty() && !b.is_empty() {
LL | | panic!("panic3");
LL | | }
| |_____^
|
help: try instead
|
LL | assert!(!(a.is_empty() && !b.is_empty()), "panic3");
|
| |_____^ help: try instead: `assert!(!(a.is_empty() && !b.is_empty()), "panic3");`
error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:60:5
...
...
@@ -70,12 +46,7 @@ error: only a `panic!` in `if`-then statement
LL | / if b.is_empty() || a.is_empty() {
LL | | panic!("panic4");
LL | | }
| |_____^
|
help: try instead
|
LL | assert!(!(b.is_empty() || a.is_empty()), "panic4");
|
| |_____^ help: try instead: `assert!(!(b.is_empty() || a.is_empty()), "panic4");`
error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:63:5
...
...
@@ -83,12 +54,7 @@ error: only a `panic!` in `if`-then statement
LL | / if a.is_empty() || !b.is_empty() {
LL | | panic!("panic5");
LL | | }
| |_____^
|
help: try instead
|
LL | assert!(!(a.is_empty() || !b.is_empty()), "panic5");
|
| |_____^ help: try instead: `assert!(!(a.is_empty() || !b.is_empty()), "panic5");`
error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:66:5
...
...
@@ -96,12 +62,7 @@ error: only a `panic!` in `if`-then statement
LL | / if a.is_empty() {
LL | | panic!("with expansion {}", one!())
LL | | }
| |_____^
|
help: try instead
|
LL | assert!(!a.is_empty(), "with expansion {}", one!());
|
| |_____^ help: try instead: `assert!(!a.is_empty(), "with expansion {}", one!());`
error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:73:5
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录