Use more slice patterns inside the compiler

This commit is contained in:
León Orell Valerian Liehr 2024-08-07 12:41:49 +02:00
parent 60d146580c
commit c4c518d2d4
No known key found for this signature in database
GPG key ID: D17A07215F68E713
40 changed files with 191 additions and 221 deletions

View file

@ -943,8 +943,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
// The current method call returns `Result<_, ()>`
&& self.can_eq(obligation.param_env, ty, found_ty)
// There's a single argument in the method call and it is a closure
&& args.len() == 1
&& let Some(arg) = args.get(0)
&& let [arg] = args
&& let hir::ExprKind::Closure(closure) = arg.kind
// The closure has a block for its body with no tail expression
&& let body = self.tcx.hir().body(closure.body)

View file

@ -73,10 +73,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
}
});
let impl_def_id_and_args = if self_match_impls.len() == 1 {
self_match_impls[0]
} else if fuzzy_match_impls.len() == 1 {
fuzzy_match_impls[0]
let impl_def_id_and_args = if let [impl_] = self_match_impls[..] {
impl_
} else if let [impl_] = fuzzy_match_impls[..] {
impl_
} else {
return None;
};

View file

@ -5300,7 +5300,8 @@ impl<'v> Visitor<'v> for FindTypeParam {
match ty.kind {
hir::TyKind::Ptr(_) | hir::TyKind::Ref(..) | hir::TyKind::TraitObject(..) => {}
hir::TyKind::Path(hir::QPath::Resolved(None, path))
if path.segments.len() == 1 && path.segments[0].ident.name == self.param =>
if let [segment] = path.segments
&& segment.ident.name == self.param =>
{
if !self.nested {
debug!(?ty, "FindTypeParam::visit_ty");