]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_typeck/check/expr.rs
Use the appropriate number of type arguments in suggestion
[rust.git] / src / librustc_typeck / check / expr.rs
index 5bfc60c75406745e0c0a7ac2c2db42eca0599edf..5f971a1ad505b3b7048676432106e921c3cc78af 100644 (file)
@@ -871,6 +871,27 @@ fn check_method_call(
 
         let method = match self.lookup_method(rcvr_t, segment, span, expr, rcvr) {
             Ok(method) => {
+                let sig = self.tcx.fn_sig(method.def_id);
+                // We could add a "consider `foo::<params>`" suggestion here, but I wasn't able to
+                // trigger this codepath causing `structuraly_resolved_type` to emit an error.
+
+                // We could do this only when type params are present in the method to reducte
+                // memory usage, but doing it unconditionally lets us also point at the method
+                // expression and state the resolved return value:
+                // ```
+                // error[E0282]: type annotations needed
+                //    --> $DIR/issue-65611.rs:59:20
+                //    |
+                // LL |     let x = buffer.last().unwrap().0.clone();
+                //    |             -------^^^^--
+                //    |             |      |
+                //    |             |      cannot infer type for `T`
+                //    |             this method call resolves to `std::option::Option<&T>`
+                //    |
+                //    = note: type must be known at this point
+                // ```
+                self.tables.borrow_mut().node_method_sig_mut().insert(expr.hir_id, sig);
+
                 self.write_method_call(expr.hir_id, method);
                 Ok(method)
             }