]> git.proxmox.com Git - rustc.git/blobdiff - compiler/rustc_typeck/src/check/place_op.rs
New upstream version 1.62.1+dfsg1
[rustc.git] / compiler / rustc_typeck / src / check / place_op.rs
index 42eec1776495e7ecd72c5b05cc14f20d40ecde07..2e0f37eba232d4762d11b13ae1880f6b4fc6d05d 100644 (file)
@@ -1,7 +1,6 @@
 use crate::check::method::MethodCallee;
 use crate::check::{has_expected_num_generic_args, FnCtxt, PlaceOp};
 use rustc_ast as ast;
-use rustc_data_structures::intern::Interned;
 use rustc_errors::Applicability;
 use rustc_hir as hir;
 use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
@@ -75,9 +74,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         let ty = self.resolve_vars_if_possible(ty);
         let mut err = self.tcx.sess.struct_span_err(
             span,
-            &format!("negative integers cannot be used to index on a `{}`", ty),
+            &format!("negative integers cannot be used to index on a `{ty}`"),
         );
-        err.span_label(span, &format!("cannot use a negative integer for indexing on `{}`", ty));
+        err.span_label(span, &format!("cannot use a negative integer for indexing on `{ty}`"));
         if let (hir::ExprKind::Path(..), Ok(snippet)) =
             (&base_expr.kind, self.tcx.sess.source_map().span_to_snippet(base_expr.span))
         {
@@ -85,10 +84,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
             err.span_suggestion_verbose(
                 span.shrink_to_lo(),
                 &format!(
-                    "to access an element starting from the end of the `{}`, compute the index",
-                    ty,
+                    "to access an element starting from the end of the `{ty}`, compute the index",
                 ),
-                format!("{}.len() ", snippet),
+                format!("{snippet}.len() "),
                 Applicability::MachineApplicable,
             );
         }
@@ -126,9 +124,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         ) = index_expr.kind
         {
             match adjusted_ty.kind() {
-                ty::Adt(ty::AdtDef(Interned(ty::AdtDefData { did, .. }, _)), _)
-                    if self.tcx.is_diagnostic_item(sym::Vec, *did) =>
-                {
+                ty::Adt(def, _) if self.tcx.is_diagnostic_item(sym::Vec, def.did()) => {
                     return self.negative_index(adjusted_ty, index_expr.span, base_expr);
                 }
                 ty::Slice(_) | ty::Array(_, _) => {
@@ -317,32 +313,32 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                 self.typeck_results.borrow_mut().adjustments_mut().remove(expr.hir_id);
             if let Some(mut adjustments) = previous_adjustments {
                 for adjustment in &mut adjustments {
-                    if let Adjust::Deref(Some(ref mut deref)) = adjustment.kind {
-                        if let Some(ok) = self.try_mutable_overloaded_place_op(
+                    if let Adjust::Deref(Some(ref mut deref)) = adjustment.kind
+                        && let Some(ok) = self.try_mutable_overloaded_place_op(
                             expr.span,
                             source,
                             &[],
                             PlaceOp::Deref,
-                        ) {
-                            let method = self.register_infer_ok_obligations(ok);
-                            if let ty::Ref(region, _, mutbl) = *method.sig.output().kind() {
-                                *deref = OverloadedDeref { region, mutbl, span: deref.span };
-                            }
-                            // If this is a union field, also throw an error for `DerefMut` of `ManuallyDrop` (see RFC 2514).
-                            // This helps avoid accidental drops.
-                            if inside_union
-                                && source.ty_adt_def().map_or(false, |adt| adt.is_manually_drop())
-                            {
-                                let mut err = self.tcx.sess.struct_span_err(
-                                    expr.span,
-                                    "not automatically applying `DerefMut` on `ManuallyDrop` union field",
-                                );
-                                err.help(
-                                    "writing to this reference calls the destructor for the old value",
-                                );
-                                err.help("add an explicit `*` if that is desired, or call `ptr::write` to not run the destructor");
-                                err.emit();
-                            }
+                        )
+                    {
+                        let method = self.register_infer_ok_obligations(ok);
+                        if let ty::Ref(region, _, mutbl) = *method.sig.output().kind() {
+                            *deref = OverloadedDeref { region, mutbl, span: deref.span };
+                        }
+                        // If this is a union field, also throw an error for `DerefMut` of `ManuallyDrop` (see RFC 2514).
+                        // This helps avoid accidental drops.
+                        if inside_union
+                            && source.ty_adt_def().map_or(false, |adt| adt.is_manually_drop())
+                        {
+                            let mut err = self.tcx.sess.struct_span_err(
+                                expr.span,
+                                "not automatically applying `DerefMut` on `ManuallyDrop` union field",
+                            );
+                            err.help(
+                                "writing to this reference calls the destructor for the old value",
+                            );
+                            err.help("add an explicit `*` if that is desired, or call `ptr::write` to not run the destructor");
+                            err.emit();
                         }
                     }
                     source = adjustment.target;