diff --git a/src/librustc/infer/error_reporting.rs b/src/librustc/infer/error_reporting.rs index b8a3bdfcf25738ad44937886569cdf19796e04c2..2792968d427aa95d39b99bf2e6e2202bd6800153 100644 --- a/src/librustc/infer/error_reporting.rs +++ b/src/librustc/infer/error_reporting.rs @@ -547,7 +547,18 @@ pub fn note_type_err(&self, }; if !is_simple_error { - diag.note_expected_found(&"type", &expected, &found); + if expected == found { + if let &TypeError::Sorts(ref values) = terr { + diag.note_expected_found_extra( + &"type", &expected, &found, + &format!(" ({})", values.expected.sort_string(self.tcx)), + &format!(" ({})", values.found.sort_string(self.tcx))); + } else { + diag.note_expected_found(&"type", &expected, &found); + } + } else { + diag.note_expected_found(&"type", &expected, &found); + } } } diff --git a/src/librustc/ty/error.rs b/src/librustc/ty/error.rs index d820fddea3907d38a754d29cff3a620eaeeea6e1..001f47af68c3bf67b0727f6425a2040eb5c0ef32 100644 --- a/src/librustc/ty/error.rs +++ b/src/librustc/ty/error.rs @@ -210,7 +210,7 @@ fn report_maybe_different(f: &mut fmt::Formatter, } impl<'a, 'gcx, 'lcx, 'tcx> ty::TyS<'tcx> { - fn sort_string(&self, tcx: TyCtxt<'a, 'gcx, 'lcx>) -> String { + pub fn sort_string(&self, tcx: TyCtxt<'a, 'gcx, 'lcx>) -> String { match self.sty { ty::TyBool | ty::TyChar | ty::TyInt(_) | ty::TyUint(_) | ty::TyFloat(_) | ty::TyStr | ty::TyNever => self.to_string(), diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index d82d7dbe70f920afcfb53f0c1bce044c2407da5f..d2f3eea85f2285ea4e10e3ab26e4fe9b4ad854df 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -273,10 +273,21 @@ pub fn note_expected_found(&mut self, expected: &fmt::Display, found: &fmt::Display) -> &mut DiagnosticBuilder<'a> + { + self.note_expected_found_extra(label, expected, found, &"", &"") + } + + pub fn note_expected_found_extra(&mut self, + label: &fmt::Display, + expected: &fmt::Display, + found: &fmt::Display, + expected_extra: &fmt::Display, + found_extra: &fmt::Display) + -> &mut DiagnosticBuilder<'a> { // For now, just attach these as notes - self.note(&format!("expected {} `{}`", label, expected)); - self.note(&format!(" found {} `{}`", label, found)); + self.note(&format!("expected {} `{}`{}", label, expected, expected_extra)); + self.note(&format!(" found {} `{}`{}", label, found, found_extra)); self } @@ -764,4 +775,4 @@ pub fn expect(diag: &Handler, opt: Option, msg: M) -> T where Some(t) => t, None => diag.bug(&msg()), } -} \ No newline at end of file +} diff --git a/src/test/ui/mismatched_types/issue-35030.rs b/src/test/ui/mismatched_types/issue-35030.rs new file mode 100644 index 0000000000000000000000000000000000000000..006074ead13bdb8666156f483756a1a673ed46ed --- /dev/null +++ b/src/test/ui/mismatched_types/issue-35030.rs @@ -0,0 +1,25 @@ +// Copyright 2016 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// rustc-env:RUST_NEW_ERROR_FORMAT + +trait Parser { + fn parse(text: &str) -> Option; +} + +impl Parser for bool { + fn parse(text: &str) -> Option { + Some(true) + } +} + +fn main() { + println!("{}", bool::parse("ok").unwrap_or(false)); +} diff --git a/src/test/ui/mismatched_types/issue-35030.stderr b/src/test/ui/mismatched_types/issue-35030.stderr new file mode 100644 index 0000000000000000000000000000000000000000..aa017297a4e154a8d2ec1626aaaa0f28803ce459 --- /dev/null +++ b/src/test/ui/mismatched_types/issue-35030.stderr @@ -0,0 +1,11 @@ +error[E0308]: mismatched types + --> $DIR/issue-35030.rs:19:14 + | +19 | Some(true) + | ^^^^ expected type parameter, found bool + | + = note: expected type `bool` (type parameter) + = note: found type `bool` (bool) + +error: aborting due to previous error +