small method code cleanup

This commit is contained in:
lcnr 2022-11-25 15:51:46 +01:00
parent 8a75c5a9b5
commit 40a053361a
3 changed files with 17 additions and 15 deletions

View File

@ -179,12 +179,16 @@ fn try_overloaded_call_step(
// Hack: we know that there are traits implementing Fn for &F
// where F:Fn and so forth. In the particular case of types
// like `x: &mut FnMut()`, if there is a call `x()`, we would
// normally translate to `FnMut::call_mut(&mut x, ())`, but
// that winds up requiring `mut x: &mut FnMut()`. A little
// over the top. The simplest fix by far is to just ignore
// this case and deref again, so we wind up with
// `FnMut::call_mut(&mut *x, ())`.
// like `f: &mut FnMut()`, if there is a call `f()`, we would
// normally translate to `FnMut::call_mut(&mut f, ())`, but
// that winds up requiring the user to potentially mark their
// variable as `mut` which feels unnecessary and unexpected.
//
// fn foo(f: &mut impl FnMut()) { f() }
// ^ without this hack `f` would have to be declared as mutable
//
// The simplest fix by far is to just ignore this case and deref again,
// so we wind up with `FnMut::call_mut(&mut *f, ())`.
ty::Ref(..) if autoderef.step_count() == 0 => {
return None;
}

View File

@ -1112,15 +1112,14 @@ fn try_find_coercion_lub<E>(
// Special-case that coercion alone cannot handle:
// Function items or non-capturing closures of differing IDs or InternalSubsts.
let (a_sig, b_sig) = {
#[allow(rustc::usage_of_ty_tykind)]
let is_capturing_closure = |ty: &ty::TyKind<'tcx>| {
if let &ty::Closure(closure_def_id, _substs) = ty {
let is_capturing_closure = |ty: Ty<'tcx>| {
if let &ty::Closure(closure_def_id, _substs) = ty.kind() {
self.tcx.upvars_mentioned(closure_def_id.expect_local()).is_some()
} else {
false
}
};
if is_capturing_closure(prev_ty.kind()) || is_capturing_closure(new_ty.kind()) {
if is_capturing_closure(prev_ty) || is_capturing_closure(new_ty) {
(None, None)
} else {
match (prev_ty.kind(), new_ty.kind()) {

View File

@ -342,10 +342,9 @@ fn probe_op<OP, R>(
&mut orig_values,
);
let steps = if mode == Mode::MethodCall {
self.tcx.method_autoderef_steps(param_env_and_self_ty)
} else {
self.probe(|_| {
let steps = match mode {
Mode::MethodCall => self.tcx.method_autoderef_steps(param_env_and_self_ty),
Mode::Path => 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
@ -374,7 +373,7 @@ fn probe_op<OP, R>(
opt_bad_ty: None,
reached_recursion_limit: false,
}
})
}),
};
// If our autoderef loop had reached the recursion limit,