Skip to content

Commit 40a0533

Browse files
committed
small method code cleanup
1 parent 8a75c5a commit 40a0533

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

compiler/rustc_hir_typeck/src/callee.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
179179

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

compiler/rustc_hir_typeck/src/coercion.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1112,15 +1112,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11121112
// Special-case that coercion alone cannot handle:
11131113
// Function items or non-capturing closures of differing IDs or InternalSubsts.
11141114
let (a_sig, b_sig) = {
1115-
#[allow(rustc::usage_of_ty_tykind)]
1116-
let is_capturing_closure = |ty: &ty::TyKind<'tcx>| {
1117-
if let &ty::Closure(closure_def_id, _substs) = ty {
1115+
let is_capturing_closure = |ty: Ty<'tcx>| {
1116+
if let &ty::Closure(closure_def_id, _substs) = ty.kind() {
11181117
self.tcx.upvars_mentioned(closure_def_id.expect_local()).is_some()
11191118
} else {
11201119
false
11211120
}
11221121
};
1123-
if is_capturing_closure(prev_ty.kind()) || is_capturing_closure(new_ty.kind()) {
1122+
if is_capturing_closure(prev_ty) || is_capturing_closure(new_ty) {
11241123
(None, None)
11251124
} else {
11261125
match (prev_ty.kind(), new_ty.kind()) {

compiler/rustc_hir_typeck/src/method/probe.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
342342
&mut orig_values,
343343
);
344344

345-
let steps = if mode == Mode::MethodCall {
346-
self.tcx.method_autoderef_steps(param_env_and_self_ty)
347-
} else {
348-
self.probe(|_| {
345+
let steps = match mode {
346+
Mode::MethodCall => self.tcx.method_autoderef_steps(param_env_and_self_ty),
347+
Mode::Path => self.probe(|_| {
349348
// Mode::Path - the deref steps is "trivial". This turns
350349
// our CanonicalQuery into a "trivial" QueryResponse. This
351350
// is a bit inefficient, but I don't think that writing
@@ -374,7 +373,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
374373
opt_bad_ty: None,
375374
reached_recursion_limit: false,
376375
}
377-
})
376+
}),
378377
};
379378

380379
// If our autoderef loop had reached the recursion limit,

0 commit comments

Comments
 (0)