1
Fork 0

Change ty.kind to a method

This commit is contained in:
LeSeulArtichaut 2020-08-03 00:49:11 +02:00
parent ef55a0a92f
commit 3e14b684dd
189 changed files with 947 additions and 899 deletions

View file

@ -340,7 +340,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
}
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
match t.kind {
match *t.kind() {
ty::Infer(ty::TyVar(vid)) => {
debug!("canonical: type var found with vid {:?}", vid);
match self.infcx.unwrap().probe_ty_var(vid) {

View file

@ -422,7 +422,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
match result_value.unpack() {
GenericArgKind::Type(result_value) => {
// e.g., here `result_value` might be `?0` in the example above...
if let ty::Bound(debruijn, b) = result_value.kind {
if let ty::Bound(debruijn, b) = *result_value.kind() {
// ...in which case we would set `canonical_vars[0]` to `Some(?U)`.
// We only allow a `ty::INNERMOST` index in substitutions.

View file

@ -72,7 +72,7 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
{
let a_is_expected = relation.a_is_expected();
match (&a.kind, &b.kind) {
match (a.kind(), b.kind()) {
// Relate integral variables to other types
(&ty::Infer(ty::IntVar(a_id)), &ty::Infer(ty::IntVar(b_id))) => {
self.inner
@ -541,7 +541,7 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
// any other type variable related to `vid` via
// subtyping. This is basically our "occurs check", preventing
// us from creating infinitely sized types.
match t.kind {
match *t.kind() {
ty::Infer(ty::TyVar(vid)) => {
let vid = self.infcx.inner.borrow_mut().type_variables().root_var(vid);
let sub_vid = self.infcx.inner.borrow_mut().type_variables().sub_root_var(vid);

View file

@ -77,7 +77,7 @@ impl TypeRelation<'tcx> for Equate<'combine, 'infcx, 'tcx> {
debug!("{}.tys: replacements ({:?}, {:?})", self.tag(), a, b);
match (&a.kind, &b.kind) {
match (a.kind(), b.kind()) {
(&ty::Infer(TyVar(a_id)), &ty::Infer(TyVar(b_id))) => {
infcx.inner.borrow_mut().type_variables().equate(a_id, b_id);
}

View file

@ -570,7 +570,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
// if they are both "path types", there's a chance of ambiguity
// due to different versions of the same crate
if let (&ty::Adt(exp_adt, _), &ty::Adt(found_adt, _)) =
(&exp_found.expected.kind, &exp_found.found.kind)
(exp_found.expected.kind(), exp_found.found.kind())
{
report_path_match(err, exp_adt.did, found_adt.did);
}
@ -796,7 +796,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
self.highlight_outer(&mut t1_out, &mut t2_out, path, sub, i, &other_ty);
return Some(());
}
if let &ty::Adt(def, _) = &ta.kind {
if let &ty::Adt(def, _) = ta.kind() {
let path_ = self.tcx.def_path_str(def.did);
if path_ == other_path {
self.highlight_outer(&mut t1_out, &mut t2_out, path, sub, i, &other_ty);
@ -977,11 +977,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
/// Compares two given types, eliding parts that are the same between them and highlighting
/// relevant differences, and return two representation of those types for highlighted printing.
fn cmp(&self, t1: Ty<'tcx>, t2: Ty<'tcx>) -> (DiagnosticStyledString, DiagnosticStyledString) {
debug!("cmp(t1={}, t1.kind={:?}, t2={}, t2.kind={:?})", t1, t1.kind, t2, t2.kind);
debug!("cmp(t1={}, t1.kind={:?}, t2={}, t2.kind={:?})", t1, t1.kind(), t2, t2.kind());
// helper functions
fn equals<'tcx>(a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
match (&a.kind, &b.kind) {
match (a.kind(), b.kind()) {
(a, b) if *a == *b => true,
(&ty::Int(_), &ty::Infer(ty::InferTy::IntVar(_)))
| (
@ -1014,7 +1014,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
}
// process starts here
match (&t1.kind, &t2.kind) {
match (t1.kind(), t2.kind()) {
(&ty::Adt(def1, sub1), &ty::Adt(def2, sub2)) => {
let sub_no_defaults_1 = self.strip_generic_default_params(def1.did, sub1);
let sub_no_defaults_2 = self.strip_generic_default_params(def2.did, sub2);
@ -1476,7 +1476,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
};
match (&terr, expected == found) {
(TypeError::Sorts(values), extra) => {
let sort_string = |ty: Ty<'tcx>| match (extra, &ty.kind) {
let sort_string = |ty: Ty<'tcx>| match (extra, ty.kind()) {
(true, ty::Opaque(def_id, _)) => format!(
" (opaque type at {})",
self.tcx
@ -1563,7 +1563,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
exp_span, exp_found.expected, exp_found.found
);
if let ty::Opaque(def_id, _) = exp_found.expected.kind {
if let ty::Opaque(def_id, _) = *exp_found.expected.kind() {
let future_trait = self.tcx.require_lang_item(LangItem::Future, None);
// Future::Output
let item_def_id = self
@ -1616,9 +1616,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
diag: &mut DiagnosticBuilder<'tcx>,
) {
if let (ty::Adt(exp_def, exp_substs), ty::Ref(_, found_ty, _)) =
(&exp_found.expected.kind, &exp_found.found.kind)
(exp_found.expected.kind(), exp_found.found.kind())
{
if let ty::Adt(found_def, found_substs) = found_ty.kind {
if let ty::Adt(found_def, found_substs) = *found_ty.kind() {
let path_str = format!("{:?}", exp_def);
if exp_def == &found_def {
let opt_msg = "you can convert from `&Option<T>` to `Option<&T>` using \
@ -1637,9 +1637,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
{
let mut show_suggestion = true;
for (exp_ty, found_ty) in exp_substs.types().zip(found_substs.types()) {
match exp_ty.kind {
match *exp_ty.kind() {
ty::Ref(_, exp_ty, _) => {
match (&exp_ty.kind, &found_ty.kind) {
match (exp_ty.kind(), found_ty.kind()) {
(_, ty::Param(_))
| (_, ty::Infer(_))
| (ty::Param(_), _)
@ -1989,7 +1989,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
);
if let Some(infer::RelateParamBound(_, t)) = origin {
let t = self.resolve_vars_if_possible(&t);
match t.kind {
match t.kind() {
// We've got:
// fn get_later<G, T>(g: G, dest: &mut T) -> impl FnOnce() + '_
// suggest:
@ -2231,7 +2231,7 @@ impl TyCategory {
}
pub fn from_ty(ty: Ty<'_>) -> Option<(Self, DefId)> {
match ty.kind {
match *ty.kind() {
ty::Closure(def_id, _) => Some((Self::Closure, def_id)),
ty::Opaque(def_id, _) => Some((Self::Opaque, def_id)),
ty::Generator(def_id, ..) => Some((Self::Generator, def_id)),

View file

@ -53,7 +53,7 @@ impl<'a, 'tcx> FindHirNodeVisitor<'a, 'tcx> {
inner == self.target
|| match (inner.unpack(), self.target.unpack()) {
(GenericArgKind::Type(inner_ty), GenericArgKind::Type(target_ty)) => {
match (&inner_ty.kind, &target_ty.kind) {
match (inner_ty.kind(), target_ty.kind()) {
(
&ty::Infer(ty::TyVar(a_vid)),
&ty::Infer(ty::TyVar(b_vid)),
@ -222,7 +222,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
ty: Ty<'tcx>,
highlight: Option<ty::print::RegionHighlightMode>,
) -> (String, Option<Span>, Cow<'static, str>, Option<String>, Option<&'static str>) {
if let ty::Infer(ty::TyVar(ty_vid)) = ty.kind {
if let ty::Infer(ty::TyVar(ty_vid)) = *ty.kind() {
let mut inner = self.inner.borrow_mut();
let ty_vars = &inner.type_variables();
let var_origin = ty_vars.var_origin(ty_vid);
@ -288,7 +288,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
None
};
printer.name_resolver = Some(Box::new(&getter));
let _ = if let ty::FnDef(..) = ty.kind {
let _ = if let ty::FnDef(..) = ty.kind() {
// We don't want the regular output for `fn`s because it includes its path in
// invalid pseudo-syntax, we want the `fn`-pointer output instead.
ty.fn_sig(self.tcx).print(printer)
@ -336,7 +336,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let ty_msg = match (local_visitor.found_node_ty, local_visitor.found_exact_method_call) {
(_, Some(_)) => String::new(),
(Some(ty::TyS { kind: ty::Closure(_, substs), .. }), _) => {
(Some(ty), _) if ty.is_closure() => {
let substs =
if let ty::Closure(_, substs) = *ty.kind() { substs } else { unreachable!() };
let fn_sig = substs.as_closure().sig();
let args = closure_args(&fn_sig);
let ret = fn_sig.output().skip_binder().to_string();
@ -370,7 +372,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
);
let suffix = match local_visitor.found_node_ty {
Some(ty::TyS { kind: ty::Closure(_, substs), .. }) => {
Some(ty) if ty.is_closure() => {
let substs =
if let ty::Closure(_, substs) = *ty.kind() { substs } else { unreachable!() };
let fn_sig = substs.as_closure().sig();
let ret = fn_sig.output().skip_binder().to_string();
@ -612,7 +616,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let bound_output = sig.output();
let output = bound_output.skip_binder();
err.span_label(e.span, &format!("this method call resolves to `{}`", output));
let kind = &output.kind;
let kind = output.kind();
if let ty::Projection(proj) = kind {
if let Some(span) = self.tcx.hir().span_if_local(proj.item_def_id) {
err.span_label(span, &format!("`{}` defined here", output));

View file

@ -465,7 +465,7 @@ struct TraitObjectVisitor(Vec<DefId>);
impl TypeVisitor<'_> for TraitObjectVisitor {
fn visit_ty(&mut self, t: Ty<'_>) -> bool {
match t.kind {
match t.kind() {
ty::Dynamic(preds, RegionKind::ReStatic) => {
if let Some(def_id) = preds.principal_def_id() {
self.0.push(def_id);

View file

@ -95,7 +95,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
decl: &hir::FnDecl<'_>,
) -> Option<Span> {
let ret_ty = self.tcx().type_of(scope_def_id);
if let ty::FnDef(_, _) = ret_ty.kind {
if let ty::FnDef(_, _) = ret_ty.kind() {
let sig = ret_ty.fn_sig(self.tcx());
let late_bound_regions =
self.tcx().collect_referenced_late_bound_regions(&sig.output());

View file

@ -144,7 +144,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
let tcx = self.infcx.tcx;
match t.kind {
match *t.kind() {
ty::Infer(ty::TyVar(v)) => {
let opt_ty = self.infcx.inner.borrow_mut().type_variables().probe(v).known();
self.freshen_ty(opt_ty, ty::TyVar(v), ty::FreshTy)

View file

@ -182,7 +182,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for InferenceFudger<'a, 'tcx> {
}
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
match ty.kind {
match *ty.kind() {
ty::Infer(ty::InferTy::TyVar(vid)) => {
if self.type_vars.0.contains(&vid) {
// This variable was created during the fudging.

View file

@ -58,7 +58,7 @@ where
let infcx = this.infcx();
let a = infcx.inner.borrow_mut().type_variables().replace_if_possible(a);
let b = infcx.inner.borrow_mut().type_variables().replace_if_possible(b);
match (&a.kind, &b.kind) {
match (a.kind(), b.kind()) {
// If one side is known to be a variable and one is not,
// create a variable (`v`) to represent the LUB. Make sure to
// relate `v` to the non-type-variable first (by passing it

View file

@ -680,7 +680,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
}
pub fn type_var_diverges(&'a self, ty: Ty<'_>) -> bool {
match ty.kind {
match *ty.kind() {
ty::Infer(ty::TyVar(vid)) => self.inner.borrow_mut().type_variables().var_diverges(vid),
_ => false,
}
@ -693,7 +693,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
pub fn type_is_unconstrained_numeric(&'a self, ty: Ty<'_>) -> UnconstrainedNumeric {
use rustc_middle::ty::error::UnconstrainedNumeric::Neither;
use rustc_middle::ty::error::UnconstrainedNumeric::{UnconstrainedFloat, UnconstrainedInt};
match ty.kind {
match *ty.kind() {
ty::Infer(ty::IntVar(vid)) => {
if self.inner.borrow_mut().int_unification_table().probe_value(vid).is_some() {
Neither
@ -1557,7 +1557,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
/// not a type variable, just return it unmodified.
// FIXME(eddyb) inline into `ShallowResolver::visit_ty`.
fn shallow_resolve_ty(&self, typ: Ty<'tcx>) -> Ty<'tcx> {
match typ.kind {
match *typ.kind() {
ty::Infer(ty::TyVar(v)) => {
// Not entirely obvious: if `typ` is a type variable,
// it can be resolved to an int/float variable, which
@ -1677,7 +1677,7 @@ impl TyOrConstInferVar<'tcx> {
/// Tries to extract an inference variable from a type, returns `None`
/// for types other than `ty::Infer(_)` (or `InferTy::Fresh*`).
pub fn maybe_from_ty(ty: Ty<'tcx>) -> Option<Self> {
match ty.kind {
match *ty.kind() {
ty::Infer(ty::TyVar(v)) => Some(TyOrConstInferVar::Ty(v)),
ty::Infer(ty::IntVar(v)) => Some(TyOrConstInferVar::TyInt(v)),
ty::Infer(ty::FloatVar(v)) => Some(TyOrConstInferVar::TyFloat(v)),

View file

@ -265,7 +265,7 @@ where
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use rustc_span::DUMMY_SP;
match value_ty.kind {
match *value_ty.kind() {
ty::Projection(other_projection_ty) => {
let var = self.infcx.next_ty_var(TypeVariableOrigin {
kind: TypeVariableOriginKind::MiscVariable,
@ -311,7 +311,7 @@ where
// This only presently applies to chalk integration, as NLL
// doesn't permit type variables to appear on both sides (and
// doesn't use lazy norm).
match value_ty.kind {
match *value_ty.kind() {
ty::Infer(ty::TyVar(value_vid)) => {
// Two type variables: just equate them.
self.infcx.inner.borrow_mut().type_variables().equate(vid, value_vid);
@ -531,7 +531,7 @@ where
}
}
match (&a.kind, &b.kind) {
match (a.kind(), b.kind()) {
(_, &ty::Infer(ty::TyVar(vid))) => {
if D::forbid_inference_vars() {
// Forbid inference variables in the RHS.
@ -868,7 +868,7 @@ where
debug!("TypeGeneralizer::tys(a={:?})", a);
match a.kind {
match *a.kind() {
ty::Infer(ty::TyVar(_)) | ty::Infer(ty::IntVar(_)) | ty::Infer(ty::FloatVar(_))
if D::forbid_inference_vars() =>
{

View file

@ -383,7 +383,7 @@ where
// #55756) in cases where you have e.g., `<T as Foo<'a>>::Item:
// 'a` in the environment but `trait Foo<'b> { type Item: 'b
// }` in the trait definition.
approx_env_bounds.retain(|bound| match bound.0.kind {
approx_env_bounds.retain(|bound| match *bound.0.kind() {
ty::Projection(projection_ty) => self
.verify_bound
.projection_declared_bounds_from_trait(projection_ty)

View file

@ -38,7 +38,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
}
fn type_bound(&self, ty: Ty<'tcx>) -> VerifyBound<'tcx> {
match ty.kind {
match *ty.kind() {
ty::Param(p) => self.param_bound(p),
ty::Projection(data) => self.projection_bound(data),
ty::FnDef(_, substs) => {
@ -118,7 +118,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
let projection_ty = GenericKind::Projection(projection_ty).to_ty(self.tcx);
let erased_projection_ty = self.tcx.erase_regions(&projection_ty);
self.declared_generic_bounds_from_env_with_compare_fn(|ty| {
if let ty::Projection(..) = ty.kind {
if let ty::Projection(..) = ty.kind() {
let erased_ty = self.tcx.erase_regions(&ty);
erased_ty == erased_projection_ty
} else {

View file

@ -124,7 +124,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for UnresolvedTypeFinder<'a, 'tcx> {
fn visit_ty(&mut self, t: Ty<'tcx>) -> bool {
let t = self.infcx.shallow_resolve(t);
if t.has_infer_types() {
if let ty::Infer(infer_ty) = t.kind {
if let ty::Infer(infer_ty) = *t.kind() {
// Since we called `shallow_resolve` above, this must
// be an (as yet...) unresolved inference variable.
let ty_var_span = if let ty::TyVar(ty_vid) = infer_ty {
@ -191,7 +191,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for FullTypeResolver<'a, 'tcx> {
t // micro-optimize -- if there is nothing in this type that this fold affects...
} else {
let t = self.infcx.shallow_resolve(t);
match t.kind {
match *t.kind() {
ty::Infer(ty::TyVar(vid)) => {
self.err = Some(FixupError::UnresolvedTy(vid));
self.tcx().ty_error()

View file

@ -83,7 +83,7 @@ impl TypeRelation<'tcx> for Sub<'combine, 'infcx, 'tcx> {
let infcx = self.fields.infcx;
let a = infcx.inner.borrow_mut().type_variables().replace_if_possible(a);
let b = infcx.inner.borrow_mut().type_variables().replace_if_possible(b);
match (&a.kind, &b.kind) {
match (a.kind(), b.kind()) {
(&ty::Infer(TyVar(a_vid)), &ty::Infer(TyVar(b_vid))) => {
// Shouldn't have any LBR here, so we can safely put
// this under a binder below without fear of accidental

View file

@ -306,7 +306,7 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
/// instantiated, then return the with which it was
/// instantiated. Otherwise, returns `t`.
pub fn replace_if_possible(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
match t.kind {
match *t.kind() {
ty::Infer(ty::TyVar(v)) => match self.probe(v) {
TypeVariableValue::Unknown { .. } => t,
TypeVariableValue::Known { value } => value,