From 801dd1d061bc6db31547d45c64a32bbd9b4f6124 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 26 Feb 2024 15:58:53 +0000 Subject: [PATCH] Remove cause --- compiler/rustc_infer/src/infer/mod.rs | 1 - .../rustc_infer/src/infer/relate/combine.rs | 1 - .../src/infer/relate/type_relating.rs | 24 ++----------------- compiler/rustc_middle/src/ty/relate.rs | 17 +++++-------- 4 files changed, 8 insertions(+), 35 deletions(-) diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index 6f52ded3551..b99ea35c22c 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -836,7 +836,6 @@ impl<'tcx> InferCtxt<'tcx> { CombineFields { infcx: self, trace, - cause: None, param_env, obligations: PredicateObligations::new(), define_opaque_types, diff --git a/compiler/rustc_infer/src/infer/relate/combine.rs b/compiler/rustc_infer/src/infer/relate/combine.rs index 0a550660f94..749c50b57b5 100644 --- a/compiler/rustc_infer/src/infer/relate/combine.rs +++ b/compiler/rustc_infer/src/infer/relate/combine.rs @@ -42,7 +42,6 @@ use rustc_span::Span; pub struct CombineFields<'infcx, 'tcx> { pub infcx: &'infcx InferCtxt<'tcx>, pub trace: TypeTrace<'tcx>, - pub cause: Option, pub param_env: ty::ParamEnv<'tcx>, pub obligations: PredicateObligations<'tcx>, pub define_opaque_types: DefineOpaqueTypes, diff --git a/compiler/rustc_infer/src/infer/relate/type_relating.rs b/compiler/rustc_infer/src/infer/relate/type_relating.rs index c4de324e6ff..ddc4bf9a514 100644 --- a/compiler/rustc_infer/src/infer/relate/type_relating.rs +++ b/compiler/rustc_infer/src/infer/relate/type_relating.rs @@ -4,12 +4,10 @@ use crate::infer::{ }; use crate::traits::{Obligation, PredicateObligations}; -use rustc_middle::ty::relate::{Cause, Relate, RelateResult, TypeRelation}; -use rustc_middle::ty::visit::TypeVisitableExt; +use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation}; use rustc_middle::ty::TyVar; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_span::Span; -use std::mem; /// Enforce that `a` is equal to or a subtype of `b`. pub struct TypeRelating<'combine, 'a, 'tcx> { @@ -43,18 +41,6 @@ impl<'tcx> TypeRelation<'tcx> for TypeRelating<'_, '_, 'tcx> { self.a_is_expected } - fn with_cause(&mut self, cause: Cause, f: F) -> R - where - F: FnOnce(&mut Self) -> R, - { - debug!("sub with_cause={:?}", cause); - let old_cause = mem::replace(&mut self.fields.cause, Some(cause)); - let r = f(self); - debug!("sub old_cause={:?}", old_cause); - self.fields.cause = old_cause; - r - } - fn relate_with_variance>( &mut self, variance: ty::Variance, @@ -84,12 +70,6 @@ impl<'tcx> TypeRelation<'tcx> for TypeRelating<'_, '_, 'tcx> { match (a.kind(), b.kind()) { (&ty::Infer(TyVar(a_id)), &ty::Infer(TyVar(b_id))) => { - // Shouldn't have any LBR here, so we can safely put - // this under a binder below without fear of accidental - // capture. - assert!(!a.has_escaping_bound_vars()); - assert!(!b.has_escaping_bound_vars()); - match self.ambient_variance { ty::Covariant => { // can't make progress on `A <: B` if both A and B are @@ -191,7 +171,7 @@ impl<'tcx> TypeRelation<'tcx> for TypeRelating<'_, '_, 'tcx> { a: ty::Region<'tcx>, b: ty::Region<'tcx>, ) -> RelateResult<'tcx, ty::Region<'tcx>> { - debug!("{}.regions({:?}, {:?}) self.cause={:?}", self.tag(), a, b, self.fields.cause); + debug!("{}.regions({:?}, {:?})", self.tag(), a, b); // FIXME -- we have more fine-grained information available // from the "cause" field, we could perhaps give more tailored diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index 303f285b00c..abd39914cfd 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -30,13 +30,6 @@ pub trait TypeRelation<'tcx>: Sized { /// relation. Just affects error messages. fn a_is_expected(&self) -> bool; - fn with_cause(&mut self, _cause: Cause, f: F) -> R - where - F: FnOnce(&mut Self) -> R, - { - f(self) - } - /// Generic relation routine suitable for most anything. fn relate>(&mut self, a: T, b: T) -> RelateResult<'tcx, T> { Relate::relate(self, a, b) @@ -452,10 +445,12 @@ pub fn structurally_relate_tys<'tcx, R: TypeRelation<'tcx>>( (&ty::Dynamic(a_obj, a_region, a_repr), &ty::Dynamic(b_obj, b_region, b_repr)) if a_repr == b_repr => { - let region_bound = relation.with_cause(Cause::ExistentialRegionBound, |relation| { - relation.relate(a_region, b_region) - })?; - Ok(Ty::new_dynamic(tcx, relation.relate(a_obj, b_obj)?, region_bound, a_repr)) + Ok(Ty::new_dynamic( + tcx, + relation.relate(a_obj, b_obj)?, + relation.relate(a_region, b_region)?, + a_repr, + )) } (&ty::Coroutine(a_id, a_args), &ty::Coroutine(b_id, b_args)) if a_id == b_id => {