diff options
| author | Sean Bowe <ewillbefull@gmail.com> | 2015-04-04 14:30:23 -0600 |
|---|---|---|
| committer | Sean Bowe <ewillbefull@gmail.com> | 2015-04-04 16:29:29 -0600 |
| commit | 3308c06e33855f89627b417fd6b57f76d9df50a1 (patch) | |
| tree | ea78dc8faa6a3b1d830b93e6f4aa70c1ed0ce3a3 | |
| parent | 5f4858e101479859ec950bceefc5e2cda2e0f58e (diff) | |
| download | rust-3308c06e33855f89627b417fd6b57f76d9df50a1.tar.gz rust-3308c06e33855f89627b417fd6b57f76d9df50a1.zip | |
Added test for #24036, using spans to display note/help for this message now
| -rw-r--r-- | src/librustc/middle/infer/error_reporting.rs | 3 | ||||
| -rw-r--r-- | src/librustc/middle/infer/mod.rs | 2 | ||||
| -rw-r--r-- | src/librustc/middle/ty.rs | 7 | ||||
| -rw-r--r-- | src/librustc_typeck/check/mod.rs | 2 | ||||
| -rw-r--r-- | src/librustc_typeck/lib.rs | 2 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-24036.rs | 30 |
6 files changed, 39 insertions, 7 deletions
diff --git a/src/librustc/middle/infer/error_reporting.rs b/src/librustc/middle/infer/error_reporting.rs index cc31e62ca28..03e76f5ee25 100644 --- a/src/librustc/middle/infer/error_reporting.rs +++ b/src/librustc/middle/infer/error_reporting.rs @@ -373,8 +373,9 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> { fn report_and_explain_type_error(&self, trace: TypeTrace<'tcx>, terr: &ty::type_err<'tcx>) { + let span = trace.origin.span(); self.report_type_error(trace, terr); - ty::note_and_explain_type_err(self.tcx, terr); + ty::note_and_explain_type_err(self.tcx, terr, span); } /// Returns a string of the form "expected `{}`, found `{}`", or None if this is a derived diff --git a/src/librustc/middle/infer/mod.rs b/src/librustc/middle/infer/mod.rs index b11e25c059d..0f62b440bf3 100644 --- a/src/librustc/middle/infer/mod.rs +++ b/src/librustc/middle/infer/mod.rs @@ -987,7 +987,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { error_str)); if let Some(err) = err { - ty::note_and_explain_type_err(self.tcx, err) + ty::note_and_explain_type_err(self.tcx, err, sp) } } } diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index ad525387b29..76581529a46 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<'tcx>(cx: &ctxt<'tcx>, err: &type_err<'tcx>) { +pub fn note_and_explain_type_err<'tcx>(cx: &ctxt<'tcx>, err: &type_err<'tcx>, sp: Span) { match *err { terr_regions_does_not_outlive(subregion, superregion) => { 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>) { 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 \ + cx.sess.span_note(sp, &format!("no two closures, even if identical, have the same \ + type")); + cx.sess.span_help(sp, &format!("consider boxing your closure and/or \ using it as a trait object")); } } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 156fbfede9c..ce4eab9988d 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3709,7 +3709,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>, .ty_to_string( actual_structure_type), type_error_description); - ty::note_and_explain_type_err(tcx, &type_error); + ty::note_and_explain_type_err(tcx, &type_error, path.span); } } } diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 9d6c04b1ad4..be3fc860b2b 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -200,7 +200,7 @@ fn require_same_types<'a, 'tcx, M>(tcx: &ty::ctxt<'tcx>, msg(), ty::type_err_to_str(tcx, terr)); - ty::note_and_explain_type_err(tcx, terr); + ty::note_and_explain_type_err(tcx, terr, span); false } } diff --git a/src/test/compile-fail/issue-24036.rs b/src/test/compile-fail/issue-24036.rs new file mode 100644 index 00000000000..3c8a64eaf7d --- /dev/null +++ b/src/test/compile-fail/issue-24036.rs @@ -0,0 +1,30 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn closure_to_loc() { + let mut x = |c| c + 1; + x = |c| c + 1; + //~^ ERROR mismatched types + //~| NOTE no two closures, even if identical, have the same type + //~| HELP consider boxing your closure and/or using it as a trait object +} + +fn closure_from_match() { + let x = match 1usize { + 1 => |c| c + 1, + 2 => |c| c - 1, + _ => |c| c - 1 + }; + //~^^^^^ ERROR match arms have incompatible types + //~| NOTE no two closures, even if identical, have the same type + //~| HELP consider boxing your closure and/or using it as a trait object +} + +fn main() { } |
