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};
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))
{
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,
);
}
) = 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(_, _) => {
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;