Skip to content

Commit a391d54

Browse files
authored
Rollup merge of #92022 - woodenarrow:br_expected_bool, r=estebank
Eliminate duplicate codes of expected_found_bool The function expected_found_bool is the same as ExpectedFound::new. So use ExpectedFound::new to replace expected_found_bool to eliminate duplicate codes. ![image](https://user-images.githubusercontent.com/95843988/146486722-c910eccd-a36c-4dc5-8b36-214aab058e38.png)
2 parents fedb525 + a995462 commit a391d54

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
@@ -836,13 +836,5 @@ pub fn expected_found<R, T>(relation: &mut R, a: T, b: T) -> ExpectedFound<T>
836836
where
837837
R: TypeRelation<'tcx>,
838838
{
839-
expected_found_bool(relation.a_is_expected(), a, b)
840-
}
841-
842-
pub fn expected_found_bool<T>(a_is_expected: bool, a: T, b: T) -> ExpectedFound<T> {
843-
if a_is_expected {
844-
ExpectedFound { expected: a, found: b }
845-
} else {
846-
ExpectedFound { expected: b, found: a }
847-
}
839+
ExpectedFound::new(relation.a_is_expected(), a, b)
848840
}

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;
@@ -1493,7 +1493,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14931493
&self.misc(base_expr.span),
14941494
adt_ty,
14951495
base_ty,
1496-
Sorts(expected_found_bool(true, adt_ty, base_ty)),
1496+
Sorts(ExpectedFound::new(true, adt_ty, base_ty)),
14971497
)
14981498
.emit();
14991499
}

0 commit comments

Comments
 (0)