Skip to content

Commit

Permalink
Remove cause
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Mar 1, 2024
1 parent c87b727 commit 801dd1d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 35 deletions.
1 change: 0 additions & 1 deletion compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,6 @@ impl<'tcx> InferCtxt<'tcx> {
CombineFields {
infcx: self,
trace,
cause: None,
param_env,
obligations: PredicateObligations::new(),
define_opaque_types,
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_infer/src/infer/relate/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ty::relate::Cause>,
pub param_env: ty::ParamEnv<'tcx>,
pub obligations: PredicateObligations<'tcx>,
pub define_opaque_types: DefineOpaqueTypes,
Expand Down
24 changes: 2 additions & 22 deletions compiler/rustc_infer/src/infer/relate/type_relating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -43,18 +41,6 @@ impl<'tcx> TypeRelation<'tcx> for TypeRelating<'_, '_, 'tcx> {
self.a_is_expected
}

fn with_cause<F, R>(&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<T: Relate<'tcx>>(
&mut self,
variance: ty::Variance,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
17 changes: 6 additions & 11 deletions compiler/rustc_middle/src/ty/relate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ pub trait TypeRelation<'tcx>: Sized {
/// relation. Just affects error messages.
fn a_is_expected(&self) -> bool;

fn with_cause<F, R>(&mut self, _cause: Cause, f: F) -> R
where
F: FnOnce(&mut Self) -> R,
{
f(self)
}

/// Generic relation routine suitable for most anything.
fn relate<T: Relate<'tcx>>(&mut self, a: T, b: T) -> RelateResult<'tcx, T> {
Relate::relate(self, a, b)
Expand Down Expand Up @@ -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 => {
Expand Down

0 comments on commit 801dd1d

Please sign in to comment.