Skip to content

Commit 9567c1c

Browse files
committed
Fixed bug calling .note() instead of .help(). Added small note when two
different closures fail typechecking. See #24036
1 parent f207ecb commit 9567c1c

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

src/librustc/middle/infer/error_reporting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
812812
}
813813
self.give_suggestion(same_regions);
814814
for &(ref trace, terr) in trace_origins {
815-
self.report_type_error(trace.clone(), &terr);
815+
self.report_and_explain_type_error(trace.clone(), &terr);
816816
}
817817
}
818818

src/librustc/middle/ty.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5096,7 +5096,7 @@ pub fn type_err_to_str<'tcx>(cx: &ctxt<'tcx>, err: &type_err<'tcx>) -> String {
50965096
}
50975097
}
50985098

5099-
pub fn note_and_explain_type_err(cx: &ctxt, err: &type_err) {
5099+
pub fn note_and_explain_type_err<'tcx>(cx: &ctxt<'tcx>, err: &type_err<'tcx>) {
51005100
match *err {
51015101
terr_regions_does_not_outlive(subregion, superregion) => {
51025102
note_and_explain_region(cx, "", subregion, "...");
@@ -5127,6 +5127,14 @@ pub fn note_and_explain_type_err(cx: &ctxt, err: &type_err) {
51275127
"expected concrete lifetime is ",
51285128
conc_region, "");
51295129
}
5130+
terr_sorts(values) => {
5131+
let expected_str = ty_sort_string(cx, values.expected);
5132+
let found_str = ty_sort_string(cx, values.found);
5133+
if expected_str == found_str && expected_str == "closure" {
5134+
cx.sess.note(&format!("no two closures, even if identical, have the same type"));
5135+
cx.sess.help(&format!("consider boxing your closure and/or using it as a trait object"));
5136+
}
5137+
}
51305138
_ => {}
51315139
}
51325140
}

src/librustc/session/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl Session {
155155
self.diagnostic().handler().note(msg)
156156
}
157157
pub fn help(&self, msg: &str) {
158-
self.diagnostic().handler().note(msg)
158+
self.diagnostic().handler().help(msg)
159159
}
160160
pub fn opt_span_bug(&self, opt_sp: Option<Span>, msg: &str) -> ! {
161161
match opt_sp {

0 commit comments

Comments
 (0)