Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
ac25636a
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,发现更多精彩内容 >>
提交
ac25636a
编写于
8月 02, 2023
作者:
Y
yukang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix RedundantLocals clippy caused by async and await
上级
75b9f53e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
22 addition
and
3 deletion
+22
-3
compiler/rustc_middle/src/lint.rs
compiler/rustc_middle/src/lint.rs
+9
-0
src/tools/clippy/clippy_lints/src/redundant_locals.rs
src/tools/clippy/clippy_lints/src/redundant_locals.rs
+13
-3
未找到文件。
compiler/rustc_middle/src/lint.rs
浏览文件 @
ac25636a
...
...
@@ -463,3 +463,12 @@ pub fn in_external_macro(sess: &Session, span: Span) -> bool {
ExpnKind
::
Macro
{
..
}
=>
true
,
// definitely a plugin
}
}
/// Return whether `span` is generated by `async` or `await`.
pub
fn
is_from_async_await
(
span
:
Span
)
->
bool
{
let
expn_data
=
span
.ctxt
()
.outer_expn_data
();
match
expn_data
.kind
{
ExpnKind
::
Desugaring
(
DesugaringKind
::
Async
|
DesugaringKind
::
Await
)
=>
true
,
_
=>
false
,
}
}
src/tools/clippy/clippy_lints/src/redundant_locals.rs
浏览文件 @
ac25636a
...
...
@@ -2,9 +2,11 @@
use
clippy_utils
::
is_from_proc_macro
;
use
clippy_utils
::
ty
::
needs_ordered_drop
;
use
rustc_hir
::
def
::
Res
;
use
rustc_hir
::{
BindingAnnotation
,
ByRef
,
Expr
,
ExprKind
,
HirId
,
Local
,
Node
,
Pat
,
PatKind
,
QPath
};
use
rustc_hir
::{
BindingAnnotation
,
ByRef
,
Expr
,
ExprKind
,
HirId
,
Local
,
Node
,
Pat
,
PatKind
,
QPath
,
};
use
rustc_lint
::{
LateContext
,
LateLintPass
,
LintContext
};
use
rustc_middle
::
lint
::
in_external_macro
;
use
rustc_middle
::
lint
::
{
in_external_macro
,
is_from_async_await
}
;
use
rustc_session
::{
declare_lint_pass
,
declare_tool_lint
};
use
rustc_span
::
symbol
::
Ident
;
...
...
@@ -65,6 +67,9 @@ fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) {
// the local is user-controlled
if
!
in_external_macro
(
cx
.sess
(),
local
.span
);
if
!
is_from_proc_macro
(
cx
,
expr
);
// Async function parameters are lowered into the closure body, so we can't lint them.
// see `lower_maybe_async_body` in `rust_ast_lowering`
if
!
is_from_async_await
(
local
.span
);
then
{
span_lint_and_help
(
cx
,
...
...
@@ -93,7 +98,12 @@ fn find_binding(pat: &Pat<'_>, name: Ident) -> Option<BindingAnnotation> {
}
/// Check if a rebinding of a local affects the code's drop behavior.
fn
affects_drop_behavior
<
'tcx
>
(
cx
:
&
LateContext
<
'tcx
>
,
bind
:
HirId
,
rebind
:
HirId
,
rebind_expr
:
&
Expr
<
'tcx
>
)
->
bool
{
fn
affects_drop_behavior
<
'tcx
>
(
cx
:
&
LateContext
<
'tcx
>
,
bind
:
HirId
,
rebind
:
HirId
,
rebind_expr
:
&
Expr
<
'tcx
>
,
)
->
bool
{
let
hir
=
cx
.tcx
.hir
();
// the rebinding is in a different scope than the original binding
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录