From 9567c1c62066a601d0ec88d7874c49881dacc8b2 Mon Sep 17 00:00:00 2001 From: Sean Bowe Date: Fri, 3 Apr 2015 22:42:19 -0600 Subject: [PATCH] Fixed bug calling .note() instead of .help(). Added small note when two different closures fail typechecking. See #24036 --- src/librustc/middle/infer/error_reporting.rs | 2 +- src/librustc/middle/ty.rs | 10 +++++++++- src/librustc/session/mod.rs | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/librustc/middle/infer/error_reporting.rs b/src/librustc/middle/infer/error_reporting.rs index 36229a558e955..cc31e62ca2828 100644 --- a/src/librustc/middle/infer/error_reporting.rs +++ b/src/librustc/middle/infer/error_reporting.rs @@ -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); } } diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 1123c9236312a..8dff4d2e5651e 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -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")); + } + } _ => {} } } diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 3e3e5e17963cd..698b681bd55ae 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -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, msg: &str) -> ! { match opt_sp {