Skip to content

Commit 737e396

Browse files
committed
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.
1 parent 14398f2 commit 737e396

File tree

4 files changed

+34
-12
lines changed

4 files changed

+34
-12
lines changed

src/librustc/middle/typeck/check/vtable.rs

+19-9
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,25 @@ pub fn maybe_report_ambiguity(fcx: &FnCtxt, obligation: &Obligation) {
303303
// has_errors() to be sure that compilation isn't happening
304304
// anyway. In that case, why inundate the user.
305305
if !fcx.tcx().sess.has_errors() {
306-
fcx.tcx().sess.span_err(
307-
obligation.cause.span,
308-
format!(
309-
"unable to infer enough type information to \
310-
locate the impl of the trait `{}` for \
311-
the type `{}`; type annotations required",
312-
trait_ref.user_string(fcx.tcx()),
313-
self_ty.user_string(fcx.tcx())).as_slice());
314-
note_obligation_cause(fcx, obligation);
306+
if fcx.ccx.tcx.lang_items.sized_trait()
307+
.map_or(false, |sized_id| sized_id == trait_ref.def_id) {
308+
fcx.tcx().sess.span_err(
309+
obligation.cause.span,
310+
format!(
311+
"unable to infer enough type information about `{}`; type annotations \
312+
required",
313+
self_ty.user_string(fcx.tcx())).as_slice());
314+
} else {
315+
fcx.tcx().sess.span_err(
316+
obligation.cause.span,
317+
format!(
318+
"unable to infer enough type information to \
319+
locate the impl of the trait `{}` for \
320+
the type `{}`; type annotations required",
321+
trait_ref.user_string(fcx.tcx()),
322+
self_ty.user_string(fcx.tcx())).as_slice());
323+
note_obligation_cause(fcx, obligation);
324+
}
315325
}
316326
} else if !fcx.tcx().sess.has_errors() {
317327
// Ambiguity. Coherence should have reported an error.

src/test/compile-fail/issue-16562.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ struct Col<D, C> {
1616
}
1717

1818
impl<T, M: MatrixShape> Collection for Col<M, uint> {
19-
//~^ ERROR unable to infer enough type information to locate the impl of the trait
20-
//~^^ NOTE the trait `core::kinds::Sized` must be implemented because it is required by
19+
//~^ ERROR unable to infer enough type information
2120
fn len(&self) -> uint {
2221
unimplemented!()
2322
}

src/test/compile-fail/issue-17551.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
struct B<T>;
1414

1515
fn main() {
16-
let foo = B; //~ ERROR unable to infer enough type information to locate the impl of the trait
16+
let foo = B; //~ ERROR unable to infer enough type information
1717
let closure = |:| foo;
1818
}

src/test/compile-fail/issue-18159.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let x; //~ ERROR unable to infer enough type information
13+
}

0 commit comments

Comments
 (0)