From 15c1c0652298e9dd3dee45813a2718623f6e3702 Mon Sep 17 00:00:00 2001 From: b-naber Date: Tue, 14 Jun 2022 17:34:37 +0200 Subject: [PATCH] rebase --- .../rustc_const_eval/src/const_eval/mod.rs | 4 +- .../rustc_const_eval/src/interpret/operand.rs | 2 +- compiler/rustc_middle/src/mir/mod.rs | 18 ++---- compiler/rustc_middle/src/mir/pretty.rs | 2 +- compiler/rustc_middle/src/ty/consts.rs | 4 +- compiler/rustc_middle/src/ty/context.rs | 64 ++++++------------- compiler/rustc_middle/src/ty/print/pretty.rs | 14 +--- compiler/rustc_symbol_mangling/src/v0.rs | 2 +- .../src/traits/fulfill.rs | 2 +- .../src/traits/select/mod.rs | 6 +- 10 files changed, 36 insertions(+), 82 deletions(-) diff --git a/compiler/rustc_const_eval/src/const_eval/mod.rs b/compiler/rustc_const_eval/src/const_eval/mod.rs index 793f02a8ade..a1d2e5cf3ef 100644 --- a/compiler/rustc_const_eval/src/const_eval/mod.rs +++ b/compiler/rustc_const_eval/src/const_eval/mod.rs @@ -97,7 +97,7 @@ pub(crate) fn try_destructure_const<'tcx>( tcx: TyCtxt<'tcx>, const_: ty::Const<'tcx>, ) -> Option> { - if let ty::ConstKind::Value(valtree) = const_.val() { + if let ty::ConstKind::Value(valtree) = const_.kind() { let branches = match valtree { ty::ValTree::Branch(b) => b, _ => return None, @@ -216,7 +216,7 @@ pub(crate) fn deref_mir_constant<'tcx>( let mplace = ecx.deref_operand(&op).unwrap(); if let Some(alloc_id) = mplace.ptr.provenance { assert_eq!( - tcx.get_global_alloc(alloc_id).unwrap().unwrap_memory().0 .0.mutability, + tcx.get_global_alloc(alloc_id).unwrap().unwrap_memory().0.0.mutability, Mutability::Not, "deref_mir_constant cannot be used with mutable allocations as \ that could allow pattern matching to observe mutable statics", diff --git a/compiler/rustc_const_eval/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs index e9a9c0e1713..6b05a49575f 100644 --- a/compiler/rustc_const_eval/src/interpret/operand.rs +++ b/compiler/rustc_const_eval/src/interpret/operand.rs @@ -638,7 +638,7 @@ pub fn const_to_op( span_bug!(self.cur_span(), "const_to_op: Unexpected ConstKind {:?}", c) } ty::ConstKind::Value(valtree) => { - let ty = val.ty(); + let ty = c.ty(); let const_val = self.tcx.valtree_to_const_val((ty, valtree)); self.const_val_to_op(const_val, ty, layout) } diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index b3cf8cdde0e..c173d453041 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -1446,11 +1446,7 @@ pub fn expand_statements(&mut self, mut f: F) } pub fn visitable(&self, index: usize) -> &dyn MirVisitable<'tcx> { - if index < self.statements.len() { - &self.statements[index] - } else { - &self.terminator - } + if index < self.statements.len() { &self.statements[index] } else { &self.terminator } } } @@ -2471,11 +2467,7 @@ pub fn constant(&self) -> Option<&Constant<'tcx>> { /// find as the `func` in a [`TerminatorKind::Call`]. pub fn const_fn_def(&self) -> Option<(DefId, SubstsRef<'tcx>)> { let const_ty = self.constant()?.literal.ty(); - if let ty::FnDef(def_id, substs) = *const_ty.kind() { - Some((def_id, substs)) - } else { - None - } + if let ty::FnDef(def_id, substs) = *const_ty.kind() { Some((def_id, substs)) } else { None } } } @@ -2995,7 +2987,7 @@ pub fn try_to_value(self, tcx: TyCtxt<'tcx>) -> Option Option { match self { - ConstantKind::Ty(c) => match c.val() { + ConstantKind::Ty(c) => match c.kind() { ty::ConstKind::Value(valtree) => match valtree { ty::ValTree::Leaf(scalar_int) => Some(Scalar::Int(scalar_int)), ty::ValTree::Branch(_) => None, @@ -3291,7 +3283,7 @@ fn from_opt_const_arg_anon_const( } pub fn from_const(c: ty::Const<'tcx>, tcx: TyCtxt<'tcx>) -> Self { - match c.val() { + match c.kind() { ty::ConstKind::Value(valtree) => { let const_val = tcx.valtree_to_const_val((c.ty(), valtree)); Self::Val(const_val, c.ty()) @@ -3587,7 +3579,7 @@ fn pretty_print_const_value<'tcx>( } } (ConstValue::ByRef { alloc, offset }, ty::Array(t, n)) if *t == u8_type => { - let n = n.val().try_to_bits(tcx.data_layout.pointer_size).unwrap(); + let n = n.kind().try_to_bits(tcx.data_layout.pointer_size).unwrap(); // cast is ok because we already checked for pointer size (32 or 64 bit) above let range = AllocRange { start: offset, size: Size::from_bytes(n) }; let byte_str = alloc.inner().get_bytes(&tcx, range).unwrap(); diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index a81a60df2be..462c0ada3cf 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -484,7 +484,7 @@ fn visit_constant(&mut self, constant: &Constant<'tcx>, _location: Location) { // This reflects what `Const` looked liked before `val` was renamed // as `kind`. We print it like this to avoid having to update // expected output in a lot of tests. - self.push(&format!("+ literal: Const {{ ty: {}, val: {} }}", literal.ty(), kind)); + self.push(&format!("+ literal: Const {{ ty: {}, val: {} }}", literal.ty(), val)); } } diff --git a/compiler/rustc_middle/src/ty/consts.rs b/compiler/rustc_middle/src/ty/consts.rs index fe5c5be15f5..bc52259b151 100644 --- a/compiler/rustc_middle/src/ty/consts.rs +++ b/compiler/rustc_middle/src/ty/consts.rs @@ -201,7 +201,7 @@ pub fn from_value(tcx: TyCtxt<'tcx>, val: ty::ValTree<'tcx>, ty: Ty<'tcx>) -> Se /// Panics if self.kind != ty::ConstKind::Value pub fn to_valtree(self) -> ty::ValTree<'tcx> { - match self.val() { + match self.kind() { ty::ConstKind::Value(valtree) => valtree, _ => bug!("expected ConstKind::Value"), } @@ -286,7 +286,7 @@ pub fn eval(self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> Const<'tcx> { /// Tries to evaluate the constant if it is `Unevaluated` and creates a ConstValue if the /// evaluation succeeds. If it doesn't succeed, returns the unevaluated constant. pub fn eval_for_mir(self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> ConstantKind<'tcx> { - if let Some(val) = self.val().try_eval_for_mir(tcx, param_env) { + if let Some(val) = self.kind().try_eval_for_mir(tcx, param_env) { match val { Ok(const_val) => ConstantKind::from_value(const_val, self.ty()), Err(ErrorGuaranteed { .. }) => ConstantKind::Ty(tcx.const_error(self.ty())), diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 0930f3edf72..4cd25a61626 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -1186,7 +1186,11 @@ pub fn layout_scalar_valid_range(self, def_id: DefId) -> (Bound, Bound: fmt::Debug { impl<'a, 'tcx> Lift<'tcx> for $ty { type Lifted = $lifted; fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option { - if tcx.interners.$set.contains_pointer_to(&InternedInSet(&*self.0 .0)) { + if tcx.interners.$set.contains_pointer_to(&InternedInSet(&*self.0.0)) { // SAFETY: `self` is interned and therefore valid // for the entire lifetime of the `TyCtxt`. Some(unsafe { mem::transmute(self) }) @@ -2244,11 +2248,7 @@ pub fn signature_unclosure( /// `*r == kind`. #[inline] pub fn reuse_or_mk_region(self, r: Region<'tcx>, kind: RegionKind) -> Region<'tcx> { - if *r == kind { - r - } else { - self.mk_region(kind) - } + if *r == kind { r } else { self.mk_region(kind) } } #[allow(rustc::usage_of_ty_tykind)] @@ -2268,11 +2268,7 @@ pub fn reuse_or_mk_predicate( pred: Predicate<'tcx>, binder: Binder<'tcx, PredicateKind<'tcx>>, ) -> Predicate<'tcx> { - if pred.kind() != binder { - self.mk_predicate(binder) - } else { - pred - } + if pred.kind() != binder { self.mk_predicate(binder) } else { pred } } pub fn mk_mach_int(self, tm: IntTy) -> Ty<'tcx> { @@ -2417,11 +2413,7 @@ pub fn mk_unit(self) -> Ty<'tcx> { #[inline] pub fn mk_diverging_default(self) -> Ty<'tcx> { - if self.features().never_type_fallback { - self.types.never - } else { - self.types.unit - } + if self.features().never_type_fallback { self.types.never } else { self.types.unit } } #[inline] @@ -2572,9 +2564,11 @@ pub fn intern_poly_existential_predicates( eps: &[ty::Binder<'tcx, ExistentialPredicate<'tcx>>], ) -> &'tcx List>> { assert!(!eps.is_empty()); - assert!(eps - .array_windows() - .all(|[a, b]| a.skip_binder().stable_cmp(self, &b.skip_binder()) != Ordering::Greater)); + assert!( + eps.array_windows() + .all(|[a, b]| a.skip_binder().stable_cmp(self, &b.skip_binder()) + != Ordering::Greater) + ); self._intern_poly_existential_predicates(eps) } @@ -2607,49 +2601,29 @@ pub fn intern_type_list(self, ts: &[Ty<'tcx>]) -> &'tcx List> { } pub fn intern_substs(self, ts: &[GenericArg<'tcx>]) -> &'tcx List> { - if ts.is_empty() { - List::empty() - } else { - self._intern_substs(ts) - } + if ts.is_empty() { List::empty() } else { self._intern_substs(ts) } } pub fn intern_projs(self, ps: &[ProjectionKind]) -> &'tcx List { - if ps.is_empty() { - List::empty() - } else { - self._intern_projs(ps) - } + if ps.is_empty() { List::empty() } else { self._intern_projs(ps) } } pub fn intern_place_elems(self, ts: &[PlaceElem<'tcx>]) -> &'tcx List> { - if ts.is_empty() { - List::empty() - } else { - self._intern_place_elems(ts) - } + if ts.is_empty() { List::empty() } else { self._intern_place_elems(ts) } } pub fn intern_canonical_var_infos( self, ts: &[CanonicalVarInfo<'tcx>], ) -> CanonicalVarInfos<'tcx> { - if ts.is_empty() { - List::empty() - } else { - self._intern_canonical_var_infos(ts) - } + if ts.is_empty() { List::empty() } else { self._intern_canonical_var_infos(ts) } } pub fn intern_bound_variable_kinds( self, ts: &[ty::BoundVariableKind], ) -> &'tcx List { - if ts.is_empty() { - List::empty() - } else { - self._intern_bound_variable_kinds(ts) - } + if ts.is_empty() { List::empty() } else { self._intern_bound_variable_kinds(ts) } } pub fn mk_fn_sig( diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 129d2051c19..58dab0f96ab 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -607,11 +607,7 @@ fn pretty_print_type(mut self, ty: Ty<'tcx>) -> Result } } } else { - if verbose { - p!(write("{:?}", infer_ty)) - } else { - p!(write("{}", infer_ty)) - } + if verbose { p!(write("{:?}", infer_ty)) } else { p!(write("{}", infer_ty)) } } } ty::Error(_) => p!("[type error]"), @@ -1335,11 +1331,7 @@ fn pretty_print_const_scalar_int( ty::Uint(_) | ty::Int(_) => { let int = ConstInt::new(int, matches!(ty.kind(), ty::Int(_)), ty.is_ptr_sized_integral()); - if print_ty { - p!(write("{:#?}", int)) - } else { - p!(write("{:?}", int)) - } + if print_ty { p!(write("{:#?}", int)) } else { p!(write("{:?}", int)) } } // Char ty::Char if char::try_from(int).is_ok() => { @@ -2294,7 +2286,7 @@ impl<'tcx> ty::fold::TypeVisitor<'tcx> for LateBoundRegionNameCollector<'_, 'tcx type BreakTy = (); fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow { - trace!("address: {:p}", r.0 .0); + trace!("address: {:p}", r.0.0); if let ty::ReLateBound(_, ty::BoundRegion { kind: ty::BrNamed(_, name), .. }) = *r { self.used_region_names.insert(name); } else if let ty::RePlaceholder(ty::PlaceholderRegion { diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index 3cd52183330..87b844ca759 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -669,7 +669,7 @@ fn print_const(mut self, ct: ty::Const<'tcx>) -> Result { diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index a002006f0e6..ee2c8da5a00 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -2578,11 +2578,7 @@ fn head(&self) -> Option<&'o TraitObligationStack<'o, 'tcx>> { } fn depth(&self) -> usize { - if let Some(head) = self.head { - head.depth - } else { - 0 - } + if let Some(head) = self.head { head.depth } else { 0 } } } -- GitLab