diff --git a/compiler/rustc_abi/src/layout.rs b/compiler/rustc_abi/src/layout.rs index cca1d499088f4..dd298d47529ae 100644 --- a/compiler/rustc_abi/src/layout.rs +++ b/compiler/rustc_abi/src/layout.rs @@ -85,11 +85,11 @@ rustc_index::newtype_index! { // but *not* an encoding of the discriminant (e.g., a tag value). // See issue #49298 for more details on the need to leave space // for non-ZST uninhabited data (mostly partial initialization). -fn absent<'a, FieldIdx, VariantIdx, F>(fields: &IndexSlice) -> bool +fn absent(fields: &IndexSlice) -> bool where FieldIdx: Idx, VariantIdx: Idx, - F: Deref> + fmt::Debug, + F: Deref> + fmt::Debug, { let uninhabited = fields.iter().any(|f| f.is_uninhabited()); // We cannot ignore alignment; that might lead us to entirely discard a variant and @@ -239,8 +239,7 @@ impl LayoutCalculator { /// This uses dedicated code instead of [`Self::layout_of_struct_or_enum`], as coroutine /// fields may be shared between multiple variants (see the [`coroutine`] module for details). pub fn coroutine< - 'a, - F: Deref> + fmt::Debug + Copy, + F: Deref> + fmt::Debug + Copy, VariantIdx: Idx, FieldIdx: Idx, LocalIdx: Idx, @@ -263,10 +262,9 @@ impl LayoutCalculator { } pub fn univariant< - 'a, FieldIdx: Idx, VariantIdx: Idx, - F: Deref> + fmt::Debug + Copy, + F: Deref> + fmt::Debug + Copy, >( &self, fields: &IndexSlice, @@ -338,10 +336,9 @@ impl LayoutCalculator { } pub fn layout_of_struct_or_enum< - 'a, FieldIdx: Idx, VariantIdx: Idx, - F: Deref> + fmt::Debug + Copy, + F: Deref> + fmt::Debug + Copy, >( &self, repr: &ReprOptions, @@ -394,10 +391,9 @@ impl LayoutCalculator { } pub fn layout_of_union< - 'a, FieldIdx: Idx, VariantIdx: Idx, - F: Deref> + fmt::Debug + Copy, + F: Deref> + fmt::Debug + Copy, >( &self, repr: &ReprOptions, @@ -520,10 +516,9 @@ impl LayoutCalculator { /// single-variant enums are just structs, if you think about it fn layout_of_struct< - 'a, FieldIdx: Idx, VariantIdx: Idx, - F: Deref> + fmt::Debug + Copy, + F: Deref> + fmt::Debug + Copy, >( &self, repr: &ReprOptions, @@ -620,10 +615,9 @@ impl LayoutCalculator { } fn layout_of_enum< - 'a, FieldIdx: Idx, VariantIdx: Idx, - F: Deref> + fmt::Debug + Copy, + F: Deref> + fmt::Debug + Copy, >( &self, repr: &ReprOptions, @@ -1158,10 +1152,9 @@ impl LayoutCalculator { } fn univariant_biased< - 'a, FieldIdx: Idx, VariantIdx: Idx, - F: Deref> + fmt::Debug + Copy, + F: Deref> + fmt::Debug + Copy, >( &self, fields: &IndexSlice, @@ -1499,10 +1492,9 @@ impl LayoutCalculator { } fn format_field_niches< - 'a, FieldIdx: Idx, VariantIdx: Idx, - F: Deref> + fmt::Debug, + F: Deref> + fmt::Debug, >( &self, layout: &LayoutData, diff --git a/compiler/rustc_abi/src/layout/coroutine.rs b/compiler/rustc_abi/src/layout/coroutine.rs index 815cf1e28a08c..ccd9ec0aebd4b 100644 --- a/compiler/rustc_abi/src/layout/coroutine.rs +++ b/compiler/rustc_abi/src/layout/coroutine.rs @@ -137,8 +137,7 @@ fn coroutine_saved_local_eligibility> + core::fmt::Debug + Copy, + F: core::ops::Deref> + core::fmt::Debug + Copy, VariantIdx: Idx, FieldIdx: Idx, LocalIdx: Idx, diff --git a/compiler/rustc_abi/src/layout/ty.rs b/compiler/rustc_abi/src/layout/ty.rs index 7698a40629daf..18099d57d7614 100644 --- a/compiler/rustc_abi/src/layout/ty.rs +++ b/compiler/rustc_abi/src/layout/ty.rs @@ -24,9 +24,9 @@ impl<'a> fmt::Debug for Layout<'a> { } impl<'a> Deref for Layout<'a> { - type Target = &'a LayoutData; - fn deref(&self) -> &&'a LayoutData { - &self.0.0 + type Target = LayoutData; + fn deref(&self) -> &Self::Target { + self.0.0 } } @@ -88,9 +88,9 @@ impl<'a, Ty: fmt::Display> fmt::Debug for TyAndLayout<'a, Ty> { } impl<'a, Ty> Deref for TyAndLayout<'a, Ty> { - type Target = &'a LayoutData; - fn deref(&self) -> &&'a LayoutData { - &self.layout.0.0 + type Target = LayoutData; + fn deref(&self) -> &Self::Target { + self.layout.0.0 } } diff --git a/compiler/rustc_const_eval/src/interpret/discriminant.rs b/compiler/rustc_const_eval/src/interpret/discriminant.rs index c50d9db8be639..8ce0608329151 100644 --- a/compiler/rustc_const_eval/src/interpret/discriminant.rs +++ b/compiler/rustc_const_eval/src/interpret/discriminant.rs @@ -64,7 +64,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { // declared list of variants -- they can differ with explicitly assigned discriminants. // We use "tag" to refer to how the discriminant is encoded in memory, which can be either // straight-forward (`TagEncoding::Direct`) or with a niche (`TagEncoding::Niche`). - let (tag_scalar_layout, tag_encoding, tag_field) = match op.layout().variants { + let layout = op.layout(); + let (tag_scalar_layout, tag_encoding, tag_field) = match layout.variants { Variants::Empty => { throw_ub!(UninhabitedEnumVariantRead(None)); } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 991c996dffbf7..dbee11b7aefa1 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -3074,10 +3074,10 @@ struct CallCtxt<'a, 'b, 'tcx> { } impl<'a, 'b, 'tcx> Deref for CallCtxt<'a, 'b, 'tcx> { - type Target = &'a FnCtxt<'b, 'tcx>; + type Target = FnCtxt<'b, 'tcx>; fn deref(&self) -> &Self::Target { - &self.fn_ctxt + self.fn_ctxt } } diff --git a/compiler/rustc_middle/src/ty/consts/valtree.rs b/compiler/rustc_middle/src/ty/consts/valtree.rs index 50242613b3e7f..ed48cb1b13b07 100644 --- a/compiler/rustc_middle/src/ty/consts/valtree.rs +++ b/compiler/rustc_middle/src/ty/consts/valtree.rs @@ -63,11 +63,11 @@ impl<'tcx> ValTree<'tcx> { } impl<'tcx> Deref for ValTree<'tcx> { - type Target = &'tcx ty::ValTreeKind>; + type Target = ty::ValTreeKind>; #[inline] - fn deref(&self) -> &&'tcx ty::ValTreeKind> { - &self.0.0 + fn deref(&self) -> &Self::Target { + self.0.0 } } @@ -168,7 +168,7 @@ impl<'tcx> Value<'tcx> { /// if this constant is some other kind. #[inline] pub fn to_leaf(self) -> ScalarInt { - match &**self.valtree { + match &*self.valtree { ValTreeKind::Leaf(s) => *s, ValTreeKind::Branch(..) => bug!("expected leaf, got {:?}", self), } @@ -178,7 +178,7 @@ impl<'tcx> Value<'tcx> { /// if this constant is some other kind. #[inline] pub fn to_branch(self) -> &'tcx [ty::Const<'tcx>] { - match &**self.valtree { + match &*self.valtree { ValTreeKind::Branch(branch) => &**branch, ValTreeKind::Leaf(..) => bug!("expected branch, got {:?}", self), } @@ -186,7 +186,7 @@ impl<'tcx> Value<'tcx> { /// Attempts to convert to a `ValTreeKind::Leaf` value. pub fn try_to_leaf(self) -> Option { - match &**self.valtree { + match &*self.valtree { ValTreeKind::Leaf(s) => Some(*s), ValTreeKind::Branch(_) => None, } @@ -199,7 +199,7 @@ impl<'tcx> Value<'tcx> { /// Attempts to convert to a `ValTreeKind::Branch` value. pub fn try_to_branch(self) -> Option<&'tcx [ty::Const<'tcx>]> { - match &**self.valtree { + match &*self.valtree { ValTreeKind::Branch(branch) => Some(&**branch), ValTreeKind::Leaf(_) => None, } diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index d3132d3f65780..9d28126ac5f58 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -2005,10 +2005,10 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { } (ty::ValTreeKind::Leaf(leaf), ty::Ref(_, inner_ty, _)) => { write!(self, "&")?; - return self.pretty_print_const_scalar_int(*leaf, inner_ty, print_ty); + return self.pretty_print_const_scalar_int(leaf, inner_ty, print_ty); } (ty::ValTreeKind::Leaf(leaf), _) => { - return self.pretty_print_const_scalar_int(*leaf, cv.ty, print_ty); + return self.pretty_print_const_scalar_int(leaf, cv.ty, print_ty); } (_, ty::FnDef(def_id, args)) => { // Never allowed today, but we still encounter them in invalid const args. diff --git a/compiler/rustc_mir_build/src/builder/matches/mod.rs b/compiler/rustc_mir_build/src/builder/matches/mod.rs index 5604e86e06722..9168f492e7f32 100644 --- a/compiler/rustc_mir_build/src/builder/matches/mod.rs +++ b/compiler/rustc_mir_build/src/builder/matches/mod.rs @@ -2947,7 +2947,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { if branch.len() != 1 { bug!("malformed valtree for an enum") }; - let ValTreeKind::Leaf(actual_variant_idx) = **branch[0].to_value().valtree else { + let ValTreeKind::Leaf(actual_variant_idx) = *branch[0].to_value().valtree else { bug!("malformed valtree for an enum") };