- } else if let Some(ExprKind::MethodCall(segment, ..)) = local_visitor.found_method_call {
- if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(segment.ident.span) {
- if segment.args.is_none() {
- err.span_suggestion(
- segment.ident.span,
- "consider specifying the type argument in the method call",
- // FIXME: we don't know how many type arguments should be set here.
- format!("{}::<_>", snippet),
- Applicability::HasPlaceholders,
- );
+ } else if let Some(e) = local_visitor.found_method_call {
+ if let ExprKind::MethodCall(segment, _call_sp, _args) = &e.kind {
+ if let (Ok(snippet), Some(tables), None) = (
+ self.tcx.sess.source_map().span_to_snippet(segment.ident.span),
+ self.in_progress_tables,
+ &segment.args,
+ ) {
+ let borrow = tables.borrow();
+ let sigs = borrow.node_method_sig();
+ if let Some(sig) = sigs.get(e.hir_id) {
+ let mut params = vec![];
+ for arg in sig.inputs_and_output().skip_binder().iter() {
+ if let ty::Param(param) = arg.kind {
+ if param.name != kw::SelfUpper {
+ let name = param.name.to_string();
+ if !params.contains(&name) {
+ params.push(name);
+ }
+ }
+ }
+ }
+ if !params.is_empty() {
+ err.span_suggestion(
+ segment.ident.span,
+ &format!(
+ "consider specifying the type argument{} in the method call",
+ if params.len() > 1 {
+ "s"
+ } else {
+ ""
+ },
+ ),
+ format!("{}::<{}>", snippet, params.join(", ")),
+ Applicability::HasPlaceholders,
+ );
+ } else {
+ err.span_label(e.span, &format!(
+ "this method call resolves to `{:?}`",
+ sig.output().skip_binder(),
+ ));
+ }
+ }