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.
This commit is contained in:
parent
14398f2929
commit
737e39696b
@ -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.
|
||||
|
@ -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!()
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
13
src/test/compile-fail/issue-18159.rs
Normal file
13
src/test/compile-fail/issue-18159.rs
Normal file
@ -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
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user