]> git.lizzy.rs Git - rust.git/commitdiff
Add some comments to librustc_typeck/check/callee.rs
authorGary Guo <gary@garyguo.net>
Sun, 14 Jun 2020 23:57:21 +0000 (00:57 +0100)
committerGary Guo <gary@garyguo.net>
Sun, 14 Jun 2020 23:57:21 +0000 (00:57 +0100)
src/librustc_typeck/check/callee.rs

index aa316105f7f11be99809a1e6d5ca07e683939591..f86b7f07b7fc48b46293dfe4e9877c0c1b5985fb 100644 (file)
@@ -220,21 +220,28 @@ fn try_overloaded_call_traits(
                 let method = self.register_infer_ok_obligations(ok);
                 let mut autoref = None;
                 if borrow {
-                    if let ty::Ref(region, _, mutbl) = method.sig.inputs()[0].kind {
-                        let mutbl = match mutbl {
-                            hir::Mutability::Not => AutoBorrowMutability::Not,
-                            hir::Mutability::Mut => AutoBorrowMutability::Mut {
-                                // For initial two-phase borrow
-                                // deployment, conservatively omit
-                                // overloaded function call ops.
-                                allow_two_phase_borrow: AllowTwoPhase::No,
-                            },
-                        };
-                        autoref = Some(Adjustment {
-                            kind: Adjust::Borrow(AutoBorrow::Ref(region, mutbl)),
-                            target: method.sig.inputs()[0],
-                        });
-                    }
+                    // Check for &self vs &mut self in the method signature. Since this is either
+                    // the Fn or FnMut trait, it should be one of those.
+                    let (region, mutbl) = if let ty::Ref(r, _, mutbl) = method.sig.inputs()[0].kind
+                    {
+                        (r, mutbl)
+                    } else {
+                        span_bug!(call_expr.span, "input to call/call_mut is not a ref?");
+                    };
+
+                    let mutbl = match mutbl {
+                        hir::Mutability::Not => AutoBorrowMutability::Not,
+                        hir::Mutability::Mut => AutoBorrowMutability::Mut {
+                            // For initial two-phase borrow
+                            // deployment, conservatively omit
+                            // overloaded function call ops.
+                            allow_two_phase_borrow: AllowTwoPhase::No,
+                        },
+                    };
+                    autoref = Some(Adjustment {
+                        kind: Adjust::Borrow(AutoBorrow::Ref(region, mutbl)),
+                        target: method.sig.inputs()[0],
+                    });
                 }
                 return Some((autoref, method));
             }