Skip to content

Commit ce11ae5

Browse files
Address some more nits
1 parent d793d80 commit ce11ae5

File tree

3 files changed

+26
-29
lines changed

3 files changed

+26
-29
lines changed

compiler/rustc_hir_analysis/src/check/compare_method.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,7 @@ fn compare_predicate_entailment<'tcx>(
290290
// type would be more appropriate. In other places we have a `Vec<Span>`
291291
// corresponding to their `Vec<Predicate>`, but we don't have that here.
292292
// Fixing this would improve the output of test `issue-83765.rs`.
293-
let mut result = infcx
294-
.at(&cause, param_env)
295-
.sup(trait_fty, impl_fty)
296-
.map(|infer_ok| ocx.register_infer_ok_obligations(infer_ok));
293+
let mut result = ocx.sup_types(&cause, param_env, trait_fty, impl_fty);
297294

298295
// HACK(RPITIT): #101614. When we are trying to infer the hidden types for
299296
// RPITITs, we need to equate the output tys instead of just subtyping. If
@@ -302,10 +299,7 @@ fn compare_predicate_entailment<'tcx>(
302299
// fixed up to `ReEmpty`, and which is certainly not what we want.
303300
if trait_fty.has_infer_types() {
304301
result = result.and_then(|()| {
305-
infcx
306-
.at(&cause, param_env)
307-
.eq(trait_sig.output(), impl_sig.output())
308-
.map(|infer_ok| ocx.register_infer_ok_obligations(infer_ok))
302+
ocx.equate_types(&cause, param_env, trait_sig.output(), impl_sig.output())
309303
});
310304
}
311305

@@ -1389,10 +1383,7 @@ pub(crate) fn raw_compare_const_impl<'tcx>(
13891383

13901384
debug!("compare_const_impl: trait_ty={:?}", trait_ty);
13911385

1392-
let err = infcx
1393-
.at(&cause, param_env)
1394-
.sup(trait_ty, impl_ty)
1395-
.map(|ok| ocx.register_infer_ok_obligations(ok));
1386+
let err = ocx.sup_types(&cause, param_env, trait_ty, impl_ty);
13961387

13971388
if let Err(terr) = err {
13981389
debug!(

compiler/rustc_trait_selection/src/traits/engine.rs

+20-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use super::{ChalkFulfillmentContext, FulfillmentContext};
66
use crate::infer::InferCtxtExt;
77
use rustc_data_structures::fx::FxHashSet;
88
use rustc_hir::def_id::{DefId, LocalDefId};
9+
use rustc_infer::infer::at::ToTrace;
910
use rustc_infer::infer::canonical::{
1011
Canonical, CanonicalVarValues, CanonicalizedQueryResponse, QueryResponse,
1112
};
@@ -111,12 +112,12 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
111112
self.register_infer_ok_obligations(infer_ok)
112113
}
113114

114-
pub fn equate_types(
115+
pub fn equate_types<T: ToTrace<'tcx>>(
115116
&self,
116117
cause: &ObligationCause<'tcx>,
117118
param_env: ty::ParamEnv<'tcx>,
118-
expected: Ty<'tcx>,
119-
actual: Ty<'tcx>,
119+
expected: T,
120+
actual: T,
120121
) -> Result<(), TypeError<'tcx>> {
121122
match self.infcx.at(cause, param_env).eq(expected, actual) {
122123
Ok(InferOk { obligations, value: () }) => {
@@ -127,6 +128,22 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
127128
}
128129
}
129130

131+
pub fn sup_types<T: ToTrace<'tcx>>(
132+
&self,
133+
cause: &ObligationCause<'tcx>,
134+
param_env: ty::ParamEnv<'tcx>,
135+
expected: T,
136+
actual: T,
137+
) -> Result<(), TypeError<'tcx>> {
138+
match self.infcx.at(cause, param_env).sup(expected, actual) {
139+
Ok(InferOk { obligations, value: () }) => {
140+
self.register_obligations(obligations);
141+
Ok(())
142+
}
143+
Err(e) => Err(e),
144+
}
145+
}
146+
130147
pub fn select_all_or_error(&self) -> Vec<FulfillmentError<'tcx>> {
131148
self.engine.borrow_mut().select_all_or_error(self.infcx)
132149
}

compiler/rustc_traits/src/type_op.rs

+3-14
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,7 @@ impl<'me, 'tcx> AscribeUserTypeCx<'me, 'tcx> {
8787
where
8888
T: ToTrace<'tcx>,
8989
{
90-
Ok(self.ocx.register_infer_ok_obligations(
91-
self.ocx
92-
.infcx
93-
.at(&ObligationCause::dummy_with_span(self.span), self.param_env)
94-
.eq(a, b)?,
95-
))
90+
Ok(self.ocx.equate_types(&ObligationCause::dummy_with_span(self.span), self.param_env, a, b)?)
9691
}
9792

9893
fn prove_predicate(&self, predicate: Predicate<'tcx>, cause: ObligationCause<'tcx>) {
@@ -181,10 +176,7 @@ fn type_op_eq<'tcx>(
181176
) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, ()>>, NoSolution> {
182177
tcx.infer_ctxt().enter_canonical_trait_query(&canonicalized, |ocx, key| {
183178
let (param_env, Eq { a, b }) = key.into_parts();
184-
ocx.register_infer_ok_obligations(
185-
ocx.infcx.at(&ObligationCause::dummy(), param_env).eq(a, b)?,
186-
);
187-
Ok(())
179+
Ok(ocx.equate_types(&ObligationCause::dummy(), param_env, a, b)?)
188180
})
189181
}
190182

@@ -236,10 +228,7 @@ fn type_op_subtype<'tcx>(
236228
) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, ()>>, NoSolution> {
237229
tcx.infer_ctxt().enter_canonical_trait_query(&canonicalized, |ocx, key| {
238230
let (param_env, Subtype { sub, sup }) = key.into_parts();
239-
ocx.register_infer_ok_obligations(
240-
ocx.infcx.at(&ObligationCause::dummy(), param_env).sup(sup, sub)?,
241-
);
242-
Ok(())
231+
Ok(ocx.sup_types(&ObligationCause::dummy(), param_env, sup, sub)?)
243232
})
244233
}
245234

0 commit comments

Comments
 (0)