]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_typeck/src/check/pat.rs
Auto merge of #95695 - the8472:vec-codegen-tests, r=Mark-Simulacrum
[rust.git] / compiler / rustc_typeck / src / check / pat.rs
index 464a2cd9524839df7175bf37b1d6e492238b1f26..f3dcf5fff74cc39bd4562826d12b1263616f6d73 100644 (file)
@@ -4,6 +4,7 @@
 use rustc_data_structures::fx::FxHashMap;
 use rustc_errors::{
     pluralize, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed,
+    MultiSpan,
 };
 use rustc_hir as hir;
 use rustc_hir::def::{CtorKind, DefKind, Res};
@@ -18,7 +19,7 @@
 use rustc_span::lev_distance::find_best_match_for_name;
 use rustc_span::source_map::{Span, Spanned};
 use rustc_span::symbol::{kw, sym, Ident};
-use rustc_span::{BytePos, MultiSpan, DUMMY_SP};
+use rustc_span::{BytePos, DUMMY_SP};
 use rustc_trait_selection::autoderef::Autoderef;
 use rustc_trait_selection::traits::{ObligationCause, Pattern};
 use ty::VariantDef;
@@ -404,16 +405,16 @@ fn check_pat_lit(
         let mut pat_ty = ty;
         if let hir::ExprKind::Lit(Spanned { node: ast::LitKind::ByteStr(_), .. }) = lt.kind {
             let expected = self.structurally_resolved_type(span, expected);
-            if let ty::Ref(_, inner_ty, _) = expected.kind() {
-                if matches!(inner_ty.kind(), ty::Slice(_)) {
-                    let tcx = self.tcx;
-                    trace!(?lt.hir_id.local_id, "polymorphic byte string lit");
-                    self.typeck_results
-                        .borrow_mut()
-                        .treat_byte_string_as_slice
-                        .insert(lt.hir_id.local_id);
-                    pat_ty = tcx.mk_imm_ref(tcx.lifetimes.re_static, tcx.mk_slice(tcx.types.u8));
-                }
+            if let ty::Ref(_, inner_ty, _) = expected.kind()
+                && matches!(inner_ty.kind(), ty::Slice(_))
+            {
+                let tcx = self.tcx;
+                trace!(?lt.hir_id.local_id, "polymorphic byte string lit");
+                self.typeck_results
+                    .borrow_mut()
+                    .treat_byte_string_as_slice
+                    .insert(lt.hir_id.local_id);
+                pat_ty = tcx.mk_imm_ref(tcx.lifetimes.re_static, tcx.mk_slice(tcx.types.u8));
             }
         }
 
@@ -480,14 +481,14 @@ fn check_pat_range(
         // Unify each side with `expected`.
         // Subtyping doesn't matter here, as the value is some kind of scalar.
         let demand_eqtype = |x: &mut _, y| {
-            if let Some((ref mut fail, x_ty, x_span)) = *x {
-                if let Some(mut err) = self.demand_eqtype_pat_diag(x_span, expected, x_ty, ti) {
-                    if let Some((_, y_ty, y_span)) = y {
-                        self.endpoint_has_type(&mut err, y_span, y_ty);
-                    }
-                    err.emit();
-                    *fail = true;
-                };
+            if let Some((ref mut fail, x_ty, x_span)) = *x
+                && let Some(mut err) = self.demand_eqtype_pat_diag(x_span, expected, x_ty, ti)
+            {
+                if let Some((_, y_ty, y_span)) = y {
+                    self.endpoint_has_type(&mut err, y_span, y_ty);
+                }
+                err.emit();
+                *fail = true;
             }
         };
         demand_eqtype(&mut lhs, rhs);
@@ -629,7 +630,7 @@ fn check_binding_alt_eq_ty(&self, span: Span, var_id: HirId, ty: Ty<'tcx>, ti: T
         if let Some(mut err) = self.demand_eqtype_pat_diag(span, var_ty, ty, ti) {
             let hir = self.tcx.hir();
             let var_ty = self.resolve_vars_with_obligations(var_ty);
-            let msg = format!("first introduced with type `{}` here", var_ty);
+            let msg = format!("first introduced with type `{var_ty}` here");
             err.span_label(hir.span(var_id), msg);
             let in_match = hir.parent_iter(var_id).any(|(_, n)| {
                 matches!(
@@ -664,8 +665,8 @@ fn borrow_pat_suggestion(
                 {
                     err.span_suggestion(
                         *span,
-                        &format!("did you mean `{}`", snippet),
-                        format!(" &{}", expected),
+                        &format!("did you mean `{snippet}`"),
+                        format!(" &{expected}"),
                         Applicability::MachineApplicable,
                     );
                 }
@@ -700,7 +701,7 @@ pub fn check_dereferenceable(&self, span: Span, expected: Ty<'tcx>, inner: &Pat<
                         "type `{}` cannot be dereferenced",
                         type_str
                     );
-                    err.span_label(span, format!("type `{}` cannot be dereferenced", type_str));
+                    err.span_label(span, format!("type `{type_str}` cannot be dereferenced"));
                     if self.tcx.sess.teach(&err.get_code().unwrap()) {
                         err.note(CANNOT_IMPLICITLY_DEREF_POINTER_TRAIT_OBJ);
                     }
@@ -917,7 +918,7 @@ fn check_pat_tuple_struct(
                 path_str
             );
 
-            let mut err = struct_span_err!(tcx.sess, pat.span, E0164, "{}", msg);
+            let mut err = struct_span_err!(tcx.sess, pat.span, E0164, "{msg}");
             match res {
                 Res::Def(DefKind::Fn | DefKind::AssocFn, _) => {
                     err.span_label(pat.span, "`fn` calls are not allowed in patterns");
@@ -1395,8 +1396,7 @@ fn error_tuple_variant_index_shorthand(
                     self.tcx.sess,
                     pat.span,
                     E0769,
-                    "tuple variant `{}` written as struct variant",
-                    path
+                    "tuple variant `{path}` written as struct variant",
                 );
                 err.span_suggestion_verbose(
                     qpath.span().shrink_to_hi().to(pat.span.shrink_to_hi()),
@@ -1421,8 +1421,7 @@ fn error_foreign_non_exhaustive_spat(&self, pat: &Pat<'_>, descr: &str, no_field
             sess,
             pat.span,
             E0638,
-            "`..` required with {} marked as non-exhaustive",
-            descr
+            "`..` required with {descr} marked as non-exhaustive",
         );
         err.span_suggestion_verbose(
             sp_comma,
@@ -1441,8 +1440,8 @@ fn error_field_already_bound(&self, span: Span, ident: Ident, other_field: Span)
             "field `{}` bound multiple times in the pattern",
             ident
         )
-        .span_label(span, format!("multiple uses of `{}` in pattern", ident))
-        .span_label(other_field, format!("first use of `{}`", ident))
+        .span_label(span, format!("multiple uses of `{ident}` in pattern"))
+        .span_label(other_field, format!("first use of `{ident}`"))
         .emit();
     }