Skip to content

Commit 2744c0e

Browse files
authored
Rollup merge of #99615 - compiler-errors:remove-some-explicit-infcx, r=lcnr
Remove some explicit `self.infcx` for `FnCtxt`, which already derefs into `InferCtxt` The use of `self.infcx.method_on_infcx` vs `self.method_on_infcx` when `self` is a `FnCtxt` is a bit inconsistent, so I'm moving some `self.infcx` usages I found to just use autoderef
2 parents d89e99a + aaa9989 commit 2744c0e

File tree

14 files changed

+68
-77
lines changed

14 files changed

+68
-77
lines changed

compiler/rustc_typeck/src/check/_match.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -488,17 +488,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
488488
ty::Binder::dummy(ty::PredicateKind::Trait(ty::TraitPredicate {
489489
trait_ref: ty::TraitRef {
490490
def_id: t.def_id(),
491-
substs: self.infcx.tcx.mk_substs_trait(outer_ty, &[]),
491+
substs: self.tcx.mk_substs_trait(outer_ty, &[]),
492492
},
493493
constness: t.constness,
494494
polarity: t.polarity,
495495
}));
496496
let obl = Obligation::new(
497497
o.cause.clone(),
498498
self.param_env,
499-
pred.to_predicate(self.infcx.tcx),
499+
pred.to_predicate(self.tcx),
500500
);
501-
suggest_box &= self.infcx.predicate_must_hold_modulo_regions(&obl);
501+
suggest_box &= self.predicate_must_hold_modulo_regions(&obl);
502502
if !suggest_box {
503503
// We've encountered some obligation that didn't hold, so the
504504
// return expression can't just be boxed. We don't need to

compiler/rustc_typeck/src/check/callee.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
376376
self.param_env,
377377
*predicate,
378378
);
379-
let result = self.infcx.evaluate_obligation(&obligation);
379+
let result = self.evaluate_obligation(&obligation);
380380
self.tcx
381381
.sess
382382
.struct_span_err(

compiler/rustc_typeck/src/check/closure.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
9696
self.tcx.typeck_root_def_id(expr_def_id.to_def_id()),
9797
);
9898

99-
let tupled_upvars_ty = self.infcx.next_ty_var(TypeVariableOrigin {
99+
let tupled_upvars_ty = self.next_ty_var(TypeVariableOrigin {
100100
kind: TypeVariableOriginKind::ClosureSynthetic,
101101
span: self.tcx.hir().span(expr.hir_id),
102102
});
@@ -141,7 +141,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
141141

142142
// Create a type variable (for now) to represent the closure kind.
143143
// It will be unified during the upvar inference phase (`upvar.rs`)
144-
None => self.infcx.next_ty_var(TypeVariableOrigin {
144+
None => self.next_ty_var(TypeVariableOrigin {
145145
// FIXME(eddyb) distinguish closure kind inference variables from the rest.
146146
kind: TypeVariableOriginKind::ClosureSynthetic,
147147
span: expr.span,
@@ -531,7 +531,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
531531
//
532532
// [c1]: https://github.com/rust-lang/rust/pull/45072#issuecomment-341089706
533533
// [c2]: https://github.com/rust-lang/rust/pull/45072#issuecomment-341096796
534-
self.infcx.commit_if_ok(|_| {
534+
self.commit_if_ok(|_| {
535535
let mut all_obligations = vec![];
536536

537537
// The liberated version of this signature should be a subtype
@@ -544,7 +544,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
544544
expected_sigs.liberated_sig.inputs(), // `liberated_sig` is E'.
545545
) {
546546
// Instantiate (this part of..) S to S', i.e., with fresh variables.
547-
let supplied_ty = self.infcx.replace_bound_vars_with_fresh_vars(
547+
let supplied_ty = self.replace_bound_vars_with_fresh_vars(
548548
hir_ty.span,
549549
LateBoundRegionConversionTime::FnCall,
550550
supplied_sig.inputs().rebind(supplied_ty),
@@ -557,7 +557,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
557557
all_obligations.extend(obligations);
558558
}
559559

560-
let supplied_output_ty = self.infcx.replace_bound_vars_with_fresh_vars(
560+
let supplied_output_ty = self.replace_bound_vars_with_fresh_vars(
561561
decl.output.span(),
562562
LateBoundRegionConversionTime::FnCall,
563563
supplied_sig.output(),

compiler/rustc_typeck/src/check/coercion.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,13 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
241241
make_adjustments: impl FnOnce(Ty<'tcx>) -> Vec<Adjustment<'tcx>>,
242242
) -> CoerceResult<'tcx> {
243243
debug!("coerce_from_inference_variable(a={:?}, b={:?})", a, b);
244-
assert!(a.is_ty_var() && self.infcx.shallow_resolve(a) == a);
245-
assert!(self.infcx.shallow_resolve(b) == b);
244+
assert!(a.is_ty_var() && self.shallow_resolve(a) == a);
245+
assert!(self.shallow_resolve(b) == b);
246246

247247
if b.is_ty_var() {
248248
// Two unresolved type variables: create a `Coerce` predicate.
249249
let target_ty = if self.use_lub {
250-
self.infcx.next_ty_var(TypeVariableOrigin {
250+
self.next_ty_var(TypeVariableOrigin {
251251
kind: TypeVariableOriginKind::LatticeVariable,
252252
span: self.cause.span,
253253
})
@@ -991,7 +991,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
991991
self.autoderef(rustc_span::DUMMY_SP, expr_ty).nth(1).and_then(|(deref_ty, _)| {
992992
self.infcx
993993
.type_implements_trait(
994-
self.infcx.tcx.lang_items().deref_mut_trait()?,
994+
self.tcx.lang_items().deref_mut_trait()?,
995995
expr_ty,
996996
ty::List::empty(),
997997
self.param_env,

compiler/rustc_typeck/src/check/demand.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
830830
hir::ExprKind::AddrOf(hir::BorrowKind::Ref, _, ref expr),
831831
_,
832832
&ty::Ref(_, checked, _),
833-
) if self.infcx.can_sub(self.param_env, checked, expected).is_ok() => {
833+
) if self.can_sub(self.param_env, checked, expected).is_ok() => {
834834
// We have `&T`, check if what was expected was `T`. If so,
835835
// we may want to suggest removing a `&`.
836836
if sm.is_imported(expr.span) {
@@ -974,7 +974,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
974974

975975
// For this suggestion to make sense, the type would need to be `Copy`,
976976
// or we have to be moving out of a `Box<T>`
977-
if self.infcx.type_is_copy_modulo_regions(self.param_env, expected, sp)
977+
if self.type_is_copy_modulo_regions(self.param_env, expected, sp)
978978
// FIXME(compiler-errors): We can actually do this if the checked_ty is
979979
// `steps` layers of boxes, not just one, but this is easier and most likely.
980980
|| (checked_ty.is_box() && steps == 1)

compiler/rustc_typeck/src/check/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2235,7 +2235,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22352235
base: &'tcx hir::Expr<'tcx>,
22362236
ty: Ty<'tcx>,
22372237
) {
2238-
let output_ty = match self.infcx.get_impl_future_output_ty(ty) {
2238+
let output_ty = match self.get_impl_future_output_ty(ty) {
22392239
Some(output_ty) => self.resolve_vars_if_possible(output_ty),
22402240
_ => return,
22412241
};

compiler/rustc_typeck/src/check/fallback.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
218218
.diverging_type_vars
219219
.borrow()
220220
.iter()
221-
.map(|&ty| self.infcx.shallow_resolve(ty))
221+
.map(|&ty| self.shallow_resolve(ty))
222222
.filter_map(|ty| ty.ty_vid())
223-
.map(|vid| self.infcx.root_var(vid))
223+
.map(|vid| self.root_var(vid))
224224
.collect();
225225
debug!(
226226
"calculate_diverging_fallback: diverging_type_vars={:?}",
@@ -236,7 +236,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
236236
let mut diverging_vids = vec![];
237237
let mut non_diverging_vids = vec![];
238238
for unsolved_vid in unsolved_vids {
239-
let root_vid = self.infcx.root_var(unsolved_vid);
239+
let root_vid = self.root_var(unsolved_vid);
240240
debug!(
241241
"calculate_diverging_fallback: unsolved_vid={:?} root_vid={:?} diverges={:?}",
242242
unsolved_vid,
@@ -271,7 +271,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
271271
// variables. (Note that this set consists of "root variables".)
272272
let mut roots_reachable_from_non_diverging = DepthFirstSearch::new(&coercion_graph);
273273
for &non_diverging_vid in &non_diverging_vids {
274-
let root_vid = self.infcx.root_var(non_diverging_vid);
274+
let root_vid = self.root_var(non_diverging_vid);
275275
if roots_reachable_from_diverging.visited(root_vid) {
276276
continue;
277277
}
@@ -294,15 +294,15 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
294294
diverging_fallback.reserve(diverging_vids.len());
295295
for &diverging_vid in &diverging_vids {
296296
let diverging_ty = self.tcx.mk_ty_var(diverging_vid);
297-
let root_vid = self.infcx.root_var(diverging_vid);
297+
let root_vid = self.root_var(diverging_vid);
298298
let can_reach_non_diverging = coercion_graph
299299
.depth_first_search(root_vid)
300300
.any(|n| roots_reachable_from_non_diverging.visited(n));
301301

302302
let mut relationship = ty::FoundRelationships { self_in_trait: false, output: false };
303303

304304
for (vid, rel) in relationships.iter() {
305-
if self.infcx.root_var(*vid) == root_vid {
305+
if self.root_var(*vid) == root_vid {
306306
relationship.self_in_trait |= rel.self_in_trait;
307307
relationship.output |= rel.output;
308308
}
@@ -387,12 +387,12 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
387387
})
388388
.collect();
389389
debug!("create_coercion_graph: coercion_edges={:?}", coercion_edges);
390-
let num_ty_vars = self.infcx.num_ty_vars();
390+
let num_ty_vars = self.num_ty_vars();
391391
VecGraph::new(num_ty_vars, coercion_edges)
392392
}
393393

394394
/// If `ty` is an unresolved type variable, returns its root vid.
395395
fn root_vid(&self, ty: Ty<'tcx>) -> Option<ty::TyVid> {
396-
Some(self.infcx.root_var(self.infcx.shallow_resolve(ty).ty_vid()?))
396+
Some(self.root_var(self.shallow_resolve(ty).ty_vid()?))
397397
}
398398
}

compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -185,20 +185,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
185185
if !method.substs.is_empty() {
186186
let method_generics = self.tcx.generics_of(method.def_id);
187187
if !method_generics.params.is_empty() {
188-
let user_type_annotation = self.infcx.probe(|_| {
188+
let user_type_annotation = self.probe(|_| {
189189
let user_substs = UserSubsts {
190190
substs: InternalSubsts::for_item(self.tcx, method.def_id, |param, _| {
191191
let i = param.index as usize;
192192
if i < method_generics.parent_count {
193-
self.infcx.var_for_def(DUMMY_SP, param)
193+
self.var_for_def(DUMMY_SP, param)
194194
} else {
195195
method.substs[i]
196196
}
197197
}),
198198
user_self_ty: None, // not relevant here
199199
};
200200

201-
self.infcx.canonicalize_user_type_annotation(UserType::TypeOf(
201+
self.canonicalize_user_type_annotation(UserType::TypeOf(
202202
method.def_id,
203203
user_substs,
204204
))
@@ -236,7 +236,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
236236
debug!("fcx {}", self.tag());
237237

238238
if Self::can_contain_user_lifetime_bounds((substs, user_self_ty)) {
239-
let canonicalized = self.infcx.canonicalize_user_type_annotation(UserType::TypeOf(
239+
let canonicalized = self.canonicalize_user_type_annotation(UserType::TypeOf(
240240
def_id,
241241
UserSubsts { substs, user_self_ty },
242242
));
@@ -480,7 +480,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
480480
debug!("to_ty_saving_user_provided_ty: ty={:?}", ty);
481481

482482
if Self::can_contain_user_lifetime_bounds(ty) {
483-
let c_ty = self.infcx.canonicalize_response(UserType::Ty(ty));
483+
let c_ty = self.canonicalize_response(UserType::Ty(ty));
484484
debug!("to_ty_saving_user_provided_ty: c_ty={:?}", c_ty);
485485
self.typeck_results.borrow_mut().user_provided_types_mut().insert(ast_ty.hir_id, c_ty);
486486
}
@@ -764,7 +764,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
764764
if let ty::subst::GenericArgKind::Type(ty) = ty.unpack()
765765
&& let ty::Opaque(def_id, _) = *ty.kind()
766766
&& let Some(def_id) = def_id.as_local()
767-
&& self.infcx.opaque_type_origin(def_id, DUMMY_SP).is_some() {
767+
&& self.opaque_type_origin(def_id, DUMMY_SP).is_some() {
768768
return None;
769769
}
770770
}
@@ -826,7 +826,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
826826
} else {
827827
self.tcx.bound_type_of(def_id)
828828
};
829-
let substs = self.infcx.fresh_substs_for_item(span, def_id);
829+
let substs = self.fresh_substs_for_item(span, def_id);
830830
let ty = item_ty.subst(self.tcx, substs);
831831

832832
self.write_resolution(hir_id, Ok((def_kind, def_id)));

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+7-15
Original file line numberDiff line numberDiff line change
@@ -1520,21 +1520,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15201520
/// ```
15211521
fn get_expr_coercion_span(&self, expr: &hir::Expr<'_>) -> rustc_span::Span {
15221522
let check_in_progress = |elem: &hir::Expr<'_>| {
1523-
self.in_progress_typeck_results
1524-
.and_then(|typeck_results| typeck_results.borrow().node_type_opt(elem.hir_id))
1525-
.and_then(|ty| {
1526-
if ty.is_never() {
1527-
None
1528-
} else {
1529-
Some(match elem.kind {
1530-
// Point at the tail expression when possible.
1531-
hir::ExprKind::Block(block, _) => {
1532-
block.expr.map_or(block.span, |e| e.span)
1533-
}
1534-
_ => elem.span,
1535-
})
1536-
}
1537-
})
1523+
self.typeck_results.borrow().node_type_opt(elem.hir_id).filter(|ty| !ty.is_never()).map(
1524+
|_| match elem.kind {
1525+
// Point at the tail expression when possible.
1526+
hir::ExprKind::Block(block, _) => block.expr.map_or(block.span, |e| e.span),
1527+
_ => elem.span,
1528+
},
1529+
)
15381530
};
15391531

15401532
if let hir::ExprKind::If(_, _, Some(el)) = expr.kind {

compiler/rustc_typeck/src/check/method/probe.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -343,15 +343,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
343343
OP: FnOnce(ProbeContext<'a, 'tcx>) -> Result<R, MethodError<'tcx>>,
344344
{
345345
let mut orig_values = OriginalQueryValues::default();
346-
let param_env_and_self_ty = self.infcx.canonicalize_query(
346+
let param_env_and_self_ty = self.canonicalize_query(
347347
ParamEnvAnd { param_env: self.param_env, value: self_ty },
348348
&mut orig_values,
349349
);
350350

351351
let steps = if mode == Mode::MethodCall {
352352
self.tcx.method_autoderef_steps(param_env_and_self_ty)
353353
} else {
354-
self.infcx.probe(|_| {
354+
self.probe(|_| {
355355
// Mode::Path - the deref steps is "trivial". This turns
356356
// our CanonicalQuery into a "trivial" QueryResponse. This
357357
// is a bit inefficient, but I don't think that writing

compiler/rustc_typeck/src/check/method/suggest.rs

+21-22
Original file line numberDiff line numberDiff line change
@@ -865,27 +865,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
865865
.join("\n");
866866
let actual_prefix = actual.prefix_string(self.tcx);
867867
info!("unimplemented_traits.len() == {}", unimplemented_traits.len());
868-
let (primary_message, label) = if unimplemented_traits.len() == 1
869-
&& unimplemented_traits_only
870-
{
871-
unimplemented_traits
872-
.into_iter()
873-
.next()
874-
.map(|(_, (trait_ref, obligation))| {
875-
if trait_ref.self_ty().references_error()
876-
|| actual.references_error()
877-
{
878-
// Avoid crashing.
879-
return (None, None);
880-
}
881-
let OnUnimplementedNote { message, label, .. } =
882-
self.infcx.on_unimplemented_note(trait_ref, &obligation);
883-
(message, label)
884-
})
885-
.unwrap_or((None, None))
886-
} else {
887-
(None, None)
888-
};
868+
let (primary_message, label) =
869+
if unimplemented_traits.len() == 1 && unimplemented_traits_only {
870+
unimplemented_traits
871+
.into_iter()
872+
.next()
873+
.map(|(_, (trait_ref, obligation))| {
874+
if trait_ref.self_ty().references_error()
875+
|| actual.references_error()
876+
{
877+
// Avoid crashing.
878+
return (None, None);
879+
}
880+
let OnUnimplementedNote { message, label, .. } =
881+
self.on_unimplemented_note(trait_ref, &obligation);
882+
(message, label)
883+
})
884+
.unwrap_or((None, None))
885+
} else {
886+
(None, None)
887+
};
889888
let primary_message = primary_message.unwrap_or_else(|| format!(
890889
"the {item_kind} `{item_name}` exists for {actual_prefix} `{ty_str}`, but its trait bounds were not satisfied"
891890
));
@@ -1648,7 +1647,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16481647
call: &hir::Expr<'_>,
16491648
span: Span,
16501649
) {
1651-
let output_ty = match self.infcx.get_impl_future_output_ty(ty) {
1650+
let output_ty = match self.get_impl_future_output_ty(ty) {
16521651
Some(output_ty) => self.resolve_vars_if_possible(output_ty).skip_binder(),
16531652
_ => return,
16541653
};

compiler/rustc_typeck/src/check/op.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
475475
suggest_deref_binop(lhs_deref_ty);
476476
} else if is_assign == IsAssign::No
477477
&& let Ref(_, lhs_deref_ty, _) = lhs_ty.kind() {
478-
if self.infcx.type_is_copy_modulo_regions(self.param_env, *lhs_deref_ty, lhs_expr.span) {
478+
if self.type_is_copy_modulo_regions(self.param_env, *lhs_deref_ty, lhs_expr.span) {
479479
suggest_deref_binop(*lhs_deref_ty);
480480
}
481481
}
@@ -523,7 +523,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
523523
_ => None,
524524
};
525525

526-
self.infcx.suggest_restricting_param_bound(
526+
self.suggest_restricting_param_bound(
527527
&mut err,
528528
trait_pred,
529529
proj_pred,
@@ -740,7 +740,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
740740
error.obligation.predicate.to_opt_poly_trait_pred()
741741
});
742742
for pred in predicates {
743-
self.infcx.suggest_restricting_param_bound(
743+
self.suggest_restricting_param_bound(
744744
&mut err,
745745
pred,
746746
None,

0 commit comments

Comments
 (0)