Skip to content

Commit a995462

Browse files
committed
Eliminate duplicate codes of expected_found_bool
1 parent 0b42dea commit a995462

File tree

3 files changed

+7
-15
lines changed

3 files changed

+7
-15
lines changed

compiler/rustc_infer/src/infer/combine.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use crate::traits::{Obligation, PredicateObligations};
3737
use rustc_data_structures::sso::SsoHashMap;
3838
use rustc_hir::def_id::DefId;
3939
use rustc_middle::traits::ObligationCause;
40-
use rustc_middle::ty::error::TypeError;
40+
use rustc_middle::ty::error::{ExpectedFound, TypeError};
4141
use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation};
4242
use rustc_middle::ty::subst::SubstsRef;
4343
use rustc_middle::ty::{self, InferConst, ToPredicate, Ty, TyCtxt, TypeFoldable};
@@ -790,23 +790,23 @@ pub fn const_unification_error<'tcx>(
790790
a_is_expected: bool,
791791
(a, b): (&'tcx ty::Const<'tcx>, &'tcx ty::Const<'tcx>),
792792
) -> TypeError<'tcx> {
793-
TypeError::ConstMismatch(ty::relate::expected_found_bool(a_is_expected, a, b))
793+
TypeError::ConstMismatch(ExpectedFound::new(a_is_expected, a, b))
794794
}
795795

796796
fn int_unification_error<'tcx>(
797797
a_is_expected: bool,
798798
v: (ty::IntVarValue, ty::IntVarValue),
799799
) -> TypeError<'tcx> {
800800
let (a, b) = v;
801-
TypeError::IntMismatch(ty::relate::expected_found_bool(a_is_expected, a, b))
801+
TypeError::IntMismatch(ExpectedFound::new(a_is_expected, a, b))
802802
}
803803

804804
fn float_unification_error<'tcx>(
805805
a_is_expected: bool,
806806
v: (ty::FloatVarValue, ty::FloatVarValue),
807807
) -> TypeError<'tcx> {
808808
let (ty::FloatVarValue(a), ty::FloatVarValue(b)) = v;
809-
TypeError::FloatMismatch(ty::relate::expected_found_bool(a_is_expected, a, b))
809+
TypeError::FloatMismatch(ExpectedFound::new(a_is_expected, a, b))
810810
}
811811

812812
struct ConstInferUnifier<'cx, 'tcx> {

compiler/rustc_middle/src/ty/relate.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -849,13 +849,5 @@ pub fn expected_found<R, T>(relation: &mut R, a: T, b: T) -> ExpectedFound<T>
849849
where
850850
R: TypeRelation<'tcx>,
851851
{
852-
expected_found_bool(relation.a_is_expected(), a, b)
853-
}
854-
855-
pub fn expected_found_bool<T>(a_is_expected: bool, a: T, b: T) -> ExpectedFound<T> {
856-
if a_is_expected {
857-
ExpectedFound { expected: a, found: b }
858-
} else {
859-
ExpectedFound { expected: b, found: a }
860-
}
852+
ExpectedFound::new(relation.a_is_expected(), a, b)
861853
}

compiler/rustc_typeck/src/check/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ use rustc_infer::infer;
3636
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
3737
use rustc_infer::infer::InferOk;
3838
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase};
39+
use rustc_middle::ty::error::ExpectedFound;
3940
use rustc_middle::ty::error::TypeError::{FieldMisMatch, Sorts};
40-
use rustc_middle::ty::relate::expected_found_bool;
4141
use rustc_middle::ty::subst::SubstsRef;
4242
use rustc_middle::ty::{self, AdtKind, Ty, TypeFoldable};
4343
use rustc_session::parse::feature_err;
@@ -1494,7 +1494,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14941494
&self.misc(base_expr.span),
14951495
adt_ty,
14961496
base_ty,
1497-
Sorts(expected_found_bool(true, adt_ty, base_ty)),
1497+
Sorts(ExpectedFound::new(true, adt_ty, base_ty)),
14981498
)
14991499
.emit();
15001500
}

0 commit comments

Comments
 (0)