auto merge of #18264 : jakub-/rust/var-ids-in-error-messages, r=nikomatsakis
This PR aims to improve the readability of diagnostic messages that involve unresolved type variables. Currently, messages like the following: ```rust mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>` <anon>:6 let a: Result<uint, ()> = None; ^~~~ mismatched types: expected `&mut <generic #2>`, found `uint` <anon>:7 f(42u); ^~~ ``` tend to appear unapproachable to new users. [0] While specific type var IDs are valuable in diagnostics that deal with more than one such variable, in practice many messages only mention one. In those cases, leaving out the specific number makes the messages slightly less terrifying. ```rust mismatched types: expected `core::result::Result<uint, ()>`, found `core::option::Option<_>` <anon>:6 let a: Result<uint, ()> = None; ^~~~ mismatched types: expected `&mut _`, found `uint` <anon>:7 f(42u); ^~~ ``` As you can see, I also tweaked the aesthetics slightly by changing type variables to use the type hole syntax _. For integer variables, the syntax used is: ```rust mismatched types: expected `core::result::Result<uint, ()>`, found `core::option::Option<_#1i>` <anon>:6 let a: Result<uint, ()> = Some(1); ``` and float variables: ```rust mismatched types: expected `core::result::Result<uint, ()>`, found `core::option::Option<_#1f>` <anon>:6 let a: Result<uint, ()> = Some(0.5); ``` [0] https://twitter.com/coda/status/517713085465772032 Closes https://github.com/rust-lang/rust/issues/2632. Closes https://github.com/rust-lang/rust/issues/3404. Closes https://github.com/rust-lang/rust/issues/18426.
This commit is contained in:
commit
82045ca360
@ -1032,10 +1032,8 @@ pub enum type_err {
|
||||
terr_ref_mutability,
|
||||
terr_vec_mutability,
|
||||
terr_tuple_size(expected_found<uint>),
|
||||
terr_fixed_array_size(expected_found<uint>),
|
||||
terr_ty_param_size(expected_found<uint>),
|
||||
terr_record_size(expected_found<uint>),
|
||||
terr_record_mutability,
|
||||
terr_record_fields(expected_found<Ident>),
|
||||
terr_arg_count,
|
||||
terr_regions_does_not_outlive(Region, Region),
|
||||
terr_regions_not_same(Region, Region),
|
||||
@ -3790,8 +3788,8 @@ pub fn ty_sort_string(cx: &ctxt, t: t) -> String {
|
||||
|
||||
ty_enum(id, _) => format!("enum {}", item_path_str(cx, id)),
|
||||
ty_uniq(_) => "box".to_string(),
|
||||
ty_vec(_, Some(_)) => "array".to_string(),
|
||||
ty_vec(_, None) => "unsized array".to_string(),
|
||||
ty_vec(_, Some(n)) => format!("array of {} elements", n),
|
||||
ty_vec(_, None) => "slice".to_string(),
|
||||
ty_ptr(_) => "*-ptr".to_string(),
|
||||
ty_rptr(_, _) => "&-ptr".to_string(),
|
||||
ty_bare_fn(_) => "extern fn".to_string(),
|
||||
@ -3874,27 +3872,18 @@ pub fn type_err_to_str(cx: &ctxt, err: &type_err) -> String {
|
||||
values.expected,
|
||||
values.found)
|
||||
}
|
||||
terr_fixed_array_size(values) => {
|
||||
format!("expected an array with a fixed size of {} elements, \
|
||||
found one with {} elements",
|
||||
values.expected,
|
||||
values.found)
|
||||
}
|
||||
terr_tuple_size(values) => {
|
||||
format!("expected a tuple with {} elements, \
|
||||
found one with {} elements",
|
||||
values.expected,
|
||||
values.found)
|
||||
}
|
||||
terr_record_size(values) => {
|
||||
format!("expected a record with {} fields, \
|
||||
found one with {} fields",
|
||||
values.expected,
|
||||
values.found)
|
||||
}
|
||||
terr_record_mutability => {
|
||||
"record elements differ in mutability".to_string()
|
||||
}
|
||||
terr_record_fields(values) => {
|
||||
format!("expected a record with field `{}`, found one \
|
||||
with field `{}`",
|
||||
token::get_ident(values.expected),
|
||||
token::get_ident(values.found))
|
||||
}
|
||||
terr_arg_count => {
|
||||
"incorrect number of function parameters".to_string()
|
||||
}
|
||||
@ -3923,9 +3912,15 @@ pub fn type_err_to_str(cx: &ctxt, err: &type_err) -> String {
|
||||
trait_store_to_string(cx, (*values).found))
|
||||
}
|
||||
terr_sorts(values) => {
|
||||
format!("expected {}, found {}",
|
||||
ty_sort_string(cx, values.expected),
|
||||
ty_sort_string(cx, values.found))
|
||||
// A naive approach to making sure that we're not reporting silly errors such as:
|
||||
// (expected closure, found closure).
|
||||
let expected_str = ty_sort_string(cx, values.expected);
|
||||
let found_str = ty_sort_string(cx, values.found);
|
||||
if expected_str == found_str {
|
||||
format!("expected {}, found a different {}", expected_str, found_str)
|
||||
} else {
|
||||
format!("expected {}, found {}", expected_str, found_str)
|
||||
}
|
||||
}
|
||||
terr_traits(values) => {
|
||||
format!("expected trait `{}`, found trait `{}`",
|
||||
|
@ -515,6 +515,16 @@ pub fn super_tys<'tcx, C: Combine<'tcx>>(this: &C, a: ty::t, b: ty::t) -> cres<t
|
||||
Ok(ty::mk_rptr(tcx, r, mt))
|
||||
}
|
||||
|
||||
(&ty::ty_vec(a_t, Some(sz_a)), &ty::ty_vec(b_t, Some(sz_b))) => {
|
||||
this.tys(a_t, b_t).and_then(|t| {
|
||||
if sz_a == sz_b {
|
||||
Ok(ty::mk_vec(tcx, t, Some(sz_a)))
|
||||
} else {
|
||||
Err(ty::terr_fixed_array_size(expected_found(this, sz_a, sz_b)))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
(&ty::ty_vec(a_t, sz_a), &ty::ty_vec(b_t, sz_b)) => {
|
||||
this.tys(a_t, b_t).and_then(|t| {
|
||||
if sz_a == sz_b {
|
||||
|
@ -111,7 +111,7 @@ pub trait ErrorReporting {
|
||||
|
||||
fn values_str(&self, values: &ValuePairs) -> Option<String>;
|
||||
|
||||
fn expected_found_str<T:UserString+Resolvable>(
|
||||
fn expected_found_str<T: UserString + Resolvable>(
|
||||
&self,
|
||||
exp_found: &ty::expected_found<T>)
|
||||
-> Option<String>;
|
||||
@ -396,16 +396,12 @@ impl<'a, 'tcx> ErrorReporting for InferCtxt<'a, 'tcx> {
|
||||
* or None if this is a derived error.
|
||||
*/
|
||||
match *values {
|
||||
infer::Types(ref exp_found) => {
|
||||
self.expected_found_str(exp_found)
|
||||
}
|
||||
infer::TraitRefs(ref exp_found) => {
|
||||
self.expected_found_str(exp_found)
|
||||
}
|
||||
infer::Types(ref exp_found) => self.expected_found_str(exp_found),
|
||||
infer::TraitRefs(ref exp_found) => self.expected_found_str(exp_found)
|
||||
}
|
||||
}
|
||||
|
||||
fn expected_found_str<T:UserString+Resolvable>(
|
||||
fn expected_found_str<T: UserString + Resolvable>(
|
||||
&self,
|
||||
exp_found: &ty::expected_found<T>)
|
||||
-> Option<String>
|
||||
|
@ -36,7 +36,8 @@ use syntax::ast;
|
||||
use syntax::codemap;
|
||||
use syntax::codemap::Span;
|
||||
use util::common::indent;
|
||||
use util::ppaux::{bound_region_to_string, ty_to_string, trait_ref_to_string, Repr};
|
||||
use util::ppaux::{bound_region_to_string, ty_to_string};
|
||||
use util::ppaux::{trait_ref_to_string, Repr};
|
||||
|
||||
use self::coercion::Coerce;
|
||||
use self::combine::{Combine, CombineFields};
|
||||
@ -900,31 +901,24 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
err: Option<&ty::type_err>) {
|
||||
debug!("hi! expected_ty = {}, actual_ty = {}", expected_ty, actual_ty);
|
||||
|
||||
let error_str = err.map_or("".to_string(), |t_err| {
|
||||
format!(" ({})", ty::type_err_to_str(self.tcx, t_err))
|
||||
});
|
||||
let resolved_expected = expected_ty.map(|e_ty| {
|
||||
self.resolve_type_vars_if_possible(e_ty)
|
||||
});
|
||||
if !resolved_expected.map_or(false, |e| { ty::type_is_error(e) }) {
|
||||
match resolved_expected {
|
||||
None => {
|
||||
self.tcx
|
||||
.sess
|
||||
.span_err(sp,
|
||||
format!("{}{}",
|
||||
mk_msg(None, actual_ty),
|
||||
error_str).as_slice())
|
||||
|
||||
match resolved_expected {
|
||||
Some(t) if ty::type_is_error(t) => (),
|
||||
_ => {
|
||||
let error_str = err.map_or("".to_string(), |t_err| {
|
||||
format!(" ({})", ty::type_err_to_str(self.tcx, t_err))
|
||||
});
|
||||
|
||||
self.tcx.sess.span_err(sp, format!("{}{}",
|
||||
mk_msg(resolved_expected.map(|t| self.ty_to_string(t)), actual_ty),
|
||||
error_str).as_slice());
|
||||
|
||||
for err in err.iter() {
|
||||
ty::note_and_explain_type_err(self.tcx, *err)
|
||||
}
|
||||
Some(e) => {
|
||||
self.tcx.sess.span_err(sp,
|
||||
format!("{}{}",
|
||||
mk_msg(Some(self.ty_to_string(e)), actual_ty),
|
||||
error_str).as_slice());
|
||||
}
|
||||
}
|
||||
for err in err.iter() {
|
||||
ty::note_and_explain_type_err(self.tcx, *err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -945,25 +939,18 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
}
|
||||
|
||||
pub fn report_mismatched_types(&self,
|
||||
sp: Span,
|
||||
e: ty::t,
|
||||
a: ty::t,
|
||||
span: Span,
|
||||
expected: ty::t,
|
||||
actual: ty::t,
|
||||
err: &ty::type_err) {
|
||||
let resolved_expected =
|
||||
self.resolve_type_vars_if_possible(e);
|
||||
let mk_msg = match ty::get(resolved_expected).sty {
|
||||
// Don't report an error if expected is ty_err
|
||||
ty::ty_err => return,
|
||||
_ => {
|
||||
// if I leave out : String, it infers &str and complains
|
||||
|actual: String| {
|
||||
format!("mismatched types: expected `{}`, found `{}`",
|
||||
self.ty_to_string(resolved_expected),
|
||||
actual)
|
||||
}
|
||||
}
|
||||
let trace = TypeTrace {
|
||||
origin: Misc(span),
|
||||
values: Types(ty::expected_found {
|
||||
expected: expected,
|
||||
found: actual
|
||||
})
|
||||
};
|
||||
self.type_error_message(sp, mk_msg, a, Some(err));
|
||||
self.report_and_explain_type_error(trace, err);
|
||||
}
|
||||
|
||||
pub fn replace_late_bound_regions_with_fresh_regions(&self,
|
||||
|
@ -229,7 +229,9 @@ pub fn mutability_to_string(m: ast::Mutability) -> String {
|
||||
}
|
||||
|
||||
pub fn mt_to_string(cx: &ctxt, m: &mt) -> String {
|
||||
format!("{}{}", mutability_to_string(m.mutbl), ty_to_string(cx, m.ty))
|
||||
format!("{}{}",
|
||||
mutability_to_string(m.mutbl),
|
||||
ty_to_string(cx, m.ty))
|
||||
}
|
||||
|
||||
pub fn trait_store_to_string(cx: &ctxt, s: ty::TraitStore) -> String {
|
||||
@ -256,9 +258,6 @@ pub fn trait_ref_to_string(cx: &ctxt, trait_ref: &ty::TraitRef) -> String {
|
||||
}
|
||||
|
||||
pub fn ty_to_string(cx: &ctxt, typ: t) -> String {
|
||||
fn fn_input_to_string(cx: &ctxt, input: ty::t) -> String {
|
||||
ty_to_string(cx, input).to_string()
|
||||
}
|
||||
fn bare_fn_to_string(cx: &ctxt,
|
||||
fn_style: ast::FnStyle,
|
||||
abi: abi::Abi,
|
||||
@ -340,7 +339,10 @@ pub fn ty_to_string(cx: &ctxt, typ: t) -> String {
|
||||
sig: &ty::FnSig,
|
||||
bounds: &str) {
|
||||
s.push(bra);
|
||||
let strs: Vec<String> = sig.inputs.iter().map(|a| fn_input_to_string(cx, *a)).collect();
|
||||
let strs = sig.inputs
|
||||
.iter()
|
||||
.map(|a| ty_to_string(cx, *a))
|
||||
.collect::<Vec<_>>();
|
||||
s.push_str(strs.connect(", ").as_slice());
|
||||
if sig.variadic {
|
||||
s.push_str(", ...");
|
||||
@ -355,7 +357,7 @@ pub fn ty_to_string(cx: &ctxt, typ: t) -> String {
|
||||
match sig.output {
|
||||
ty::FnConverging(t) => {
|
||||
if !ty::type_is_nil(t) {
|
||||
s.push_str(" -> ");
|
||||
s.push_str(" -> ");
|
||||
s.push_str(ty_to_string(cx, t).as_slice());
|
||||
}
|
||||
}
|
||||
@ -365,82 +367,96 @@ pub fn ty_to_string(cx: &ctxt, typ: t) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
// if there is an id, print that instead of the structural type:
|
||||
/*for def_id in ty::type_def_id(typ).iter() {
|
||||
// note that this typedef cannot have type parameters
|
||||
return ty::item_path_str(cx, *def_id);
|
||||
}*/
|
||||
fn infer_ty_to_string(cx: &ctxt, ty: ty::InferTy) -> String {
|
||||
let print_var_ids = cx.sess.verbose();
|
||||
match ty {
|
||||
ty::TyVar(ty::TyVid { index: vid }) if print_var_ids =>
|
||||
format!("_#{}", vid),
|
||||
ty::IntVar(ty::IntVid { index: vid }) if print_var_ids =>
|
||||
format!("_#{}i", vid),
|
||||
ty::FloatVar(ty::FloatVid { index: vid }) if print_var_ids =>
|
||||
format!("_#{}f", vid),
|
||||
ty::TyVar(_) | ty::IntVar(_) | ty::FloatVar(_) =>
|
||||
"_".to_string(),
|
||||
ty::SkolemizedTy(v) => format!("SkolemizedTy({})", v),
|
||||
ty::SkolemizedIntTy(v) => format!("SkolemizedIntTy({})", v)
|
||||
}
|
||||
}
|
||||
|
||||
// pretty print the structural type representation:
|
||||
return match ty::get(typ).sty {
|
||||
ty_nil => "()".to_string(),
|
||||
ty_bool => "bool".to_string(),
|
||||
ty_char => "char".to_string(),
|
||||
ty_int(t) => ast_util::int_ty_to_string(t, None).to_string(),
|
||||
ty_uint(t) => ast_util::uint_ty_to_string(t, None).to_string(),
|
||||
ty_float(t) => ast_util::float_ty_to_string(t).to_string(),
|
||||
ty_uniq(typ) => format!("Box<{}>", ty_to_string(cx, typ)),
|
||||
ty_ptr(ref tm) => {
|
||||
format!("*{} {}", match tm.mutbl {
|
||||
ast::MutMutable => "mut",
|
||||
ast::MutImmutable => "const",
|
||||
}, ty_to_string(cx, tm.ty))
|
||||
}
|
||||
ty_rptr(r, ref tm) => {
|
||||
let mut buf = region_ptr_to_string(cx, r);
|
||||
buf.push_str(mt_to_string(cx, tm).as_slice());
|
||||
buf
|
||||
}
|
||||
ty_open(typ) => format!("opened<{}>", ty_to_string(cx, typ)),
|
||||
ty_tup(ref elems) => {
|
||||
let strs: Vec<String> = elems.iter().map(|elem| ty_to_string(cx, *elem)).collect();
|
||||
format!("({})", strs.connect(","))
|
||||
}
|
||||
ty_closure(ref f) => {
|
||||
closure_to_string(cx, &**f)
|
||||
}
|
||||
ty_bare_fn(ref f) => {
|
||||
bare_fn_to_string(cx, f.fn_style, f.abi, None, &f.sig)
|
||||
}
|
||||
ty_infer(infer_ty) => infer_ty.to_string(),
|
||||
ty_err => "[type error]".to_string(),
|
||||
ty_param(ref param_ty) => {
|
||||
param_ty.repr(cx)
|
||||
}
|
||||
ty_enum(did, ref substs) | ty_struct(did, ref substs) => {
|
||||
let base = ty::item_path_str(cx, did);
|
||||
let generics = ty::lookup_item_type(cx, did).generics;
|
||||
parameterized(cx, base.as_slice(), substs, &generics)
|
||||
}
|
||||
ty_trait(box ty::TyTrait {
|
||||
def_id: did, ref substs, ref bounds
|
||||
}) => {
|
||||
let base = ty::item_path_str(cx, did);
|
||||
let trait_def = ty::lookup_trait_def(cx, did);
|
||||
let ty = parameterized(cx, base.as_slice(),
|
||||
substs, &trait_def.generics);
|
||||
let bound_str = bounds.user_string(cx);
|
||||
let bound_sep = if bound_str.is_empty() { "" } else { "+" };
|
||||
format!("{}{}{}",
|
||||
ty,
|
||||
bound_sep,
|
||||
bound_str)
|
||||
}
|
||||
ty_str => "str".to_string(),
|
||||
ty_unboxed_closure(ref did, _, ref substs) => {
|
||||
let unboxed_closures = cx.unboxed_closures.borrow();
|
||||
unboxed_closures.find(did).map(|cl| {
|
||||
closure_to_string(cx, &cl.closure_type.subst(cx, substs))
|
||||
}).unwrap_or_else(|| "closure".to_string())
|
||||
}
|
||||
ty_vec(t, sz) => {
|
||||
match sz {
|
||||
Some(n) => {
|
||||
format!("[{}, ..{}]", ty_to_string(cx, t), n)
|
||||
}
|
||||
None => format!("[{}]", ty_to_string(cx, t)),
|
||||
}
|
||||
}
|
||||
match ty::get(typ).sty {
|
||||
ty_nil => "()".to_string(),
|
||||
ty_bool => "bool".to_string(),
|
||||
ty_char => "char".to_string(),
|
||||
ty_int(t) => ast_util::int_ty_to_string(t, None).to_string(),
|
||||
ty_uint(t) => ast_util::uint_ty_to_string(t, None).to_string(),
|
||||
ty_float(t) => ast_util::float_ty_to_string(t).to_string(),
|
||||
ty_uniq(typ) => format!("Box<{}>", ty_to_string(cx, typ)),
|
||||
ty_ptr(ref tm) => {
|
||||
format!("*{} {}", match tm.mutbl {
|
||||
ast::MutMutable => "mut",
|
||||
ast::MutImmutable => "const",
|
||||
}, ty_to_string(cx, tm.ty))
|
||||
}
|
||||
ty_rptr(r, ref tm) => {
|
||||
let mut buf = region_ptr_to_string(cx, r);
|
||||
buf.push_str(mt_to_string(cx, tm).as_slice());
|
||||
buf
|
||||
}
|
||||
ty_open(typ) =>
|
||||
format!("opened<{}>", ty_to_string(cx, typ)),
|
||||
ty_tup(ref elems) => {
|
||||
let strs = elems
|
||||
.iter()
|
||||
.map(|elem| ty_to_string(cx, *elem))
|
||||
.collect::<Vec<_>>();
|
||||
match strs.as_slice() {
|
||||
[ref string] => format!("({},)", string),
|
||||
strs => format!("({})", strs.connect(", "))
|
||||
}
|
||||
}
|
||||
ty_closure(ref f) => {
|
||||
closure_to_string(cx, &**f)
|
||||
}
|
||||
ty_bare_fn(ref f) => {
|
||||
bare_fn_to_string(cx, f.fn_style, f.abi, None, &f.sig)
|
||||
}
|
||||
ty_infer(infer_ty) => infer_ty_to_string(cx, infer_ty),
|
||||
ty_err => "[type error]".to_string(),
|
||||
ty_param(ref param_ty) => param_ty.repr(cx),
|
||||
ty_enum(did, ref substs) | ty_struct(did, ref substs) => {
|
||||
let base = ty::item_path_str(cx, did);
|
||||
let generics = ty::lookup_item_type(cx, did).generics;
|
||||
parameterized(cx, base.as_slice(), substs, &generics)
|
||||
}
|
||||
ty_trait(box ty::TyTrait {
|
||||
def_id: did, ref substs, ref bounds
|
||||
}) => {
|
||||
let base = ty::item_path_str(cx, did);
|
||||
let trait_def = ty::lookup_trait_def(cx, did);
|
||||
let ty = parameterized(cx, base.as_slice(),
|
||||
substs, &trait_def.generics);
|
||||
let bound_str = bounds.user_string(cx);
|
||||
let bound_sep = if bound_str.is_empty() { "" } else { "+" };
|
||||
format!("{}{}{}",
|
||||
ty,
|
||||
bound_sep,
|
||||
bound_str)
|
||||
}
|
||||
ty_str => "str".to_string(),
|
||||
ty_unboxed_closure(ref did, _, ref substs) => {
|
||||
let unboxed_closures = cx.unboxed_closures.borrow();
|
||||
unboxed_closures.find(did).map(|cl| {
|
||||
closure_to_string(cx, &cl.closure_type.subst(cx, substs))
|
||||
}).unwrap_or_else(|| "closure".to_string())
|
||||
}
|
||||
ty_vec(t, sz) => {
|
||||
let inner_str = ty_to_string(cx, t);
|
||||
match sz {
|
||||
Some(n) => format!("[{}, ..{}]", inner_str, n),
|
||||
None => format!("[{}]", inner_str),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -470,15 +486,15 @@ pub fn parameterized(cx: &ctxt,
|
||||
subst::NonerasedRegions(ref regions) => {
|
||||
for &r in regions.iter() {
|
||||
let s = region_to_string(cx, "", false, r);
|
||||
if !s.is_empty() {
|
||||
strs.push(s)
|
||||
} else {
|
||||
if s.is_empty() {
|
||||
// This happens when the value of the region
|
||||
// parameter is not easily serialized. This may be
|
||||
// because the user omitted it in the first place,
|
||||
// or because it refers to some block in the code,
|
||||
// etc. I'm not sure how best to serialize this.
|
||||
strs.push(format!("'_"));
|
||||
} else {
|
||||
strs.push(s)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -515,7 +531,7 @@ pub fn parameterized(cx: &ctxt,
|
||||
}
|
||||
|
||||
if strs.len() > 0u {
|
||||
format!("{}<{}>", base, strs.connect(","))
|
||||
format!("{}<{}>", base, strs.connect(", "))
|
||||
} else {
|
||||
format!("{}", base)
|
||||
}
|
||||
|
@ -9,8 +9,8 @@
|
||||
// except according to those terms.
|
||||
|
||||
fn main() {
|
||||
let _x: int = [1i, 2, 3]; //~ ERROR expected int, found array
|
||||
let _x: int = [1i, 2, 3]; //~ ERROR expected int, found array of 3 elements
|
||||
|
||||
let x: &[int] = &[1, 2, 3];
|
||||
let _y: &int = x; //~ ERROR expected int, found unsized array
|
||||
let _y: &int = x; //~ ERROR expected int, found slice
|
||||
}
|
||||
|
@ -16,10 +16,10 @@ struct Foo<'a,'b> {
|
||||
impl<'a,'b> Foo<'a,'b> {
|
||||
// The number of errors is related to the way invariance works.
|
||||
fn bar(self: Foo<'b,'a>) {}
|
||||
//~^ ERROR mismatched types: expected `Foo<'a,'b>`, found `Foo<'b,'a>`
|
||||
//~^^ ERROR mismatched types: expected `Foo<'a,'b>`, found `Foo<'b,'a>`
|
||||
//~^^^ ERROR mismatched types: expected `Foo<'b,'a>`, found `Foo<'a,'b>`
|
||||
//~^^^^ ERROR mismatched types: expected `Foo<'b,'a>`, found `Foo<'a,'b>`
|
||||
//~^ ERROR mismatched types: expected `Foo<'a, 'b>`, found `Foo<'b, 'a>`
|
||||
//~^^ ERROR mismatched types: expected `Foo<'a, 'b>`, found `Foo<'b, 'a>`
|
||||
//~^^^ ERROR mismatched types: expected `Foo<'b, 'a>`, found `Foo<'a, 'b>`
|
||||
//~^^^^ ERROR mismatched types: expected `Foo<'b, 'a>`, found `Foo<'a, 'b>`
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -29,13 +29,13 @@ fn main() {
|
||||
|
||||
// Including cases where the default is using previous type params.
|
||||
let _: HashMap<String, int> = ();
|
||||
//~^ ERROR mismatched types: expected `HashMap<collections::string::String,int>`, found `()`
|
||||
//~^ ERROR mismatched types: expected `HashMap<collections::string::String, int>`, found `()`
|
||||
let _: HashMap<String, int, Hash<String>> = ();
|
||||
//~^ ERROR mismatched types: expected `HashMap<collections::string::String,int>`, found `()`
|
||||
//~^ ERROR mismatched types: expected `HashMap<collections::string::String, int>`, found `()`
|
||||
|
||||
// But not when there's a different type in between.
|
||||
let _: Foo<A, int, C> = ();
|
||||
//~^ ERROR mismatched types: expected `Foo<A,int>`, found `()`
|
||||
//~^ ERROR mismatched types: expected `Foo<A, int>`, found `()`
|
||||
|
||||
// And don't print <> at all when there's just defaults.
|
||||
let _: Foo<A, B, C> = ();
|
||||
|
15
src/test/compile-fail/integral-variable-unification-error.rs
Normal file
15
src/test/compile-fail/integral-variable-unification-error.rs
Normal file
@ -0,0 +1,15 @@
|
||||
// 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 mut x = 2;
|
||||
x = 5.0;
|
||||
//~^ ERROR expected `_`, found `_` (expected integral variable, found floating-point variable)
|
||||
}
|
21
src/test/compile-fail/issue-13482-2.rs
Normal file
21
src/test/compile-fail/issue-13482-2.rs
Normal file
@ -0,0 +1,21 @@
|
||||
// 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.
|
||||
|
||||
// compile-flags:-Z verbose
|
||||
|
||||
fn main() {
|
||||
let x = [1,2];
|
||||
let y = match x {
|
||||
[] => None,
|
||||
//~^ ERROR types: expected `[_#0i, ..2]`, found `[_#7, ..0]`
|
||||
// (expected array of 2 elements, found array of 0 elements)
|
||||
[a,_] => Some(a)
|
||||
};
|
||||
}
|
@ -12,8 +12,8 @@ fn main() {
|
||||
let x = [1,2];
|
||||
let y = match x {
|
||||
[] => None,
|
||||
//~^ ERROR mismatched types: expected `[<generic integer #0>, ..2]`, found `[<generic #7>, ..0]`
|
||||
// (expected array, found array)
|
||||
//~^ ERROR types: expected `[_, ..2]`, found `[_, ..0]`
|
||||
// (expected array of 2 elements, found array of 0 elements)
|
||||
[a,_] => Some(a)
|
||||
};
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ use std::raw::Slice;
|
||||
|
||||
fn main() {
|
||||
let Slice { data: data, len: len } = "foo";
|
||||
//~^ ERROR mismatched types: expected `&str`, found `core::raw::Slice<<generic #3>>`
|
||||
//~^ ERROR mismatched types: expected `&str`, found `core::raw::Slice<_>`
|
||||
// (expected &-ptr, found struct core::raw::Slice)
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ use std::raw::Slice;
|
||||
fn main() {
|
||||
match () {
|
||||
Slice { data: data, len: len } => (),
|
||||
//~^ ERROR mismatched types: expected `()`, found `core::raw::Slice<<generic #3>>`
|
||||
//~^ ERROR mismatched types: expected `()`, found `core::raw::Slice<_>`
|
||||
// (expected (), found struct core::raw::Slice)
|
||||
_ => unreachable!()
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
fn main() {
|
||||
match None {
|
||||
Err(_) => ()
|
||||
//~^ ERROR mismatched types: expected `core::option::Option<<generic #1>>`
|
||||
// , found `core::result::Result<<generic #2>,<generic #3>>`
|
||||
//~^ ERROR mismatched types: expected `core::option::Option<_>`
|
||||
// , found `core::result::Result<_, _>`
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ fn main() {
|
||||
let a = if true {
|
||||
0
|
||||
} else if false {
|
||||
//~^ ERROR if may be missing an else clause: expected `()`, found `<generic integer #1>`
|
||||
//~^ ERROR if may be missing an else clause: expected `()`, found `_`
|
||||
1
|
||||
};
|
||||
}
|
||||
|
@ -13,6 +13,6 @@
|
||||
const A: (int,int) = (4,2);
|
||||
fn main() {
|
||||
match 42 { A => () }
|
||||
//~^ ERROR mismatched types: expected `<generic integer #0>`, found `(int,int)`
|
||||
//~^ ERROR mismatched types: expected `_`, found `(int, int)`
|
||||
// (expected integral variable, found tuple)
|
||||
}
|
||||
|
@ -13,32 +13,32 @@ enum A { B, C }
|
||||
fn main() {
|
||||
match (true, false) {
|
||||
B => (),
|
||||
//~^ ERROR mismatched types: expected `(bool,bool)`, found `A`
|
||||
// (expected tuple, found enum A)
|
||||
//~^ ERROR mismatched types: expected `(bool, bool)`, found `A` (expected tuple, found enum A)
|
||||
_ => ()
|
||||
}
|
||||
|
||||
match (true, false) {
|
||||
(true, false, false) => ()
|
||||
//~^ ERROR mismatched types: expected `(bool,bool)`,
|
||||
// found `(<generic #7>,<generic #8>,<generic #9>)`
|
||||
// (expected a tuple with 2 elements, found one with 3 elements)
|
||||
//~^ ERROR mismatched types: expected `(bool, bool)`, found `(_, _, _)`
|
||||
}
|
||||
|
||||
match (true, false) {
|
||||
(true, false, false) => ()
|
||||
//~^ ERROR (expected a tuple with 2 elements, found one with 3 elements)
|
||||
}
|
||||
|
||||
match (true, false) {
|
||||
box (true, false) => ()
|
||||
//~^ ERROR mismatched types: expected `(bool,bool)`, found `Box<<generic #15>>`
|
||||
// (expected tuple, found box)
|
||||
//~^ ERROR mismatched types: expected `(bool, bool)`, found `Box<_>` (expected tuple, found box)
|
||||
}
|
||||
|
||||
match (true, false) {
|
||||
&(true, false) => ()
|
||||
//~^ ERROR mismatched types: expected `(bool,bool)`, found `&<generic #21>`
|
||||
// (expected tuple, found &-ptr)
|
||||
//~^ ERROR mismatched types: expected `(bool, bool)`, found `&_` (expected tuple, found &-ptr)
|
||||
}
|
||||
|
||||
|
||||
let v = [('a', 'b') //~ ERROR expected function, found `(char,char)`
|
||||
let v = [('a', 'b') //~ ERROR expected function, found `(char, char)`
|
||||
('c', 'd'),
|
||||
('e', 'f')];
|
||||
|
||||
|
@ -10,5 +10,5 @@
|
||||
|
||||
fn main() {
|
||||
&panic!()
|
||||
//~^ ERROR mismatched types: expected `()`, found `&<generic #2>` (expected (), found &-ptr)
|
||||
//~^ ERROR mismatched types: expected `()`, found `&_` (expected (), found &-ptr)
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ enum Whatever {
|
||||
fn foo(x: Whatever) {
|
||||
match x {
|
||||
Some(field) =>
|
||||
//~^ ERROR: mismatched types: expected `Whatever`, found `core::option::Option<<generic #3>>`
|
||||
//~^ ERROR: mismatched types: expected `Whatever`, found `core::option::Option<_>`
|
||||
field.access(), //~ ERROR the type of this value must be known in this context
|
||||
}
|
||||
}
|
||||
|
@ -14,14 +14,14 @@ mod foo { pub fn bar() {} }
|
||||
|
||||
fn main() {
|
||||
match (true, false) {
|
||||
B => (), //~ ERROR expected `(bool,bool)`, found `A` (expected tuple, found enum A)
|
||||
B => (), //~ ERROR expected `(bool, bool)`, found `A` (expected tuple, found enum A)
|
||||
_ => ()
|
||||
}
|
||||
|
||||
match &Some(42i) {
|
||||
Some(x) => (), //~ ERROR expected `&core::option::Option<int>`,
|
||||
// found `core::option::Option<<generic #4>>`
|
||||
// found `core::option::Option<_>`
|
||||
None => () //~ ERROR expected `&core::option::Option<int>`,
|
||||
// found `core::option::Option<<generic #5>>`
|
||||
// found `core::option::Option<_>`
|
||||
}
|
||||
}
|
||||
|
@ -18,5 +18,5 @@ fn main() {
|
||||
let x: Box<HashMap<int, int>> = box HashMap::new();
|
||||
let x: Box<Map<int, int>> = x;
|
||||
let y: Box<Map<uint, int>> = box x;
|
||||
//~^ ERROR the trait `collections::Map<uint,int>` is not implemented
|
||||
//~^ ERROR the trait `collections::Map<uint, int>` is not implemented
|
||||
}
|
||||
|
@ -11,6 +11,6 @@
|
||||
fn main() {
|
||||
match () {
|
||||
[()] => { }
|
||||
//~^ ERROR mismatched types: expected `()`, found `&[<generic #1>]` (expected (), found &-ptr)
|
||||
//~^ ERROR mismatched types: expected `()`, found `&[_]` (expected (), found &-ptr)
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ fn main() {
|
||||
let c = [0, ..true]; //~ ERROR expected positive integer for repeat count, found boolean
|
||||
//~^ ERROR: expected `uint`, found `bool`
|
||||
let d = [0, ..0.5]; //~ ERROR expected positive integer for repeat count, found float
|
||||
//~^ ERROR: expected `uint`, found `<generic float #0>`
|
||||
//~^ ERROR: expected `uint`, found `_`
|
||||
let e = [0, .."foo"]; //~ ERROR expected positive integer for repeat count, found string
|
||||
//~^ ERROR: expected `uint`, found `&'static str`
|
||||
let f = [0, ..-4];
|
||||
|
@ -13,7 +13,7 @@ struct Foo<T,U>(T);
|
||||
fn main() {
|
||||
match Foo(1.1) {
|
||||
1 => {}
|
||||
//~^ ERROR expected `Foo<<generic float #0>,<generic #2>>`, found `<generic integer #0>`
|
||||
//~^ ERROR expected `Foo<_, _>`, found `_`
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,6 @@
|
||||
|
||||
fn main() {
|
||||
let (x, y) = ();
|
||||
//~^ ERROR types: expected `()`, found `(<generic #3>,<generic #4>)` (expected (), found tuple)
|
||||
//~^ ERROR expected `()`, found `(_, _)` (expected (), found tuple)
|
||||
return x;
|
||||
}
|
||||
|
@ -15,4 +15,7 @@ fn first((value, _): (int, f64)) -> int { value }
|
||||
fn main() {
|
||||
let y = first ((1,2.0,3));
|
||||
//~^ ERROR expected a tuple with 2 elements, found one with 3 elements
|
||||
|
||||
let y = first ((1,));
|
||||
//~^ ERROR expected `(int, f64)`, found `(int,)`
|
||||
}
|
||||
|
@ -22,5 +22,5 @@ fn main() {
|
||||
tuple.0;
|
||||
tuple.1;
|
||||
tuple.2;
|
||||
//~^ ERROR attempted out-of-bounds tuple index `2` on type `(int,int)`
|
||||
//~^ ERROR attempted out-of-bounds tuple index `2` on type `(int, int)`
|
||||
}
|
||||
|
@ -11,6 +11,9 @@
|
||||
// Test that we print out the names of type parameters correctly in
|
||||
// our error messages.
|
||||
|
||||
fn foo<Foo, Bar>(x: Foo) -> Bar { x } //~ ERROR expected `Bar`, found `Foo`
|
||||
fn foo<Foo, Bar>(x: Foo) -> Bar {
|
||||
x
|
||||
//~^ ERROR expected `Bar`, found `Foo` (expected type parameter, found a different type parameter)
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -19,11 +19,11 @@ pub fn main() {
|
||||
|
||||
fn test1() {
|
||||
let x: Foo<_> = Bar::<uint>;
|
||||
//~^ ERROR mismatched types: expected `Foo<<generic #0>>`, found `Bar<uint>`
|
||||
//~^ ERROR mismatched types: expected `Foo<_>`, found `Bar<uint>`
|
||||
let y: Foo<uint> = x;
|
||||
}
|
||||
|
||||
fn test2() {
|
||||
let x: Foo<_> = Bar::<uint>;
|
||||
//~^ ERROR mismatched types: expected `Foo<<generic #0>>`, found `Bar<uint>`
|
||||
//~^ ERROR mismatched types: expected `Foo<_>`, found `Bar<uint>`
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user