5 - Make more use of let_chains
This commit is contained in:
parent
48132caac2
commit
d956c8b816
5 changed files with 63 additions and 68 deletions
|
@ -1113,8 +1113,7 @@ impl CheckAttrVisitor<'_> {
|
|||
/// 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() {
|
||||
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 \
|
||||
|
@ -1129,7 +1128,6 @@ impl CheckAttrVisitor<'_> {
|
|||
.emit();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// For now, its always valid
|
||||
true
|
||||
|
|
|
@ -683,9 +683,10 @@ impl<'tcx> DeadVisitor<'tcx> {
|
|||
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) {
|
||||
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)))
|
||||
|
@ -710,8 +711,6 @@ impl<'tcx> DeadVisitor<'tcx> {
|
|||
.collect::<Vec<_>>();
|
||||
err.span_note(multispan, &msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
err.emit();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -332,13 +332,12 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'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) {
|
||||
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]
|
||||
if self.tcx.has_attr(def_id, sym::naked) {
|
||||
|
|
|
@ -94,8 +94,7 @@ impl<'tcx> Visitor<'tcx> for ReachableContext<'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 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 {
|
||||
|
@ -115,7 +114,6 @@ impl<'tcx> Visitor<'tcx> for ReachableContext<'tcx> {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
intravisit::walk_expr(self, expr)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue