Skip to content

Commit

Permalink
Fixed bug calling .note() instead of .help(). Added small note when two
Browse files Browse the repository at this point in the history
different closures fail typechecking.

See rust-lang#24036
  • Loading branch information
ebfull committed Apr 4, 2015
1 parent f207ecb commit 9567c1c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/librustc/middle/infer/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, "...");
Expand Down Expand Up @@ -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"));
}
}
_ => {}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 9567c1c

Please sign in to comment.