Overhaul TyS
and Ty
.
Specifically, change `Ty` from this: ``` pub type Ty<'tcx> = &'tcx TyS<'tcx>; ``` to this ``` pub struct Ty<'tcx>(Interned<'tcx, TyS<'tcx>>); ``` There are two benefits to this. - It's now a first class type, so we can define methods on it. This means we can move a lot of methods away from `TyS`, leaving `TyS` as a barely-used type, which is appropriate given that it's not meant to be used directly. - The uniqueness requirement is now explicit, via the `Interned` type. E.g. the pointer-based `Eq` and `Hash` comes from `Interned`, rather than via `TyS`, which wasn't obvious at all. Much of this commit is boring churn. The interesting changes are in these files: - compiler/rustc_middle/src/arena.rs - compiler/rustc_middle/src/mir/visit.rs - compiler/rustc_middle/src/ty/context.rs - compiler/rustc_middle/src/ty/mod.rs Specifically: - Most mentions of `TyS` are removed. It's very much a dumb struct now; `Ty` has all the smarts. - `TyS` now has `crate` visibility instead of `pub`. - `TyS::make_for_test` is removed in favour of the static `BOOL_TY`, which just works better with the new structure. - The `Eq`/`Ord`/`Hash` impls are removed from `TyS`. `Interned`s impls of `Eq`/`Hash` now suffice. `Ord` is now partly on `Interned` (pointer-based, for the `Equal` case) and partly on `TyS` (contents-based, for the other cases). - There are many tedious sigil adjustments, i.e. adding or removing `*` or `&`. They seem to be unavoidable.
This commit is contained in:
parent
0c2ebbd412
commit
e9a0c429c5
145 changed files with 519 additions and 531 deletions
|
@ -348,7 +348,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
let place_builder = place_builder.clone();
|
||||
this.consume_by_copy_or_move(
|
||||
place_builder
|
||||
.field(n, ty)
|
||||
.field(n, *ty)
|
||||
.into_place(this.tcx, this.typeck_results),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -397,7 +397,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
(Some((region, elem_ty, _)), _) | (None, Some((region, elem_ty, _))) => {
|
||||
let tcx = self.tcx;
|
||||
// make both a slice
|
||||
ty = tcx.mk_imm_ref(region, tcx.mk_slice(elem_ty));
|
||||
ty = tcx.mk_imm_ref(region, tcx.mk_slice(*elem_ty));
|
||||
if opt_ref_ty.is_some() {
|
||||
let temp = self.temp(ty, source_info.span);
|
||||
self.cfg.push_assign(
|
||||
|
|
|
@ -903,7 +903,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
let mut closure_ty = self.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty;
|
||||
if let ty::Ref(_, ty, _) = closure_ty.kind() {
|
||||
closure_env_projs.push(ProjectionElem::Deref);
|
||||
closure_ty = ty;
|
||||
closure_ty = *ty;
|
||||
}
|
||||
let upvar_substs = match closure_ty.kind() {
|
||||
ty::Closure(_, substs) => ty::UpvarSubsts::Closure(substs),
|
||||
|
|
|
@ -556,7 +556,7 @@ fn non_exhaustive_match<'p, 'tcx>(
|
|||
}
|
||||
}
|
||||
if let ty::Ref(_, sub_ty, _) = scrut_ty.kind() {
|
||||
if cx.tcx.is_ty_uninhabited_from(cx.module, sub_ty, cx.param_env) {
|
||||
if cx.tcx.is_ty_uninhabited_from(cx.module, *sub_ty, cx.param_env) {
|
||||
err.note("references are always considered inhabited");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -420,7 +420,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
|
|||
suffix: vec![],
|
||||
}),
|
||||
span,
|
||||
ty: pointee_ty,
|
||||
ty: *pointee_ty,
|
||||
},
|
||||
};
|
||||
self.behind_reference.set(old);
|
||||
|
@ -457,7 +457,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
|
|||
// this pattern to a `PartialEq::eq` comparison and `PartialEq::eq` takes a
|
||||
// reference. This makes the rest of the matching logic simpler as it doesn't have
|
||||
// to figure out how to get a reference again.
|
||||
ty::Adt(adt_def, _) if !self.type_marked_structural(pointee_ty) => {
|
||||
ty::Adt(adt_def, _) if !self.type_marked_structural(*pointee_ty) => {
|
||||
if self.behind_reference.get() {
|
||||
if self.include_lint_checks
|
||||
&& !self.saw_const_match_error.get()
|
||||
|
|
|
@ -929,7 +929,7 @@ impl<'tcx> SplitWildcard<'tcx> {
|
|||
ty::Bool => smallvec![make_range(0, 1)],
|
||||
ty::Array(sub_ty, len) if len.try_eval_usize(cx.tcx, cx.param_env).is_some() => {
|
||||
let len = len.eval_usize(cx.tcx, cx.param_env) as usize;
|
||||
if len != 0 && cx.is_uninhabited(sub_ty) {
|
||||
if len != 0 && cx.is_uninhabited(*sub_ty) {
|
||||
smallvec![]
|
||||
} else {
|
||||
smallvec![Slice(Slice::new(Some(len), VarLen(0, 0)))]
|
||||
|
@ -937,7 +937,7 @@ impl<'tcx> SplitWildcard<'tcx> {
|
|||
}
|
||||
// Treat arrays of a constant but unknown length like slices.
|
||||
ty::Array(sub_ty, _) | ty::Slice(sub_ty) => {
|
||||
let kind = if cx.is_uninhabited(sub_ty) { FixedLen(0) } else { VarLen(0, 0) };
|
||||
let kind = if cx.is_uninhabited(*sub_ty) { FixedLen(0) } else { VarLen(0, 0) };
|
||||
smallvec![Slice(Slice::new(None, kind))]
|
||||
}
|
||||
ty::Adt(def, substs) if def.is_enum() => {
|
||||
|
@ -1386,7 +1386,7 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
|
|||
// fields.
|
||||
// Note: `t` is `str`, not `&str`.
|
||||
let subpattern =
|
||||
DeconstructedPat::new(Str(value), Fields::empty(), t, pat.span);
|
||||
DeconstructedPat::new(Str(value), Fields::empty(), *t, pat.span);
|
||||
ctor = Single;
|
||||
fields = Fields::singleton(cx, subpattern)
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
|||
debug!("{:?}: wrapping pattern with type {:?}", pat, ref_ty);
|
||||
Pat {
|
||||
span: pat.span,
|
||||
ty: ref_ty,
|
||||
ty: *ref_ty,
|
||||
kind: Box::new(PatKind::Deref { subpattern: pat }),
|
||||
}
|
||||
},
|
||||
|
@ -275,7 +275,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
|||
let var_ty = ty;
|
||||
if let ty::BindByReference(_) = bm {
|
||||
if let ty::Ref(_, rty, _) = ty.kind() {
|
||||
ty = rty;
|
||||
ty = *rty;
|
||||
} else {
|
||||
bug!("`ref {}` has wrong type {}", ident, ty);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue