Fixed bug calling .note() instead of .help(). Added small note when two

different closures fail typechecking.

See #24036
This commit is contained in:
Sean Bowe 2015-04-03 22:42:19 -06:00
parent f207ecbe02
commit 9567c1c620
3 changed files with 11 additions and 3 deletions

View file

@ -812,7 +812,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
}
self.give_suggestion(same_regions);
for &(ref trace, terr) in trace_origins {
self.report_type_error(trace.clone(), &terr);
self.report_and_explain_type_error(trace.clone(), &terr);
}
}

View file

@ -5096,7 +5096,7 @@ pub fn type_err_to_str<'tcx>(cx: &ctxt<'tcx>, err: &type_err<'tcx>) -> String {
}
}
pub fn note_and_explain_type_err(cx: &ctxt, err: &type_err) {
pub fn note_and_explain_type_err<'tcx>(cx: &ctxt<'tcx>, err: &type_err<'tcx>) {
match *err {
terr_regions_does_not_outlive(subregion, superregion) => {
note_and_explain_region(cx, "", subregion, "...");
@ -5127,6 +5127,14 @@ pub fn note_and_explain_type_err(cx: &ctxt, err: &type_err) {
"expected concrete lifetime is ",
conc_region, "");
}
terr_sorts(values) => {
let expected_str = ty_sort_string(cx, values.expected);
let found_str = ty_sort_string(cx, values.found);
if expected_str == found_str && expected_str == "closure" {
cx.sess.note(&format!("no two closures, even if identical, have the same type"));
cx.sess.help(&format!("consider boxing your closure and/or using it as a trait object"));
}
}
_ => {}
}
}

View file

@ -155,7 +155,7 @@ impl Session {
self.diagnostic().handler().note(msg)
}
pub fn help(&self, msg: &str) {
self.diagnostic().handler().note(msg)
self.diagnostic().handler().help(msg)
}
pub fn opt_span_bug(&self, opt_sp: Option<Span>, msg: &str) -> ! {
match opt_sp {