diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 963da8588035..b8200a8e1733 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -1994,6 +1994,30 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { } let mut err = self.need_type_info_err(body_id, span, self_ty, ErrorCode::E0283); err.note(&format!("cannot resolve `{}`", predicate)); + if let (Ok(ref snippet), ObligationCauseCode::BindingObligation(ref def_id, _)) = ( + self.tcx.sess.source_map().span_to_snippet(span), + &obligation.cause.code, + ) { + let generics = self.tcx.generics_of(*def_id); + if !generics.params.is_empty() { + err.span_suggestion( + span, + &format!( + "consider specifying the type argument{} in the function call", + if generics.params.len() > 1 { + "s" + } else { + "" + }, + ), + format!("{}::<{}>", snippet, generics.params.iter() + .map(|p| p.name.to_string()) + .collect::>() + .join(", ")), + Applicability::HasPlaceholders, + ); + } + } err } diff --git a/src/test/ui/type/type-annotation-needed.stderr b/src/test/ui/type/type-annotation-needed.stderr index f30bbf6b7db5..5b7d6ba16d02 100644 --- a/src/test/ui/type/type-annotation-needed.stderr +++ b/src/test/ui/type/type-annotation-needed.stderr @@ -5,7 +5,10 @@ LL | fn foo>(x: i32) {} | --- ------------ required by this bound in `foo` ... LL | foo(42); - | ^^^ cannot infer type for `T` + | ^^^ + | | + | cannot infer type for `T` + | help: consider specifying the type argument in the function call: `foo::` | = note: cannot resolve `_: std::convert::Into`