clippy: fold by value

This commit is contained in:
Bastian Kauschke 2020-10-24 02:21:27 +02:00
parent 27a15721c5
commit 3567ea546f
9 changed files with 15 additions and 15 deletions

View File

@ -141,7 +141,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> {
match typ.kind() {
ty::FnDef(..) | ty::FnPtr(_) => {
let sig = typ.fn_sig(self.cx.tcx);
if let ty::Never = self.cx.tcx.erase_late_bound_regions(&sig).output().kind() {
if let ty::Never = self.cx.tcx.erase_late_bound_regions(sig).output().kind() {
self.report_diverging_sub_expr(e);
}
},

View File

@ -1615,7 +1615,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
let method_def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);
let method_sig = cx.tcx.fn_sig(method_def_id);
let method_sig = cx.tcx.erase_late_bound_regions(&method_sig);
let method_sig = cx.tcx.erase_late_bound_regions(method_sig);
let first_arg_ty = &method_sig.inputs().iter().next();
@ -2681,7 +2681,7 @@ fn lint_map_flatten<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, map
ty::Closure(_, substs) => substs.as_closure().sig(),
_ => map_closure_ty.fn_sig(cx.tcx),
};
let map_closure_return_ty = cx.tcx.erase_late_bound_regions(&map_closure_sig.output());
let map_closure_return_ty = cx.tcx.erase_late_bound_regions(map_closure_sig.output());
is_type_diagnostic_item(cx, map_closure_return_ty, sym::option_type)
},
_ => false,

View File

@ -92,7 +92,7 @@ fn check_sig<'tcx>(cx: &LateContext<'tcx>, item_hir_id: hir::HirId, decl: &hir::
check_ty(
cx,
decl.output.span(),
cx.tcx.erase_late_bound_regions(&fn_sig.output()),
cx.tcx.erase_late_bound_regions(fn_sig.output()),
);
}

View File

@ -141,7 +141,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
};
let fn_sig = cx.tcx.fn_sig(fn_def_id);
let fn_sig = cx.tcx.erase_late_bound_regions(&fn_sig);
let fn_sig = cx.tcx.erase_late_bound_regions(fn_sig);
for (idx, ((input, &ty), arg)) in decl.inputs.iter().zip(fn_sig.inputs()).zip(body.params).enumerate() {
// All spans generated from a proc-macro invocation are the same...

View File

@ -115,7 +115,7 @@ impl<'tcx> PassByRefOrValue {
let fn_def_id = cx.tcx.hir().local_def_id(hir_id);
let fn_sig = cx.tcx.fn_sig(fn_def_id);
let fn_sig = cx.tcx.erase_late_bound_regions(&fn_sig);
let fn_sig = cx.tcx.erase_late_bound_regions(fn_sig);
let fn_body = cx.enclosing_body.map(|id| cx.tcx.hir().body(id));

View File

@ -491,7 +491,7 @@ impl<'tcx> LateLintPass<'tcx> for Transmute {
Applicability::Unspecified,
);
} else {
if (cx.tcx.erase_regions(&from_ty) != cx.tcx.erase_regions(&to_ty))
if (cx.tcx.erase_regions(from_ty) != cx.tcx.erase_regions(to_ty))
&& !const_context {
span_lint_and_then(
cx,

View File

@ -43,7 +43,7 @@ fn get_trait_predicates_for_trait_id<'tcx>(
for (pred, _) in generics.predicates {
if_chain! {
if let PredicateAtom::Trait(poly_trait_pred, _) = pred.skip_binders();
let trait_pred = cx.tcx.erase_late_bound_regions(&ty::Binder::bind(poly_trait_pred));
let trait_pred = cx.tcx.erase_late_bound_regions(ty::Binder::bind(poly_trait_pred));
if let Some(trait_def_id) = trait_id;
if trait_def_id == trait_pred.trait_ref.def_id;
then {
@ -61,7 +61,7 @@ fn get_projection_pred<'tcx>(
) -> Option<ProjectionPredicate<'tcx>> {
generics.predicates.iter().find_map(|(proj_pred, _)| {
if let ty::PredicateAtom::Projection(proj_pred) = proj_pred.skip_binders() {
let projection_pred = cx.tcx.erase_late_bound_regions(&ty::Binder::bind(proj_pred));
let projection_pred = cx.tcx.erase_late_bound_regions(ty::Binder::bind(proj_pred));
if projection_pred.projection_ty.substs == pred.trait_ref.substs {
return Some(projection_pred);
}
@ -81,7 +81,7 @@ fn get_args_to_check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Ve
get_trait_predicates_for_trait_id(cx, generics, cx.tcx.lang_items().partial_ord_trait());
// Trying to call erase_late_bound_regions on fn_sig.inputs() gives the following error
// The trait `rustc::ty::TypeFoldable<'_>` is not implemented for `&[&rustc::ty::TyS<'_>]`
let inputs_output = cx.tcx.erase_late_bound_regions(&fn_sig.inputs_and_output());
let inputs_output = cx.tcx.erase_late_bound_regions(fn_sig.inputs_and_output());
inputs_output
.iter()
.rev()
@ -112,7 +112,7 @@ fn check_arg<'tcx>(cx: &LateContext<'tcx>, arg: &'tcx Expr<'tcx>) -> Option<(Spa
if let ExprKind::Closure(_, _fn_decl, body_id, span, _) = arg.kind;
if let ty::Closure(_def_id, substs) = &cx.typeck_results().node_type(arg.hir_id).kind();
let ret_ty = substs.as_closure().sig().output();
let ty = cx.tcx.erase_late_bound_regions(&ret_ty);
let ty = cx.tcx.erase_late_bound_regions(ret_ty);
if ty.is_unit();
then {
if_chain! {

View File

@ -123,7 +123,7 @@ fn check_trait_method_impl_decl<'tcx>(
.expect("impl method matches a trait method");
let trait_method_sig = cx.tcx.fn_sig(trait_method.def_id);
let trait_method_sig = cx.tcx.erase_late_bound_regions(&trait_method_sig);
let trait_method_sig = cx.tcx.erase_late_bound_regions(trait_method_sig);
let output_hir_ty = if let FnRetTy::Return(ty) = &impl_decl.output {
Some(&**ty)

View File

@ -363,7 +363,7 @@ pub fn implements_trait<'tcx>(
if ty.has_infer_types() {
return false;
}
let ty = cx.tcx.erase_regions(&ty);
let ty = cx.tcx.erase_regions(ty);
let ty_params = cx.tcx.mk_substs(ty_params.iter());
cx.tcx.type_implements_trait((trait_id, ty, ty_params, cx.param_env))
}
@ -887,7 +887,7 @@ pub fn is_direct_expn_of(span: Span, name: &str) -> Option<Span> {
pub fn return_ty<'tcx>(cx: &LateContext<'tcx>, fn_item: hir::HirId) -> Ty<'tcx> {
let fn_def_id = cx.tcx.hir().local_def_id(fn_item);
let ret_ty = cx.tcx.fn_sig(fn_def_id).output();
cx.tcx.erase_late_bound_regions(&ret_ty)
cx.tcx.erase_late_bound_regions(ret_ty)
}
/// Walks into `ty` and returns `true` if any inner type is the same as `other_ty`
@ -1220,7 +1220,7 @@ pub fn match_function_call<'tcx>(
pub fn is_normalizable<'tcx>(cx: &LateContext<'tcx>, param_env: ty::ParamEnv<'tcx>, ty: Ty<'tcx>) -> bool {
cx.tcx.infer_ctxt().enter(|infcx| {
let cause = rustc_middle::traits::ObligationCause::dummy();
infcx.at(&cause, param_env).normalize(&ty).is_ok()
infcx.at(&cause, param_env).normalize(ty).is_ok()
})
}