Skip to content

Commit

Permalink
Rollup merge of rust-lang#99615 - compiler-errors:remove-some-explici…
Browse files Browse the repository at this point in the history
…t-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
  • Loading branch information
JohnTitor authored Jul 26, 2022
2 parents d89e99a + aaa9989 commit 2744c0e
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 77 deletions.
6 changes: 3 additions & 3 deletions compiler/rustc_typeck/src/check/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,17 +488,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ty::Binder::dummy(ty::PredicateKind::Trait(ty::TraitPredicate {
trait_ref: ty::TraitRef {
def_id: t.def_id(),
substs: self.infcx.tcx.mk_substs_trait(outer_ty, &[]),
substs: self.tcx.mk_substs_trait(outer_ty, &[]),
},
constness: t.constness,
polarity: t.polarity,
}));
let obl = Obligation::new(
o.cause.clone(),
self.param_env,
pred.to_predicate(self.infcx.tcx),
pred.to_predicate(self.tcx),
);
suggest_box &= self.infcx.predicate_must_hold_modulo_regions(&obl);
suggest_box &= self.predicate_must_hold_modulo_regions(&obl);
if !suggest_box {
// We've encountered some obligation that didn't hold, so the
// return expression can't just be boxed. We don't need to
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.param_env,
*predicate,
);
let result = self.infcx.evaluate_obligation(&obligation);
let result = self.evaluate_obligation(&obligation);
self.tcx
.sess
.struct_span_err(
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_typeck/src/check/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.tcx.typeck_root_def_id(expr_def_id.to_def_id()),
);

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

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

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

let supplied_output_ty = self.infcx.replace_bound_vars_with_fresh_vars(
let supplied_output_ty = self.replace_bound_vars_with_fresh_vars(
decl.output.span(),
LateBoundRegionConversionTime::FnCall,
supplied_sig.output(),
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_typeck/src/check/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,13 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
make_adjustments: impl FnOnce(Ty<'tcx>) -> Vec<Adjustment<'tcx>>,
) -> CoerceResult<'tcx> {
debug!("coerce_from_inference_variable(a={:?}, b={:?})", a, b);
assert!(a.is_ty_var() && self.infcx.shallow_resolve(a) == a);
assert!(self.infcx.shallow_resolve(b) == b);
assert!(a.is_ty_var() && self.shallow_resolve(a) == a);
assert!(self.shallow_resolve(b) == b);

if b.is_ty_var() {
// Two unresolved type variables: create a `Coerce` predicate.
let target_ty = if self.use_lub {
self.infcx.next_ty_var(TypeVariableOrigin {
self.next_ty_var(TypeVariableOrigin {
kind: TypeVariableOriginKind::LatticeVariable,
span: self.cause.span,
})
Expand Down Expand Up @@ -991,7 +991,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.autoderef(rustc_span::DUMMY_SP, expr_ty).nth(1).and_then(|(deref_ty, _)| {
self.infcx
.type_implements_trait(
self.infcx.tcx.lang_items().deref_mut_trait()?,
self.tcx.lang_items().deref_mut_trait()?,
expr_ty,
ty::List::empty(),
self.param_env,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_typeck/src/check/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
hir::ExprKind::AddrOf(hir::BorrowKind::Ref, _, ref expr),
_,
&ty::Ref(_, checked, _),
) if self.infcx.can_sub(self.param_env, checked, expected).is_ok() => {
) if self.can_sub(self.param_env, checked, expected).is_ok() => {
// We have `&T`, check if what was expected was `T`. If so,
// we may want to suggest removing a `&`.
if sm.is_imported(expr.span) {
Expand Down Expand Up @@ -974,7 +974,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

// For this suggestion to make sense, the type would need to be `Copy`,
// or we have to be moving out of a `Box<T>`
if self.infcx.type_is_copy_modulo_regions(self.param_env, expected, sp)
if self.type_is_copy_modulo_regions(self.param_env, expected, sp)
// FIXME(compiler-errors): We can actually do this if the checked_ty is
// `steps` layers of boxes, not just one, but this is easier and most likely.
|| (checked_ty.is_box() && steps == 1)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2235,7 +2235,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
base: &'tcx hir::Expr<'tcx>,
ty: Ty<'tcx>,
) {
let output_ty = match self.infcx.get_impl_future_output_ty(ty) {
let output_ty = match self.get_impl_future_output_ty(ty) {
Some(output_ty) => self.resolve_vars_if_possible(output_ty),
_ => return,
};
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_typeck/src/check/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
.diverging_type_vars
.borrow()
.iter()
.map(|&ty| self.infcx.shallow_resolve(ty))
.map(|&ty| self.shallow_resolve(ty))
.filter_map(|ty| ty.ty_vid())
.map(|vid| self.infcx.root_var(vid))
.map(|vid| self.root_var(vid))
.collect();
debug!(
"calculate_diverging_fallback: diverging_type_vars={:?}",
Expand All @@ -236,7 +236,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
let mut diverging_vids = vec![];
let mut non_diverging_vids = vec![];
for unsolved_vid in unsolved_vids {
let root_vid = self.infcx.root_var(unsolved_vid);
let root_vid = self.root_var(unsolved_vid);
debug!(
"calculate_diverging_fallback: unsolved_vid={:?} root_vid={:?} diverges={:?}",
unsolved_vid,
Expand Down Expand Up @@ -271,7 +271,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
// variables. (Note that this set consists of "root variables".)
let mut roots_reachable_from_non_diverging = DepthFirstSearch::new(&coercion_graph);
for &non_diverging_vid in &non_diverging_vids {
let root_vid = self.infcx.root_var(non_diverging_vid);
let root_vid = self.root_var(non_diverging_vid);
if roots_reachable_from_diverging.visited(root_vid) {
continue;
}
Expand All @@ -294,15 +294,15 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
diverging_fallback.reserve(diverging_vids.len());
for &diverging_vid in &diverging_vids {
let diverging_ty = self.tcx.mk_ty_var(diverging_vid);
let root_vid = self.infcx.root_var(diverging_vid);
let root_vid = self.root_var(diverging_vid);
let can_reach_non_diverging = coercion_graph
.depth_first_search(root_vid)
.any(|n| roots_reachable_from_non_diverging.visited(n));

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

for (vid, rel) in relationships.iter() {
if self.infcx.root_var(*vid) == root_vid {
if self.root_var(*vid) == root_vid {
relationship.self_in_trait |= rel.self_in_trait;
relationship.output |= rel.output;
}
Expand Down Expand Up @@ -387,12 +387,12 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
})
.collect();
debug!("create_coercion_graph: coercion_edges={:?}", coercion_edges);
let num_ty_vars = self.infcx.num_ty_vars();
let num_ty_vars = self.num_ty_vars();
VecGraph::new(num_ty_vars, coercion_edges)
}

/// If `ty` is an unresolved type variable, returns its root vid.
fn root_vid(&self, ty: Ty<'tcx>) -> Option<ty::TyVid> {
Some(self.infcx.root_var(self.infcx.shallow_resolve(ty).ty_vid()?))
Some(self.root_var(self.shallow_resolve(ty).ty_vid()?))
}
}
14 changes: 7 additions & 7 deletions compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if !method.substs.is_empty() {
let method_generics = self.tcx.generics_of(method.def_id);
if !method_generics.params.is_empty() {
let user_type_annotation = self.infcx.probe(|_| {
let user_type_annotation = self.probe(|_| {
let user_substs = UserSubsts {
substs: InternalSubsts::for_item(self.tcx, method.def_id, |param, _| {
let i = param.index as usize;
if i < method_generics.parent_count {
self.infcx.var_for_def(DUMMY_SP, param)
self.var_for_def(DUMMY_SP, param)
} else {
method.substs[i]
}
}),
user_self_ty: None, // not relevant here
};

self.infcx.canonicalize_user_type_annotation(UserType::TypeOf(
self.canonicalize_user_type_annotation(UserType::TypeOf(
method.def_id,
user_substs,
))
Expand Down Expand Up @@ -236,7 +236,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
debug!("fcx {}", self.tag());

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

if Self::can_contain_user_lifetime_bounds(ty) {
let c_ty = self.infcx.canonicalize_response(UserType::Ty(ty));
let c_ty = self.canonicalize_response(UserType::Ty(ty));
debug!("to_ty_saving_user_provided_ty: c_ty={:?}", c_ty);
self.typeck_results.borrow_mut().user_provided_types_mut().insert(ast_ty.hir_id, c_ty);
}
Expand Down Expand Up @@ -764,7 +764,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let ty::subst::GenericArgKind::Type(ty) = ty.unpack()
&& let ty::Opaque(def_id, _) = *ty.kind()
&& let Some(def_id) = def_id.as_local()
&& self.infcx.opaque_type_origin(def_id, DUMMY_SP).is_some() {
&& self.opaque_type_origin(def_id, DUMMY_SP).is_some() {
return None;
}
}
Expand Down Expand Up @@ -826,7 +826,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} else {
self.tcx.bound_type_of(def_id)
};
let substs = self.infcx.fresh_substs_for_item(span, def_id);
let substs = self.fresh_substs_for_item(span, def_id);
let ty = item_ty.subst(self.tcx, substs);

self.write_resolution(hir_id, Ok((def_kind, def_id)));
Expand Down
22 changes: 7 additions & 15 deletions compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1520,21 +1520,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// ```
fn get_expr_coercion_span(&self, expr: &hir::Expr<'_>) -> rustc_span::Span {
let check_in_progress = |elem: &hir::Expr<'_>| {
self.in_progress_typeck_results
.and_then(|typeck_results| typeck_results.borrow().node_type_opt(elem.hir_id))
.and_then(|ty| {
if ty.is_never() {
None
} else {
Some(match elem.kind {
// Point at the tail expression when possible.
hir::ExprKind::Block(block, _) => {
block.expr.map_or(block.span, |e| e.span)
}
_ => elem.span,
})
}
})
self.typeck_results.borrow().node_type_opt(elem.hir_id).filter(|ty| !ty.is_never()).map(
|_| match elem.kind {
// Point at the tail expression when possible.
hir::ExprKind::Block(block, _) => block.expr.map_or(block.span, |e| e.span),
_ => elem.span,
},
)
};

if let hir::ExprKind::If(_, _, Some(el)) = expr.kind {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_typeck/src/check/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,15 +343,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
OP: FnOnce(ProbeContext<'a, 'tcx>) -> Result<R, MethodError<'tcx>>,
{
let mut orig_values = OriginalQueryValues::default();
let param_env_and_self_ty = self.infcx.canonicalize_query(
let param_env_and_self_ty = self.canonicalize_query(
ParamEnvAnd { param_env: self.param_env, value: self_ty },
&mut orig_values,
);

let steps = if mode == Mode::MethodCall {
self.tcx.method_autoderef_steps(param_env_and_self_ty)
} else {
self.infcx.probe(|_| {
self.probe(|_| {
// Mode::Path - the deref steps is "trivial". This turns
// our CanonicalQuery into a "trivial" QueryResponse. This
// is a bit inefficient, but I don't think that writing
Expand Down
43 changes: 21 additions & 22 deletions compiler/rustc_typeck/src/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -865,27 +865,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.join("\n");
let actual_prefix = actual.prefix_string(self.tcx);
info!("unimplemented_traits.len() == {}", unimplemented_traits.len());
let (primary_message, label) = if unimplemented_traits.len() == 1
&& unimplemented_traits_only
{
unimplemented_traits
.into_iter()
.next()
.map(|(_, (trait_ref, obligation))| {
if trait_ref.self_ty().references_error()
|| actual.references_error()
{
// Avoid crashing.
return (None, None);
}
let OnUnimplementedNote { message, label, .. } =
self.infcx.on_unimplemented_note(trait_ref, &obligation);
(message, label)
})
.unwrap_or((None, None))
} else {
(None, None)
};
let (primary_message, label) =
if unimplemented_traits.len() == 1 && unimplemented_traits_only {
unimplemented_traits
.into_iter()
.next()
.map(|(_, (trait_ref, obligation))| {
if trait_ref.self_ty().references_error()
|| actual.references_error()
{
// Avoid crashing.
return (None, None);
}
let OnUnimplementedNote { message, label, .. } =
self.on_unimplemented_note(trait_ref, &obligation);
(message, label)
})
.unwrap_or((None, None))
} else {
(None, None)
};
let primary_message = primary_message.unwrap_or_else(|| format!(
"the {item_kind} `{item_name}` exists for {actual_prefix} `{ty_str}`, but its trait bounds were not satisfied"
));
Expand Down Expand Up @@ -1648,7 +1647,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
call: &hir::Expr<'_>,
span: Span,
) {
let output_ty = match self.infcx.get_impl_future_output_ty(ty) {
let output_ty = match self.get_impl_future_output_ty(ty) {
Some(output_ty) => self.resolve_vars_if_possible(output_ty).skip_binder(),
_ => return,
};
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_typeck/src/check/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
suggest_deref_binop(lhs_deref_ty);
} else if is_assign == IsAssign::No
&& let Ref(_, lhs_deref_ty, _) = lhs_ty.kind() {
if self.infcx.type_is_copy_modulo_regions(self.param_env, *lhs_deref_ty, lhs_expr.span) {
if self.type_is_copy_modulo_regions(self.param_env, *lhs_deref_ty, lhs_expr.span) {
suggest_deref_binop(*lhs_deref_ty);
}
}
Expand Down Expand Up @@ -523,7 +523,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
_ => None,
};

self.infcx.suggest_restricting_param_bound(
self.suggest_restricting_param_bound(
&mut err,
trait_pred,
proj_pred,
Expand Down Expand Up @@ -740,7 +740,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
error.obligation.predicate.to_opt_poly_trait_pred()
});
for pred in predicates {
self.infcx.suggest_restricting_param_bound(
self.suggest_restricting_param_bound(
&mut err,
pred,
None,
Expand Down
Loading

0 comments on commit 2744c0e

Please sign in to comment.