Rollup merge of #128762 - fmease:use-more-slice-pats, r=compiler-errors
Use more slice patterns inside the compiler Nothing super noteworthy. Just replacing the common 'fragile' pattern of "length check followed by indexing or unwrap" with slice patterns for legibility and 'robustness'. r? ghost
This commit is contained in:
commit
32e0fe129d
40 changed files with 191 additions and 221 deletions
|
@ -944,8 +944,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)
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue