update clippy
This commit is contained in:
parent
670bc53c03
commit
107ee40674
11 changed files with 27 additions and 45 deletions
|
|
@ -1,6 +1,7 @@
|
|||
use rustc_ast::{ast, attr};
|
||||
use rustc_ast::ast;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_session::Session;
|
||||
use rustc_ast::attr;
|
||||
use rustc_span::sym;
|
||||
use std::str::FromStr;
|
||||
|
||||
|
|
@ -158,7 +159,3 @@ pub fn is_doc_hidden(attrs: &[ast::Attribute]) -> bool {
|
|||
.any(|l| attr::list_contains_name(&l, sym::hidden))
|
||||
}
|
||||
|
||||
/// Return true if the attributes contain `#[unstable]`
|
||||
pub fn is_unstable(attrs: &[ast::Attribute]) -> bool {
|
||||
attrs.iter().any(|attr| attr.has_name(sym::unstable))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ use std::lazy::SyncOnceCell;
|
|||
use std::sync::{Mutex, MutexGuard};
|
||||
|
||||
use if_chain::if_chain;
|
||||
use rustc_ast::ast::{self, Attribute, LitKind};
|
||||
use rustc_ast::ast::{self, LitKind};
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::unhash::UnhashMap;
|
||||
use rustc_hir as hir;
|
||||
|
|
@ -1472,12 +1472,6 @@ pub fn recurse_or_patterns<'tcx, F: FnMut(&'tcx Pat<'tcx>)>(pat: &'tcx Pat<'tcx>
|
|||
}
|
||||
}
|
||||
|
||||
/// Checks for the `#[automatically_derived]` attribute all `#[derive]`d
|
||||
/// implementations have.
|
||||
pub fn is_automatically_derived(attrs: &[ast::Attribute]) -> bool {
|
||||
has_attr(attrs, sym::automatically_derived)
|
||||
}
|
||||
|
||||
pub fn is_self(slf: &Param<'_>) -> bool {
|
||||
if let PatKind::Binding(.., name, _) = slf.pat.kind {
|
||||
name.name == kw::SelfLower
|
||||
|
|
@ -1724,11 +1718,6 @@ pub fn get_async_fn_body<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'_>) -> Option<&'t
|
|||
None
|
||||
}
|
||||
|
||||
// Finds the `#[must_use]` attribute, if any
|
||||
pub fn must_use_attr(attrs: &[Attribute]) -> Option<&Attribute> {
|
||||
attrs.iter().find(|a| a.has_name(sym::must_use))
|
||||
}
|
||||
|
||||
// check if expr is calling method or function with #[must_use] attribute
|
||||
pub fn is_must_use_func_call(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||
let did = match expr.kind {
|
||||
|
|
@ -1745,7 +1734,7 @@ pub fn is_must_use_func_call(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
|||
_ => None,
|
||||
};
|
||||
|
||||
did.map_or(false, |did| must_use_attr(cx.tcx.get_attrs(did)).is_some())
|
||||
did.map_or(false, |did| cx.tcx.has_attr(did, sym::must_use))
|
||||
}
|
||||
|
||||
/// Checks if an expression represents the identity function
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ use rustc_trait_selection::infer::InferCtxtExt;
|
|||
use rustc_trait_selection::traits::query::normalize::AtExt;
|
||||
use std::iter;
|
||||
|
||||
use crate::{match_def_path, must_use_attr, path_res, paths};
|
||||
use crate::{match_def_path, path_res, paths};
|
||||
|
||||
// Checks if the given type implements copy.
|
||||
pub fn is_copy<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
|
||||
|
|
@ -178,18 +178,18 @@ pub fn has_drop<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
|
|||
// Returns whether the type has #[must_use] attribute
|
||||
pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
|
||||
match ty.kind() {
|
||||
ty::Adt(adt, _) => must_use_attr(cx.tcx.get_attrs(adt.did())).is_some(),
|
||||
ty::Foreign(ref did) => must_use_attr(cx.tcx.get_attrs(*did)).is_some(),
|
||||
ty::Adt(adt, _) => cx.tcx.has_attr(adt.did(), sym::must_use),
|
||||
ty::Foreign(did) => cx.tcx.has_attr(*did, sym::must_use),
|
||||
ty::Slice(ty) | ty::Array(ty, _) | ty::RawPtr(ty::TypeAndMut { ty, .. }) | ty::Ref(_, ty, _) => {
|
||||
// for the Array case we don't need to care for the len == 0 case
|
||||
// because we don't want to lint functions returning empty arrays
|
||||
is_must_use_ty(cx, *ty)
|
||||
},
|
||||
ty::Tuple(substs) => substs.iter().any(|ty| is_must_use_ty(cx, ty)),
|
||||
ty::Opaque(ref def_id, _) => {
|
||||
ty::Opaque(def_id, _) => {
|
||||
for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) {
|
||||
if let ty::PredicateKind::Trait(trait_predicate) = predicate.kind().skip_binder() {
|
||||
if must_use_attr(cx.tcx.get_attrs(trait_predicate.trait_ref.def_id)).is_some() {
|
||||
if cx.tcx.has_attr(trait_predicate.trait_ref.def_id, sym::must_use) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -199,7 +199,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
|
|||
ty::Dynamic(binder, _) => {
|
||||
for predicate in binder.iter() {
|
||||
if let ty::ExistentialPredicate::Trait(ref trait_ref) = predicate.skip_binder() {
|
||||
if must_use_attr(cx.tcx.get_attrs(trait_ref.def_id)).is_some() {
|
||||
if cx.tcx.has_attr(trait_ref.def_id, sym::must_use) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue