@@ -44,6 +44,7 @@ use rustc_hir::def_id::DefId;
44
44
use rustc_hir:: intravisit:: { self , Visitor } ;
45
45
use rustc_hir:: Expr ;
46
46
use rustc_hir_analysis:: astconv:: AstConv ;
47
+ use rustc_infer:: infer:: at:: At ;
47
48
use rustc_infer:: infer:: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
48
49
use rustc_infer:: infer:: { Coercion , DefiningAnchor , InferOk , InferResult } ;
49
50
use rustc_infer:: traits:: Obligation ;
@@ -140,12 +141,14 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
140
141
Coerce { fcx, cause, allow_two_phase, use_lub : false }
141
142
}
142
143
144
+ pub fn at ( & self ) -> At < ' _ , ' tcx > {
145
+ self . infcx . at ( & self . cause , self . param_env )
146
+ }
147
+
143
148
fn unify ( & self , a : Ty < ' tcx > , b : Ty < ' tcx > ) -> InferResult < ' tcx , Ty < ' tcx > > {
144
149
debug ! ( "unify(a: {:?}, b: {:?}, use_lub: {})" , a, b, self . use_lub) ;
145
150
self . commit_if_ok ( |_| {
146
- let at = self
147
- . at ( & self . cause , self . fcx . param_env )
148
- . define_opaque_types ( self . defining_use_anchor ( ) ) ;
151
+ let at = self . at ( ) . define_opaque_types ( self . defining_use_anchor ( ) ) ;
149
152
if self . use_lub {
150
153
at. lub ( b, a)
151
154
} else {
@@ -177,9 +180,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
177
180
// so this will have the side-effect of making sure we have no ambiguities
178
181
// due to `[type error]` and `_` not coercing together.
179
182
let _ = self . commit_if_ok ( |_| {
180
- self . at ( & self . cause , self . param_env )
181
- . define_opaque_types ( self . defining_use_anchor ( ) )
182
- . eq ( a, b)
183
+ self . at ( ) . define_opaque_types ( self . defining_use_anchor ( ) ) . eq ( a, b)
183
184
} ) ;
184
185
return success ( vec ! [ ] , self . fcx . tcx . ty_error ( guar) , vec ! [ ] ) ;
185
186
}
@@ -843,8 +844,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
843
844
//! into a closure or a `proc`.
844
845
845
846
let b = self . shallow_resolve ( b) ;
846
- let InferOk { value : b, mut obligations } =
847
- self . at ( & self . cause , self . param_env ) . normalize ( b) ;
847
+ let InferOk { value : b, mut obligations } = self . at ( ) . normalize ( b) ;
848
848
debug ! ( "coerce_from_fn_item(a={:?}, b={:?})" , a, b) ;
849
849
850
850
match b. kind ( ) {
@@ -865,8 +865,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
865
865
}
866
866
}
867
867
868
- let InferOk { value : a_sig, obligations : o1 } =
869
- self . at ( & self . cause , self . param_env ) . normalize ( a_sig) ;
868
+ let InferOk { value : a_sig, obligations : o1 } = self . at ( ) . normalize ( a_sig) ;
870
869
obligations. extend ( o1) ;
871
870
872
871
let a_fn_pointer = self . tcx . mk_fn_ptr ( a_sig) ;
@@ -1105,9 +1104,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1105
1104
( ty:: FnDef ( ..) , ty:: FnDef ( ..) ) => {
1106
1105
// Don't reify if the function types have a LUB, i.e., they
1107
1106
// are the same function and their parameters have a LUB.
1108
- match self
1109
- . commit_if_ok ( |_| self . at ( cause, self . param_env ) . lub ( prev_ty, new_ty) )
1110
- {
1107
+ match self . commit_if_ok ( |_| self . at ( cause) . lub ( prev_ty, new_ty) ) {
1111
1108
// We have a LUB of prev_ty and new_ty, just return it.
1112
1109
Ok ( ok) => return Ok ( self . register_infer_ok_obligations ( ok) ) ,
1113
1110
Err ( _) => {
@@ -1155,7 +1152,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1155
1152
// The signature must match.
1156
1153
let ( a_sig, b_sig) = self . normalize ( new. span , ( a_sig, b_sig) ) ;
1157
1154
let sig = self
1158
- . at ( cause, self . param_env )
1155
+ . at ( cause)
1159
1156
. trace ( prev_ty, new_ty)
1160
1157
. lub ( a_sig, b_sig)
1161
1158
. map ( |ok| self . register_infer_ok_obligations ( ok) ) ?;
@@ -1241,7 +1238,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1241
1238
) ;
1242
1239
1243
1240
return self
1244
- . commit_if_ok ( |_| self . at ( cause, self . param_env ) . lub ( prev_ty, new_ty) )
1241
+ . commit_if_ok ( |_| self . at ( cause) . lub ( prev_ty, new_ty) )
1245
1242
. map ( |ok| self . register_infer_ok_obligations ( ok) ) ;
1246
1243
}
1247
1244
}
@@ -1252,7 +1249,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1252
1249
if let Some ( e) = first_error {
1253
1250
Err ( e)
1254
1251
} else {
1255
- self . commit_if_ok ( |_| self . at ( cause, self . param_env ) . lub ( prev_ty, new_ty) )
1252
+ self . commit_if_ok ( |_| self . at ( cause) . lub ( prev_ty, new_ty) )
1256
1253
. map ( |ok| self . register_infer_ok_obligations ( ok) )
1257
1254
}
1258
1255
}
@@ -1489,7 +1486,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
1489
1486
//
1490
1487
// Another example is `break` with no argument expression.
1491
1488
assert ! ( expression_ty. is_unit( ) , "if let hack without unit type" ) ;
1492
- fcx. at ( cause, fcx . param_env )
1489
+ fcx. at ( cause)
1493
1490
// needed for tests/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs
1494
1491
. define_opaque_types ( fcx. defining_use_anchor ( ) )
1495
1492
. eq_exp ( label_expression_as_expected, expression_ty, self . merged_ty ( ) )
0 commit comments