diff options
| author | P1start <rewi-github@whanau.org> | 2014-10-28 21:04:08 +1300 |
|---|---|---|
| committer | P1start <rewi-github@whanau.org> | 2014-10-30 19:51:17 +1300 |
| commit | 737e39696ba0964729f29410cf4e75a061ce120a (patch) | |
| tree | 0ff7bb4beddffe9ca37a9e58f436c01c2ebb8d45 | |
| parent | 14398f29290b0d96dbe60f329b69062442eefb33 (diff) | |
| download | rust-737e39696ba0964729f29410cf4e75a061ce120a.tar.gz rust-737e39696ba0964729f29410cf4e75a061ce120a.zip | |
Special-case some error messages about `Sized`
The error messages still aren’t as good as they were before DST, but they better describe the actual problem, not mentioning `Sized` at all (because that bound is normally implied, not explicitly stated). Closes #17567. Closes #18040. Closes #18159.
| -rw-r--r-- | src/librustc/middle/typeck/check/vtable.rs | 28 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-16562.rs | 3 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-17551.rs | 2 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-18159.rs | 13 |
4 files changed, 34 insertions, 12 deletions
diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc/middle/typeck/check/vtable.rs index a5624dcc2fc..14bb92759d3 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 1e69fb7bfc9..2207e10add4 100644 --- a/src/test/compile-fail/issue-16562.rs +++ b/src/test/compile-fail/issue-16562.rs @@ -16,8 +16,7 @@ struct Col<D, C> { } impl<T, M: MatrixShape> Collection for Col<M, uint> { -//~^ 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 197319b6d43..e7f61a4f3ff 100644 --- a/src/test/compile-fail/issue-17551.rs +++ b/src/test/compile-fail/issue-17551.rs @@ -13,6 +13,6 @@ struct B<T>; 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 00000000000..e46bcf46cc3 --- /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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 +} |
