Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
bf6954b2
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,发现更多精彩内容 >>
未验证
提交
bf6954b2
编写于
3月 01, 2022
作者:
D
Dylan DPC
提交者:
GitHub
3月 01, 2022
浏览文件
操作
浏览文件
下载
差异文件
Rollup merge of #94448 - c410-f3r:yet-more-let-chains, r=estebank
5 - Make more use of `let_chains` Continuation of #94376. cc #53667
上级
5bd119da
d956c8b8
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
63 addition
and
68 deletion
+63
-68
compiler/rustc_passes/src/check_attr.rs
compiler/rustc_passes/src/check_attr.rs
+14
-16
compiler/rustc_passes/src/dead.rs
compiler/rustc_passes/src/dead.rs
+27
-28
compiler/rustc_passes/src/lib.rs
compiler/rustc_passes/src/lib.rs
+2
-1
compiler/rustc_passes/src/liveness.rs
compiler/rustc_passes/src/liveness.rs
+5
-6
compiler/rustc_passes/src/reachable.rs
compiler/rustc_passes/src/reachable.rs
+15
-17
未找到文件。
compiler/rustc_passes/src/check_attr.rs
浏览文件 @
bf6954b2
...
...
@@ -1113,22 +1113,20 @@ fn check_pass_by_value(&self, attr: &Attribute, span: Span, target: Target) -> b
/// Warns against some misuses of `#[must_use]`
fn
check_must_use
(
&
self
,
hir_id
:
HirId
,
attr
:
&
Attribute
,
span
:
Span
,
target
:
Target
)
->
bool
{
let
node
=
self
.tcx
.hir
()
.get
(
hir_id
);
if
let
Some
(
fn_node
)
=
node
.fn_kind
()
{
if
let
rustc_hir
::
IsAsync
::
Async
=
fn_node
.asyncness
()
{
self
.tcx
.struct_span_lint_hir
(
UNUSED_ATTRIBUTES
,
hir_id
,
attr
.span
,
|
lint
|
{
lint
.build
(
"`must_use` attribute on `async` functions
\
applies to the anonymous `Future` returned by the
\
function, not the value within"
,
)
.span_label
(
span
,
"this attribute does nothing, the `Future`s
\
returned by async functions are already `must_use`"
,
)
.emit
();
});
}
if
let
Some
(
kind
)
=
node
.fn_kind
()
&&
let
rustc_hir
::
IsAsync
::
Async
=
kind
.asyncness
()
{
self
.tcx
.struct_span_lint_hir
(
UNUSED_ATTRIBUTES
,
hir_id
,
attr
.span
,
|
lint
|
{
lint
.build
(
"`must_use` attribute on `async` functions
\
applies to the anonymous `Future` returned by the
\
function, not the value within"
,
)
.span_label
(
span
,
"this attribute does nothing, the `Future`s
\
returned by async functions are already `must_use`"
,
)
.emit
();
});
}
if
!
matches!
(
...
...
compiler/rustc_passes/src/dead.rs
浏览文件 @
bf6954b2
...
...
@@ -683,34 +683,33 @@ fn warn_dead_code(
let
descr
=
self
.tcx
.def_kind
(
def_id
)
.descr
(
def_id
.to_def_id
());
let
mut
err
=
lint
.build
(
&
format!
(
"{} is never {}: `{}`"
,
descr
,
participle
,
name
));
let
hir
=
self
.tcx
.hir
();
if
let
Some
(
encl_scope
)
=
hir
.get_enclosing_scope
(
id
)
{
if
let
Some
(
encl_def_id
)
=
hir
.opt_local_def_id
(
encl_scope
)
{
if
let
Some
(
ign_traits
)
=
self
.ignored_derived_traits
.get
(
&
encl_def_id
)
{
let
traits_str
=
ign_traits
.iter
()
.map
(|(
trait_id
,
_
)|
format!
(
"`{}`"
,
self
.tcx
.item_name
(
*
trait_id
)))
.collect
::
<
Vec
<
_
>>
()
.join
(
" and "
);
let
plural_s
=
pluralize!
(
ign_traits
.len
());
let
article
=
if
ign_traits
.len
()
>
1
{
""
}
else
{
"a "
};
let
is_are
=
if
ign_traits
.len
()
>
1
{
"these are"
}
else
{
"this is"
};
let
msg
=
format!
(
"`{}` has {}derived impl{} for the trait{} {}, but {}
\
intentionally ignored during dead code analysis"
,
self
.tcx
.item_name
(
encl_def_id
.to_def_id
()),
article
,
plural_s
,
plural_s
,
traits_str
,
is_are
);
let
multispan
=
ign_traits
.iter
()
.map
(|(
_
,
impl_id
)|
self
.tcx
.def_span
(
*
impl_id
))
.collect
::
<
Vec
<
_
>>
();
err
.span_note
(
multispan
,
&
msg
);
}
}
if
let
Some
(
encl_scope
)
=
hir
.get_enclosing_scope
(
id
)
&&
let
Some
(
encl_def_id
)
=
hir
.opt_local_def_id
(
encl_scope
)
&&
let
Some
(
ign_traits
)
=
self
.ignored_derived_traits
.get
(
&
encl_def_id
)
{
let
traits_str
=
ign_traits
.iter
()
.map
(|(
trait_id
,
_
)|
format!
(
"`{}`"
,
self
.tcx
.item_name
(
*
trait_id
)))
.collect
::
<
Vec
<
_
>>
()
.join
(
" and "
);
let
plural_s
=
pluralize!
(
ign_traits
.len
());
let
article
=
if
ign_traits
.len
()
>
1
{
""
}
else
{
"a "
};
let
is_are
=
if
ign_traits
.len
()
>
1
{
"these are"
}
else
{
"this is"
};
let
msg
=
format!
(
"`{}` has {}derived impl{} for the trait{} {}, but {}
\
intentionally ignored during dead code analysis"
,
self
.tcx
.item_name
(
encl_def_id
.to_def_id
()),
article
,
plural_s
,
plural_s
,
traits_str
,
is_are
);
let
multispan
=
ign_traits
.iter
()
.map
(|(
_
,
impl_id
)|
self
.tcx
.def_span
(
*
impl_id
))
.collect
::
<
Vec
<
_
>>
();
err
.span_note
(
multispan
,
&
msg
);
}
err
.emit
();
});
...
...
compiler/rustc_passes/src/lib.rs
浏览文件 @
bf6954b2
...
...
@@ -4,16 +4,17 @@
//!
//! This API is completely unstable and subject to change.
#![allow(rustc::potential_query_instability)]
#![doc(html_root_url
=
"https://doc.rust-lang.org/nightly/nightly-rustc/"
)]
#![feature(crate_visibility_modifier)]
#![feature(iter_intersperse)]
#![feature(let_else)]
#![feature(let_chains)]
#![feature(map_try_insert)]
#![feature(min_specialization)]
#![feature(nll)]
#![feature(try_blocks)]
#![recursion_limit
=
"256"
]
#![allow(rustc::potential_query_instability)]
#[macro_use]
extern
crate
rustc_middle
;
...
...
compiler/rustc_passes/src/liveness.rs
浏览文件 @
bf6954b2
...
...
@@ -332,12 +332,11 @@ fn visit_body(&mut self, body: &'tcx hir::Body<'tcx>) {
let
def_id
=
local_def_id
.to_def_id
();
// Don't run unused pass for #[derive()]
if
let
Some
(
parent
)
=
self
.tcx
.parent
(
def_id
)
{
if
let
DefKind
::
Impl
=
self
.tcx
.def_kind
(
parent
.expect_local
())
{
if
self
.tcx
.has_attr
(
parent
,
sym
::
automatically_derived
)
{
return
;
}
}
if
let
Some
(
parent
)
=
self
.tcx
.parent
(
def_id
)
&&
let
DefKind
::
Impl
=
self
.tcx
.def_kind
(
parent
.expect_local
())
&&
self
.tcx
.has_attr
(
parent
,
sym
::
automatically_derived
)
{
return
;
}
// Don't run unused pass for #[naked]
...
...
compiler/rustc_passes/src/reachable.rs
浏览文件 @
bf6954b2
...
...
@@ -94,24 +94,22 @@ fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
_
=>
None
,
};
if
let
Some
(
res
)
=
res
{
if
let
Some
(
def_id
)
=
res
.opt_def_id
()
.and_then
(|
def_id
|
def_id
.as_local
())
{
if
self
.def_id_represents_local_inlined_item
(
def_id
.to_def_id
())
{
self
.worklist
.push
(
def_id
);
}
else
{
match
res
{
// If this path leads to a constant, then we need to
// recurse into the constant to continue finding
// items that are reachable.
Res
::
Def
(
DefKind
::
Const
|
DefKind
::
AssocConst
,
_
)
=>
{
self
.worklist
.push
(
def_id
);
}
if
let
Some
(
res
)
=
res
&&
let
Some
(
def_id
)
=
res
.opt_def_id
()
.and_then
(|
el
|
el
.as_local
())
{
if
self
.def_id_represents_local_inlined_item
(
def_id
.to_def_id
())
{
self
.worklist
.push
(
def_id
);
}
else
{
match
res
{
// If this path leads to a constant, then we need to
// recurse into the constant to continue finding
// items that are reachable.
Res
::
Def
(
DefKind
::
Const
|
DefKind
::
AssocConst
,
_
)
=>
{
self
.worklist
.push
(
def_id
);
}
// If this wasn't a static, then the destination is
// surely reachable.
_
=>
{
self
.reachable_symbols
.insert
(
def_id
);
}
// If this wasn't a static, then the destination is
// surely reachable.
_
=>
{
self
.reachable_symbols
.insert
(
def_id
);
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录