diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc/middle/typeck/check/vtable.rs index a5624dcc2fcd..14bb92759d3e 100644 --- a/src/librustc/middle/typeck/check/vtable.rs +++ b/src/librustc/middle/typeck/check/vtable.rs @@ -303,15 +303,25 @@ pub fn maybe_report_ambiguity(fcx: &FnCtxt, obligation: &Obligation) { // has_errors() to be sure that compilation isn't happening // anyway. In that case, why inundate the user. if !fcx.tcx().sess.has_errors() { - fcx.tcx().sess.span_err( - obligation.cause.span, - format!( - "unable to infer enough type information to \ - locate the impl of the trait `{}` for \ - the type `{}`; type annotations required", - trait_ref.user_string(fcx.tcx()), - self_ty.user_string(fcx.tcx())).as_slice()); - note_obligation_cause(fcx, obligation); + if fcx.ccx.tcx.lang_items.sized_trait() + .map_or(false, |sized_id| sized_id == trait_ref.def_id) { + fcx.tcx().sess.span_err( + obligation.cause.span, + format!( + "unable to infer enough type information about `{}`; type annotations \ + required", + self_ty.user_string(fcx.tcx())).as_slice()); + } else { + fcx.tcx().sess.span_err( + obligation.cause.span, + format!( + "unable to infer enough type information to \ + locate the impl of the trait `{}` for \ + the type `{}`; type annotations required", + trait_ref.user_string(fcx.tcx()), + self_ty.user_string(fcx.tcx())).as_slice()); + note_obligation_cause(fcx, obligation); + } } } else if !fcx.tcx().sess.has_errors() { // Ambiguity. Coherence should have reported an error. diff --git a/src/test/compile-fail/issue-16562.rs b/src/test/compile-fail/issue-16562.rs index 1e69fb7bfc94..2207e10add45 100644 --- a/src/test/compile-fail/issue-16562.rs +++ b/src/test/compile-fail/issue-16562.rs @@ -16,8 +16,7 @@ struct Col { } impl Collection for Col { -//~^ ERROR unable to infer enough type information to locate the impl of the trait -//~^^ NOTE the trait `core::kinds::Sized` must be implemented because it is required by +//~^ ERROR unable to infer enough type information fn len(&self) -> uint { unimplemented!() } diff --git a/src/test/compile-fail/issue-17551.rs b/src/test/compile-fail/issue-17551.rs index 197319b6d434..e7f61a4f3ff5 100644 --- a/src/test/compile-fail/issue-17551.rs +++ b/src/test/compile-fail/issue-17551.rs @@ -13,6 +13,6 @@ struct B; fn main() { - let foo = B; //~ ERROR unable to infer enough type information to locate the impl of the trait + let foo = B; //~ ERROR unable to infer enough type information let closure = |:| foo; } diff --git a/src/test/compile-fail/issue-18159.rs b/src/test/compile-fail/issue-18159.rs new file mode 100644 index 000000000000..e46bcf46cc39 --- /dev/null +++ b/src/test/compile-fail/issue-18159.rs @@ -0,0 +1,13 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let x; //~ ERROR unable to infer enough type information +}