提交 15c1c065 编写于 作者: B b-naber

rebase

上级 e14b34c3
...@@ -97,7 +97,7 @@ pub(crate) fn try_destructure_const<'tcx>( ...@@ -97,7 +97,7 @@ pub(crate) fn try_destructure_const<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
const_: ty::Const<'tcx>, const_: ty::Const<'tcx>,
) -> Option<ty::DestructuredConst<'tcx>> { ) -> Option<ty::DestructuredConst<'tcx>> {
if let ty::ConstKind::Value(valtree) = const_.val() { if let ty::ConstKind::Value(valtree) = const_.kind() {
let branches = match valtree { let branches = match valtree {
ty::ValTree::Branch(b) => b, ty::ValTree::Branch(b) => b,
_ => return None, _ => return None,
...@@ -216,7 +216,7 @@ pub(crate) fn deref_mir_constant<'tcx>( ...@@ -216,7 +216,7 @@ pub(crate) fn deref_mir_constant<'tcx>(
let mplace = ecx.deref_operand(&op).unwrap(); let mplace = ecx.deref_operand(&op).unwrap();
if let Some(alloc_id) = mplace.ptr.provenance { if let Some(alloc_id) = mplace.ptr.provenance {
assert_eq!( 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, Mutability::Not,
"deref_mir_constant cannot be used with mutable allocations as \ "deref_mir_constant cannot be used with mutable allocations as \
that could allow pattern matching to observe mutable statics", that could allow pattern matching to observe mutable statics",
......
...@@ -638,7 +638,7 @@ pub fn const_to_op( ...@@ -638,7 +638,7 @@ pub fn const_to_op(
span_bug!(self.cur_span(), "const_to_op: Unexpected ConstKind {:?}", c) span_bug!(self.cur_span(), "const_to_op: Unexpected ConstKind {:?}", c)
} }
ty::ConstKind::Value(valtree) => { ty::ConstKind::Value(valtree) => {
let ty = val.ty(); let ty = c.ty();
let const_val = self.tcx.valtree_to_const_val((ty, valtree)); let const_val = self.tcx.valtree_to_const_val((ty, valtree));
self.const_val_to_op(const_val, ty, layout) self.const_val_to_op(const_val, ty, layout)
} }
......
...@@ -1446,11 +1446,7 @@ pub fn expand_statements<F, I>(&mut self, mut f: F) ...@@ -1446,11 +1446,7 @@ pub fn expand_statements<F, I>(&mut self, mut f: F)
} }
pub fn visitable(&self, index: usize) -> &dyn MirVisitable<'tcx> { pub fn visitable(&self, index: usize) -> &dyn MirVisitable<'tcx> {
if index < self.statements.len() { if index < self.statements.len() { &self.statements[index] } else { &self.terminator }
&self.statements[index]
} else {
&self.terminator
}
} }
} }
...@@ -2471,11 +2467,7 @@ pub fn constant(&self) -> Option<&Constant<'tcx>> { ...@@ -2471,11 +2467,7 @@ pub fn constant(&self) -> Option<&Constant<'tcx>> {
/// find as the `func` in a [`TerminatorKind::Call`]. /// find as the `func` in a [`TerminatorKind::Call`].
pub fn const_fn_def(&self) -> Option<(DefId, SubstsRef<'tcx>)> { pub fn const_fn_def(&self) -> Option<(DefId, SubstsRef<'tcx>)> {
let const_ty = self.constant()?.literal.ty(); let const_ty = self.constant()?.literal.ty();
if let ty::FnDef(def_id, substs) = *const_ty.kind() { if let ty::FnDef(def_id, substs) = *const_ty.kind() { Some((def_id, substs)) } else { None }
Some((def_id, substs))
} else {
None
}
} }
} }
...@@ -2995,7 +2987,7 @@ pub fn try_to_value(self, tcx: TyCtxt<'tcx>) -> Option<interpret::ConstValue<'tc ...@@ -2995,7 +2987,7 @@ pub fn try_to_value(self, tcx: TyCtxt<'tcx>) -> Option<interpret::ConstValue<'tc
#[inline] #[inline]
pub fn try_to_scalar(self) -> Option<Scalar> { pub fn try_to_scalar(self) -> Option<Scalar> {
match self { match self {
ConstantKind::Ty(c) => match c.val() { ConstantKind::Ty(c) => match c.kind() {
ty::ConstKind::Value(valtree) => match valtree { ty::ConstKind::Value(valtree) => match valtree {
ty::ValTree::Leaf(scalar_int) => Some(Scalar::Int(scalar_int)), ty::ValTree::Leaf(scalar_int) => Some(Scalar::Int(scalar_int)),
ty::ValTree::Branch(_) => None, ty::ValTree::Branch(_) => None,
...@@ -3291,7 +3283,7 @@ fn from_opt_const_arg_anon_const( ...@@ -3291,7 +3283,7 @@ fn from_opt_const_arg_anon_const(
} }
pub fn from_const(c: ty::Const<'tcx>, tcx: TyCtxt<'tcx>) -> Self { pub fn from_const(c: ty::Const<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
match c.val() { match c.kind() {
ty::ConstKind::Value(valtree) => { ty::ConstKind::Value(valtree) => {
let const_val = tcx.valtree_to_const_val((c.ty(), valtree)); let const_val = tcx.valtree_to_const_val((c.ty(), valtree));
Self::Val(const_val, c.ty()) Self::Val(const_val, c.ty())
...@@ -3587,7 +3579,7 @@ fn pretty_print_const_value<'tcx>( ...@@ -3587,7 +3579,7 @@ fn pretty_print_const_value<'tcx>(
} }
} }
(ConstValue::ByRef { alloc, offset }, ty::Array(t, n)) if *t == u8_type => { (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 // 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 range = AllocRange { start: offset, size: Size::from_bytes(n) };
let byte_str = alloc.inner().get_bytes(&tcx, range).unwrap(); let byte_str = alloc.inner().get_bytes(&tcx, range).unwrap();
......
...@@ -484,7 +484,7 @@ fn visit_constant(&mut self, constant: &Constant<'tcx>, _location: Location) { ...@@ -484,7 +484,7 @@ fn visit_constant(&mut self, constant: &Constant<'tcx>, _location: Location) {
// This reflects what `Const` looked liked before `val` was renamed // This reflects what `Const` looked liked before `val` was renamed
// as `kind`. We print it like this to avoid having to update // as `kind`. We print it like this to avoid having to update
// expected output in a lot of tests. // 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));
} }
} }
......
...@@ -201,7 +201,7 @@ pub fn from_value(tcx: TyCtxt<'tcx>, val: ty::ValTree<'tcx>, ty: Ty<'tcx>) -> Se ...@@ -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 /// Panics if self.kind != ty::ConstKind::Value
pub fn to_valtree(self) -> ty::ValTree<'tcx> { pub fn to_valtree(self) -> ty::ValTree<'tcx> {
match self.val() { match self.kind() {
ty::ConstKind::Value(valtree) => valtree, ty::ConstKind::Value(valtree) => valtree,
_ => bug!("expected ConstKind::Value"), _ => bug!("expected ConstKind::Value"),
} }
...@@ -286,7 +286,7 @@ pub fn eval(self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> Const<'tcx> { ...@@ -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 /// 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. /// 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> { 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 { match val {
Ok(const_val) => ConstantKind::from_value(const_val, self.ty()), Ok(const_val) => ConstantKind::from_value(const_val, self.ty()),
Err(ErrorGuaranteed { .. }) => ConstantKind::Ty(tcx.const_error(self.ty())), Err(ErrorGuaranteed { .. }) => ConstantKind::Ty(tcx.const_error(self.ty())),
......
...@@ -1186,7 +1186,11 @@ pub fn layout_scalar_valid_range(self, def_id: DefId) -> (Bound<u128>, Bound<u12 ...@@ -1186,7 +1186,11 @@ pub fn layout_scalar_valid_range(self, def_id: DefId) -> (Bound<u128>, Bound<u12
}; };
debug!("layout_scalar_valid_range: attr={:?}", attr); debug!("layout_scalar_valid_range: attr={:?}", attr);
if let Some( if let Some(
&[ast::NestedMetaItem::Literal(ast::Lit { kind: ast::LitKind::Int(a, _), .. })], &[
ast::NestedMetaItem::Literal(ast::Lit {
kind: ast::LitKind::Int(a, _), ..
}),
],
) = attr.meta_item_list().as_deref() ) = attr.meta_item_list().as_deref()
{ {
Bound::Included(a) Bound::Included(a)
...@@ -1659,7 +1663,7 @@ pub trait Lift<'tcx>: fmt::Debug { ...@@ -1659,7 +1663,7 @@ pub trait Lift<'tcx>: fmt::Debug {
impl<'a, 'tcx> Lift<'tcx> for $ty { impl<'a, 'tcx> Lift<'tcx> for $ty {
type Lifted = $lifted; type Lifted = $lifted;
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
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 // SAFETY: `self` is interned and therefore valid
// for the entire lifetime of the `TyCtxt`. // for the entire lifetime of the `TyCtxt`.
Some(unsafe { mem::transmute(self) }) Some(unsafe { mem::transmute(self) })
...@@ -2244,11 +2248,7 @@ pub fn signature_unclosure( ...@@ -2244,11 +2248,7 @@ pub fn signature_unclosure(
/// `*r == kind`. /// `*r == kind`.
#[inline] #[inline]
pub fn reuse_or_mk_region(self, r: Region<'tcx>, kind: RegionKind) -> Region<'tcx> { pub fn reuse_or_mk_region(self, r: Region<'tcx>, kind: RegionKind) -> Region<'tcx> {
if *r == kind { if *r == kind { r } else { self.mk_region(kind) }
r
} else {
self.mk_region(kind)
}
} }
#[allow(rustc::usage_of_ty_tykind)] #[allow(rustc::usage_of_ty_tykind)]
...@@ -2268,11 +2268,7 @@ pub fn reuse_or_mk_predicate( ...@@ -2268,11 +2268,7 @@ pub fn reuse_or_mk_predicate(
pred: Predicate<'tcx>, pred: Predicate<'tcx>,
binder: Binder<'tcx, PredicateKind<'tcx>>, binder: Binder<'tcx, PredicateKind<'tcx>>,
) -> Predicate<'tcx> { ) -> Predicate<'tcx> {
if pred.kind() != binder { if pred.kind() != binder { self.mk_predicate(binder) } else { pred }
self.mk_predicate(binder)
} else {
pred
}
} }
pub fn mk_mach_int(self, tm: IntTy) -> Ty<'tcx> { pub fn mk_mach_int(self, tm: IntTy) -> Ty<'tcx> {
...@@ -2417,11 +2413,7 @@ pub fn mk_unit(self) -> Ty<'tcx> { ...@@ -2417,11 +2413,7 @@ pub fn mk_unit(self) -> Ty<'tcx> {
#[inline] #[inline]
pub fn mk_diverging_default(self) -> Ty<'tcx> { pub fn mk_diverging_default(self) -> Ty<'tcx> {
if self.features().never_type_fallback { if self.features().never_type_fallback { self.types.never } else { self.types.unit }
self.types.never
} else {
self.types.unit
}
} }
#[inline] #[inline]
...@@ -2572,9 +2564,11 @@ pub fn intern_poly_existential_predicates( ...@@ -2572,9 +2564,11 @@ pub fn intern_poly_existential_predicates(
eps: &[ty::Binder<'tcx, ExistentialPredicate<'tcx>>], eps: &[ty::Binder<'tcx, ExistentialPredicate<'tcx>>],
) -> &'tcx List<ty::Binder<'tcx, ExistentialPredicate<'tcx>>> { ) -> &'tcx List<ty::Binder<'tcx, ExistentialPredicate<'tcx>>> {
assert!(!eps.is_empty()); assert!(!eps.is_empty());
assert!(eps assert!(
.array_windows() eps.array_windows()
.all(|[a, b]| a.skip_binder().stable_cmp(self, &b.skip_binder()) != Ordering::Greater)); .all(|[a, b]| a.skip_binder().stable_cmp(self, &b.skip_binder())
!= Ordering::Greater)
);
self._intern_poly_existential_predicates(eps) self._intern_poly_existential_predicates(eps)
} }
...@@ -2607,49 +2601,29 @@ pub fn intern_type_list(self, ts: &[Ty<'tcx>]) -> &'tcx List<Ty<'tcx>> { ...@@ -2607,49 +2601,29 @@ pub fn intern_type_list(self, ts: &[Ty<'tcx>]) -> &'tcx List<Ty<'tcx>> {
} }
pub fn intern_substs(self, ts: &[GenericArg<'tcx>]) -> &'tcx List<GenericArg<'tcx>> { pub fn intern_substs(self, ts: &[GenericArg<'tcx>]) -> &'tcx List<GenericArg<'tcx>> {
if ts.is_empty() { if ts.is_empty() { List::empty() } else { self._intern_substs(ts) }
List::empty()
} else {
self._intern_substs(ts)
}
} }
pub fn intern_projs(self, ps: &[ProjectionKind]) -> &'tcx List<ProjectionKind> { pub fn intern_projs(self, ps: &[ProjectionKind]) -> &'tcx List<ProjectionKind> {
if ps.is_empty() { if ps.is_empty() { List::empty() } else { self._intern_projs(ps) }
List::empty()
} else {
self._intern_projs(ps)
}
} }
pub fn intern_place_elems(self, ts: &[PlaceElem<'tcx>]) -> &'tcx List<PlaceElem<'tcx>> { pub fn intern_place_elems(self, ts: &[PlaceElem<'tcx>]) -> &'tcx List<PlaceElem<'tcx>> {
if ts.is_empty() { if ts.is_empty() { List::empty() } else { self._intern_place_elems(ts) }
List::empty()
} else {
self._intern_place_elems(ts)
}
} }
pub fn intern_canonical_var_infos( pub fn intern_canonical_var_infos(
self, self,
ts: &[CanonicalVarInfo<'tcx>], ts: &[CanonicalVarInfo<'tcx>],
) -> CanonicalVarInfos<'tcx> { ) -> CanonicalVarInfos<'tcx> {
if ts.is_empty() { if ts.is_empty() { List::empty() } else { self._intern_canonical_var_infos(ts) }
List::empty()
} else {
self._intern_canonical_var_infos(ts)
}
} }
pub fn intern_bound_variable_kinds( pub fn intern_bound_variable_kinds(
self, self,
ts: &[ty::BoundVariableKind], ts: &[ty::BoundVariableKind],
) -> &'tcx List<ty::BoundVariableKind> { ) -> &'tcx List<ty::BoundVariableKind> {
if ts.is_empty() { if ts.is_empty() { List::empty() } else { self._intern_bound_variable_kinds(ts) }
List::empty()
} else {
self._intern_bound_variable_kinds(ts)
}
} }
pub fn mk_fn_sig<I>( pub fn mk_fn_sig<I>(
......
...@@ -607,11 +607,7 @@ fn pretty_print_type(mut self, ty: Ty<'tcx>) -> Result<Self::Type, Self::Error> ...@@ -607,11 +607,7 @@ fn pretty_print_type(mut self, ty: Ty<'tcx>) -> Result<Self::Type, Self::Error>
} }
} }
} else { } else {
if verbose { if verbose { p!(write("{:?}", infer_ty)) } else { p!(write("{}", infer_ty)) }
p!(write("{:?}", infer_ty))
} else {
p!(write("{}", infer_ty))
}
} }
} }
ty::Error(_) => p!("[type error]"), ty::Error(_) => p!("[type error]"),
...@@ -1335,11 +1331,7 @@ fn pretty_print_const_scalar_int( ...@@ -1335,11 +1331,7 @@ fn pretty_print_const_scalar_int(
ty::Uint(_) | ty::Int(_) => { ty::Uint(_) | ty::Int(_) => {
let int = let int =
ConstInt::new(int, matches!(ty.kind(), ty::Int(_)), ty.is_ptr_sized_integral()); ConstInt::new(int, matches!(ty.kind(), ty::Int(_)), ty.is_ptr_sized_integral());
if print_ty { if print_ty { p!(write("{:#?}", int)) } else { p!(write("{:?}", int)) }
p!(write("{:#?}", int))
} else {
p!(write("{:?}", int))
}
} }
// Char // Char
ty::Char if char::try_from(int).is_ok() => { ty::Char if char::try_from(int).is_ok() => {
...@@ -2294,7 +2286,7 @@ impl<'tcx> ty::fold::TypeVisitor<'tcx> for LateBoundRegionNameCollector<'_, 'tcx ...@@ -2294,7 +2286,7 @@ impl<'tcx> ty::fold::TypeVisitor<'tcx> for LateBoundRegionNameCollector<'_, 'tcx
type BreakTy = (); type BreakTy = ();
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> { fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
trace!("address: {:p}", r.0 .0); trace!("address: {:p}", r.0.0);
if let ty::ReLateBound(_, ty::BoundRegion { kind: ty::BrNamed(_, name), .. }) = *r { if let ty::ReLateBound(_, ty::BoundRegion { kind: ty::BrNamed(_, name), .. }) = *r {
self.used_region_names.insert(name); self.used_region_names.insert(name);
} else if let ty::RePlaceholder(ty::PlaceholderRegion { } else if let ty::RePlaceholder(ty::PlaceholderRegion {
......
...@@ -669,7 +669,7 @@ fn print_const(mut self, ct: ty::Const<'tcx>) -> Result<Self::Const, Self::Error ...@@ -669,7 +669,7 @@ fn print_const(mut self, ct: ty::Const<'tcx>) -> Result<Self::Const, Self::Error
.expect("tried to dereference on non-ptr type") .expect("tried to dereference on non-ptr type")
.ty; .ty;
let dereferenced_const = let dereferenced_const =
self.tcx.mk_const(ty::ConstS { val: ct.val(), ty: pointee_ty }); self.tcx.mk_const(ty::ConstS { kind: ct.kind(), ty: pointee_ty });
self = dereferenced_const.print(self)?; self = dereferenced_const.print(self)?;
} }
} }
......
...@@ -407,7 +407,7 @@ fn process_changed_obligations( ...@@ -407,7 +407,7 @@ fn process_changed_obligations(
let pred = let pred =
ty::Binder::dummy(infcx.replace_bound_vars_with_placeholders(binder)); ty::Binder::dummy(infcx.replace_bound_vars_with_placeholders(binder));
ProcessResult::Changed(mk_pending(vec![ ProcessResult::Changed(mk_pending(vec![
obligation.with(pred.to_predicate(self.selcx.tcx())) obligation.with(pred.to_predicate(self.selcx.tcx())),
])) ]))
} }
ty::PredicateKind::TypeWellFormedFromEnv(..) => { ty::PredicateKind::TypeWellFormedFromEnv(..) => {
......
...@@ -2578,11 +2578,7 @@ fn head(&self) -> Option<&'o TraitObligationStack<'o, 'tcx>> { ...@@ -2578,11 +2578,7 @@ fn head(&self) -> Option<&'o TraitObligationStack<'o, 'tcx>> {
} }
fn depth(&self) -> usize { fn depth(&self) -> usize {
if let Some(head) = self.head { if let Some(head) = self.head { head.depth } else { 0 }
head.depth
} else {
0
}
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册