Re-format let-else per rustfmt update
This commit is contained in:
parent
67b0cfc761
commit
cc907f80b9
162 changed files with 1404 additions and 947 deletions
|
@ -363,7 +363,8 @@ impl AddToDiagnostic for AddLifetimeParamsSuggestion<'_> {
|
|||
let (
|
||||
hir::Ty { kind: hir::TyKind::Ref(lifetime_sub, _), .. },
|
||||
hir::Ty { kind: hir::TyKind::Ref(lifetime_sup, _), .. },
|
||||
) = (self.ty_sub, self.ty_sup) else {
|
||||
) = (self.ty_sub, self.ty_sup)
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
|
||||
|
|
|
@ -2109,14 +2109,13 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
found: Ty<'tcx>,
|
||||
expected_fields: &List<Ty<'tcx>>,
|
||||
) -> Option<TypeErrorAdditionalDiags> {
|
||||
let [expected_tup_elem] = expected_fields[..] else { return None};
|
||||
let [expected_tup_elem] = expected_fields[..] else { return None };
|
||||
|
||||
if !self.same_type_modulo_infer(expected_tup_elem, found) {
|
||||
return None;
|
||||
}
|
||||
|
||||
let Ok(code) = self.tcx.sess().source_map().span_to_snippet(span)
|
||||
else { return None };
|
||||
let Ok(code) = self.tcx.sess().source_map().span_to_snippet(span) else { return None };
|
||||
|
||||
let sugg = if code.starts_with('(') && code.ends_with(')') {
|
||||
let before_close = span.hi() - BytePos::from_u32(1);
|
||||
|
|
|
@ -419,7 +419,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
}
|
||||
|
||||
let Some(InferSource { span, kind }) = local_visitor.infer_source else {
|
||||
return self.bad_inference_failure_err(failure_span, arg_data, error_code)
|
||||
return self.bad_inference_failure_err(failure_span, arg_data, error_code);
|
||||
};
|
||||
|
||||
let (source_kind, name) = kind.ty_localized_msg(self);
|
||||
|
@ -1157,9 +1157,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> {
|
|||
continue;
|
||||
}
|
||||
|
||||
let Some(param_ty) = self.opt_node_type(param.hir_id) else {
|
||||
continue
|
||||
};
|
||||
let Some(param_ty) = self.opt_node_type(param.hir_id) else { continue };
|
||||
|
||||
if self.generic_arg_contains_target(param_ty.into()) {
|
||||
self.update_infer_source(InferSource {
|
||||
|
|
|
@ -38,8 +38,9 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
let ObligationCauseCode::MatchImpl(parent, impl_def_id) = code else {
|
||||
return None;
|
||||
};
|
||||
let (ObligationCauseCode::BindingObligation(_, binding_span) | ObligationCauseCode::ExprBindingObligation(_, binding_span, ..))
|
||||
= *parent.code() else {
|
||||
let (ObligationCauseCode::BindingObligation(_, binding_span)
|
||||
| ObligationCauseCode::ExprBindingObligation(_, binding_span, ..)) = *parent.code()
|
||||
else {
|
||||
return None;
|
||||
};
|
||||
|
||||
|
@ -67,7 +68,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
let hir::Node::Item(hir::Item {
|
||||
kind: hir::ItemKind::Impl(hir::Impl { self_ty: impl_self_ty, .. }),
|
||||
..
|
||||
}) = impl_node else {
|
||||
}) = impl_node
|
||||
else {
|
||||
bug!("Node not an impl.");
|
||||
};
|
||||
|
||||
|
|
|
@ -503,7 +503,9 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
|
||||
// Get the `Ident` of the method being called and the corresponding `impl` (to point at
|
||||
// `Bar` in `impl Foo for dyn Bar {}` and the definition of the method being called).
|
||||
let Some((ident, self_ty)) = NiceRegionError::get_impl_ident_and_self_ty_from_trait(tcx, instance.def_id(), &v.0) else {
|
||||
let Some((ident, self_ty)) =
|
||||
NiceRegionError::get_impl_ident_and_self_ty_from_trait(tcx, instance.def_id(), &v.0)
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
|
||||
|
|
|
@ -295,12 +295,13 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
// but right now it's not really very smart when it comes to implicit `Sized`
|
||||
// predicates and bounds on the trait itself.
|
||||
|
||||
let Some(impl_def_id) =
|
||||
self.tcx.associated_item(impl_item_def_id).impl_container(self.tcx) else { return; };
|
||||
let Some(trait_ref) = self
|
||||
.tcx
|
||||
.impl_trait_ref(impl_def_id)
|
||||
else { return; };
|
||||
let Some(impl_def_id) = self.tcx.associated_item(impl_item_def_id).impl_container(self.tcx)
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let Some(trait_ref) = self.tcx.impl_trait_ref(impl_def_id) else {
|
||||
return;
|
||||
};
|
||||
let trait_substs = trait_ref
|
||||
.subst_identity()
|
||||
// Replace the explicit self type with `Self` for better suggestion rendering
|
||||
|
@ -309,20 +310,25 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
let trait_item_substs = ty::InternalSubsts::identity_for_item(self.tcx, impl_item_def_id)
|
||||
.rebase_onto(self.tcx, impl_def_id, trait_substs);
|
||||
|
||||
let Ok(trait_predicates) = self
|
||||
.tcx
|
||||
.explicit_predicates_of(trait_item_def_id)
|
||||
.instantiate_own(self.tcx, trait_item_substs)
|
||||
.map(|(pred, _)| {
|
||||
if pred.is_suggestable(self.tcx, false) {
|
||||
Ok(pred.to_string())
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
})
|
||||
.collect::<Result<Vec<_>, ()>>() else { return; };
|
||||
let Ok(trait_predicates) =
|
||||
self.tcx
|
||||
.explicit_predicates_of(trait_item_def_id)
|
||||
.instantiate_own(self.tcx, trait_item_substs)
|
||||
.map(|(pred, _)| {
|
||||
if pred.is_suggestable(self.tcx, false) {
|
||||
Ok(pred.to_string())
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
})
|
||||
.collect::<Result<Vec<_>, ()>>()
|
||||
else {
|
||||
return;
|
||||
};
|
||||
|
||||
let Some(generics) = self.tcx.hir().get_generics(impl_item_def_id) else { return; };
|
||||
let Some(generics) = self.tcx.hir().get_generics(impl_item_def_id) else {
|
||||
return;
|
||||
};
|
||||
|
||||
let suggestion = if trait_predicates.is_empty() {
|
||||
WhereClauseSuggestions::Remove { span: generics.where_clause_span }
|
||||
|
|
|
@ -526,13 +526,23 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
diag: &mut Diagnostic,
|
||||
) {
|
||||
// 0. Extract fn_decl from hir
|
||||
let hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(hir::Closure { body, fn_decl, .. }), .. }) = hir else { return; };
|
||||
let hir::Node::Expr(hir::Expr {
|
||||
kind: hir::ExprKind::Closure(hir::Closure { body, fn_decl, .. }),
|
||||
..
|
||||
}) = hir
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let hir::Body { params, .. } = self.tcx.hir().body(*body);
|
||||
|
||||
// 1. Get the substs of the closure.
|
||||
// 2. Assume exp_found is FnOnce / FnMut / Fn, we can extract function parameters from [1].
|
||||
let Some(expected) = exp_found.expected.skip_binder().substs.get(1) else { return; };
|
||||
let Some(found) = exp_found.found.skip_binder().substs.get(1) else { return; };
|
||||
let Some(expected) = exp_found.expected.skip_binder().substs.get(1) else {
|
||||
return;
|
||||
};
|
||||
let Some(found) = exp_found.found.skip_binder().substs.get(1) else {
|
||||
return;
|
||||
};
|
||||
let expected = expected.unpack();
|
||||
let found = found.unpack();
|
||||
// 3. Extract the tuple type from Fn trait and suggest the change.
|
||||
|
@ -711,7 +721,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
|
||||
let hir = self.tcx.hir();
|
||||
for stmt in blk.stmts.iter().rev() {
|
||||
let hir::StmtKind::Local(local) = &stmt.kind else { continue; };
|
||||
let hir::StmtKind::Local(local) = &stmt.kind else {
|
||||
continue;
|
||||
};
|
||||
local.pat.walk(&mut find_compatible_candidates);
|
||||
}
|
||||
match hir.find_parent(blk.hir_id) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue