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 // Hack: we know that there are traits implementing Fn for &F
// where F:Fn and so forth. In the particular case of types // where F:Fn and so forth. In the particular case of types
// like `x: &mut FnMut()`, if there is a call `x()`, we would // like `f: &mut FnMut()`, if there is a call `f()`, we would
// normally translate to `FnMut::call_mut(&mut x, ())`, but // normally translate to `FnMut::call_mut(&mut f, ())`, but
// that winds up requiring `mut x: &mut FnMut()`. A little // that winds up requiring the user to potentially mark their
// over the top. The simplest fix by far is to just ignore // variable as `mut` which feels unnecessary and unexpected.
// this case and deref again, so we wind up with //
// `FnMut::call_mut(&mut *x, ())`. // 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 => { ty::Ref(..) if autoderef.step_count() == 0 => {
return None; return None;
} }

View File

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

View File

@ -342,10 +342,9 @@ fn probe_op<OP, R>(
&mut orig_values, &mut orig_values,
); );
let steps = if mode == Mode::MethodCall { let steps = match mode {
self.tcx.method_autoderef_steps(param_env_and_self_ty) Mode::MethodCall => self.tcx.method_autoderef_steps(param_env_and_self_ty),
} else { Mode::Path => self.probe(|_| {
self.probe(|_| {
// Mode::Path - the deref steps is "trivial". This turns // Mode::Path - the deref steps is "trivial". This turns
// our CanonicalQuery into a "trivial" QueryResponse. This // our CanonicalQuery into a "trivial" QueryResponse. This
// is a bit inefficient, but I don't think that writing // is a bit inefficient, but I don't think that writing
@ -374,7 +373,7 @@ fn probe_op<OP, R>(
opt_bad_ty: None, opt_bad_ty: None,
reached_recursion_limit: false, reached_recursion_limit: false,
} }
}) }),
}; };
// If our autoderef loop had reached the recursion limit, // If our autoderef loop had reached the recursion limit,