Skip to content

Commit 3308c06

Browse files
committed
Added test for #24036, using spans to display note/help for this message now
1 parent 5f4858e commit 3308c06

File tree

6 files changed

+39
-7
lines changed

6 files changed

+39
-7
lines changed

src/librustc/middle/infer/error_reporting.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,9 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
373373
fn report_and_explain_type_error(&self,
374374
trace: TypeTrace<'tcx>,
375375
terr: &ty::type_err<'tcx>) {
376+
let span = trace.origin.span();
376377
self.report_type_error(trace, terr);
377-
ty::note_and_explain_type_err(self.tcx, terr);
378+
ty::note_and_explain_type_err(self.tcx, terr, span);
378379
}
379380

380381
/// Returns a string of the form "expected `{}`, found `{}`", or None if this is a derived

src/librustc/middle/infer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
987987
error_str));
988988

989989
if let Some(err) = err {
990-
ty::note_and_explain_type_err(self.tcx, err)
990+
ty::note_and_explain_type_err(self.tcx, err, sp)
991991
}
992992
}
993993
}

src/librustc/middle/ty.rs

Lines changed: 4 additions & 3 deletions
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<'tcx>(cx: &ctxt<'tcx>, err: &type_err<'tcx>) {
5099+
pub fn note_and_explain_type_err<'tcx>(cx: &ctxt<'tcx>, err: &type_err<'tcx>, sp: Span) {
51005100
match *err {
51015101
terr_regions_does_not_outlive(subregion, superregion) => {
51025102
note_and_explain_region(cx, "", subregion, "...");
@@ -5131,8 +5131,9 @@ pub fn note_and_explain_type_err<'tcx>(cx: &ctxt<'tcx>, err: &type_err<'tcx>) {
51315131
let expected_str = ty_sort_string(cx, values.expected);
51325132
let found_str = ty_sort_string(cx, values.found);
51335133
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 \
5134+
cx.sess.span_note(sp, &format!("no two closures, even if identical, have the same \
5135+
type"));
5136+
cx.sess.span_help(sp, &format!("consider boxing your closure and/or \
51365137
using it as a trait object"));
51375138
}
51385139
}

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3709,7 +3709,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
37093709
.ty_to_string(
37103710
actual_structure_type),
37113711
type_error_description);
3712-
ty::note_and_explain_type_err(tcx, &type_error);
3712+
ty::note_and_explain_type_err(tcx, &type_error, path.span);
37133713
}
37143714
}
37153715
}

src/librustc_typeck/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ fn require_same_types<'a, 'tcx, M>(tcx: &ty::ctxt<'tcx>,
200200
msg(),
201201
ty::type_err_to_str(tcx,
202202
terr));
203-
ty::note_and_explain_type_err(tcx, terr);
203+
ty::note_and_explain_type_err(tcx, terr, span);
204204
false
205205
}
206206
}

src/test/compile-fail/issue-24036.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn closure_to_loc() {
12+
let mut x = |c| c + 1;
13+
x = |c| c + 1;
14+
//~^ ERROR mismatched types
15+
//~| NOTE no two closures, even if identical, have the same type
16+
//~| HELP consider boxing your closure and/or using it as a trait object
17+
}
18+
19+
fn closure_from_match() {
20+
let x = match 1usize {
21+
1 => |c| c + 1,
22+
2 => |c| c - 1,
23+
_ => |c| c - 1
24+
};
25+
//~^^^^^ ERROR match arms have incompatible types
26+
//~| NOTE no two closures, even if identical, have the same type
27+
//~| HELP consider boxing your closure and/or using it as a trait object
28+
}
29+
30+
fn main() { }

0 commit comments

Comments
 (0)