diff --git a/src/librustc_errors/diagnostic.rs b/src/librustc_errors/diagnostic.rs index 730ca8f9e2e44..6eaafae982970 100644 --- a/src/librustc_errors/diagnostic.rs +++ b/src/librustc_errors/diagnostic.rs @@ -95,12 +95,18 @@ impl Diagnostic { found_extra: &fmt::Display) -> &mut Self { - // For now, just attach these as notes - self.note(&format!("expected {} `{}`{}", label, expected, expected_extra)); - self.note(&format!(" found {} `{}`{}", label, found, found_extra)); + self.sub(Level::Expected, + &format!("{} `{}`{}", label, expected, expected_extra), + MultiSpan::new(), + None); + self.sub(Level::Found, + &format!("{} `{}`{}", label, found, found_extra), + MultiSpan::new(), + None); self } + pub fn note(&mut self, msg: &str) -> &mut Self { self.sub(Level::Note, msg, MultiSpan::new(), None); self diff --git a/src/librustc_errors/diagnostic_builder.rs b/src/librustc_errors/diagnostic_builder.rs index 7dfea6b8951b0..bb7958e4cb8f2 100644 --- a/src/librustc_errors/diagnostic_builder.rs +++ b/src/librustc_errors/diagnostic_builder.rs @@ -91,6 +91,8 @@ impl<'a> DiagnosticBuilder<'a> { Level::Warning | Level::Note | Level::Help | + Level::Expected | + Level::Found | Level::Cancelled => { } } diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 808fe504b95cd..2c11e707a23ec 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -713,15 +713,39 @@ impl EmitterWriter { -> io::Result<()> { let mut buffer = StyledBuffer::new(); + fn colorize_type_mismatch(buffer: &mut StyledBuffer, msg: &str) { + let msg_split = msg.split('`').collect::>(); + buffer.append(0, msg_split[0], Style::NoStyle); + buffer.append(0, "`", Style::HeaderMsg); + buffer.append(0, msg_split[1], Style::Highlight); + buffer.append(0, "`", Style::HeaderMsg); + buffer.append(0, msg_split[2], Style::NoStyle); + } + if msp.primary_spans().is_empty() && msp.span_labels().is_empty() && is_secondary { // This is a secondary message with no span info for _ in 0..max_line_num_len { buffer.prepend(0, " ", Style::NoStyle); } draw_note_separator(&mut buffer, 0, max_line_num_len + 1); - buffer.append(0, &level.to_string(), Style::HeaderMsg); - buffer.append(0, ": ", Style::NoStyle); - buffer.append(0, msg, Style::NoStyle); + match level { + &Level::Expected => { + buffer.append(0, &level.to_string(), Style::NoStyle); + buffer.append(0, " ", Style::NoStyle); + colorize_type_mismatch(&mut buffer, msg); + } + &Level::Found => { + buffer.append(0, " ", Style::NoStyle); + buffer.append(0, &level.to_string(), Style::NoStyle); + buffer.append(0, " ", Style::NoStyle); + colorize_type_mismatch(&mut buffer, msg); + }, + _ => { + buffer.append(0, &level.to_string(), Style::HeaderMsg); + buffer.append(0, ": ", Style::NoStyle); + buffer.append(0, msg, Style::NoStyle); + } + } } else { buffer.append(0, &level.to_string(), Style::Level(level.clone())); match code { @@ -733,7 +757,12 @@ impl EmitterWriter { _ => {} } buffer.append(0, ": ", Style::HeaderMsg); - buffer.append(0, msg, Style::HeaderMsg); + match level { + &Level::Expected | &Level::Found => { + colorize_type_mismatch(&mut buffer, msg); + } + _ => buffer.append(0, msg, Style::HeaderMsg), + } } // Preprocess all the annotations so that they are grouped by file and by line number @@ -1159,6 +1188,7 @@ impl Destination { self.start_attr(term::Attr::Bold)?; self.start_attr(term::Attr::ForegroundColor(l.color()))?; } + Style::Highlight => self.start_attr(term::Attr::Bold)?, } Ok(()) } diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 09a0c7f9be4ea..cfb7697855ca2 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -496,6 +496,9 @@ pub enum Level { Note, Help, Cancelled, + // Expected/Found type/struct/variant + Expected, + Found, } impl fmt::Display for Level { @@ -515,7 +518,7 @@ impl Level { term::color::YELLOW } } - Note => term::color::BRIGHT_GREEN, + Note | Expected | Found => term::color::BRIGHT_GREEN, Help => term::color::BRIGHT_CYAN, Cancelled => unreachable!(), } @@ -527,6 +530,8 @@ impl Level { Fatal | PhaseFatal | Error => "error", Warning => "warning", Note => "note", + Expected => "expected", + Found => "found", Help => "help", Cancelled => panic!("Shouldn't call on cancelled error"), } diff --git a/src/librustc_errors/snippet.rs b/src/librustc_errors/snippet.rs index b8c1726443db3..18e7b324f081e 100644 --- a/src/librustc_errors/snippet.rs +++ b/src/librustc_errors/snippet.rs @@ -185,4 +185,5 @@ pub enum Style { NoStyle, ErrorCode, Level(Level), + Highlight, } diff --git a/src/test/compile-fail-fulldeps/proc-macro/signature.rs b/src/test/compile-fail-fulldeps/proc-macro/signature.rs index 6d6b5a23e941f..732e45589ad2a 100644 --- a/src/test/compile-fail-fulldeps/proc-macro/signature.rs +++ b/src/test/compile-fail-fulldeps/proc-macro/signature.rs @@ -17,7 +17,7 @@ extern crate proc_macro; pub unsafe extern fn foo(a: i32, b: u32) -> u32 { //~^ ERROR: mismatched types //~| NOTE: expected normal fn, found unsafe fn - //~| NOTE: expected type `fn(proc_macro::TokenStream) -> proc_macro::TokenStream` - //~| NOTE: found type `unsafe extern "C" fn(i32, u32) -> u32 {foo}` + //~| expected type `fn(proc_macro::TokenStream) -> proc_macro::TokenStream` + //~| found type `unsafe extern "C" fn(i32, u32) -> u32 {foo}` loop {} } diff --git a/src/test/ui/compare-method/reordered-type-param.stderr b/src/test/ui/compare-method/reordered-type-param.stderr index 985b85cc4ec40..61551b35c3e19 100644 --- a/src/test/ui/compare-method/reordered-type-param.stderr +++ b/src/test/ui/compare-method/reordered-type-param.stderr @@ -7,8 +7,8 @@ error[E0053]: method `b` has an incompatible type for trait 26 | fn b(&self, _x: G) -> G { panic!() } //~ ERROR method `b` has an incompatible type | ^ expected type parameter, found a different type parameter | - = note: expected type `fn(&E, F) -> F` - = note: found type `fn(&E, G) -> G` + = expected type `fn(&E, F) -> F` + = found type `fn(&E, G) -> G` error: aborting due to previous error diff --git a/src/test/ui/mismatched_types/issue-35030.stderr b/src/test/ui/mismatched_types/issue-35030.stderr index aa017297a4e15..60b6202ee02c1 100644 --- a/src/test/ui/mismatched_types/issue-35030.stderr +++ b/src/test/ui/mismatched_types/issue-35030.stderr @@ -4,8 +4,8 @@ error[E0308]: mismatched types 19 | Some(true) | ^^^^ expected type parameter, found bool | - = note: expected type `bool` (type parameter) - = note: found type `bool` (bool) + = expected type `bool` (type parameter) + = found type `bool` (bool) error: aborting due to previous error diff --git a/src/test/ui/mismatched_types/main.stderr b/src/test/ui/mismatched_types/main.stderr index c87b635521eab..7f74bae5d3ba4 100644 --- a/src/test/ui/mismatched_types/main.stderr +++ b/src/test/ui/mismatched_types/main.stderr @@ -6,8 +6,8 @@ error[E0308]: mismatched types 13 | | ); | |_____^ ...ending here: expected u32, found () | - = note: expected type `u32` - = note: found type `()` + = expected type `u32` + = found type `()` error: aborting due to previous error diff --git a/src/test/ui/mismatched_types/trait-impl-fn-incompatibility.stderr b/src/test/ui/mismatched_types/trait-impl-fn-incompatibility.stderr index 4a0ccc46525d0..9ce478586b726 100644 --- a/src/test/ui/mismatched_types/trait-impl-fn-incompatibility.stderr +++ b/src/test/ui/mismatched_types/trait-impl-fn-incompatibility.stderr @@ -16,8 +16,8 @@ error[E0053]: method `bar` has an incompatible type for trait 22 | fn bar(&mut self, bar: &Bar) { } | ^^^^ types differ in mutability | - = note: expected type `fn(&mut Bar, &mut Bar)` - = note: found type `fn(&mut Bar, &Bar)` + = expected type `fn(&mut Bar, &mut Bar)` + = found type `fn(&mut Bar, &Bar)` error: aborting due to 2 previous errors diff --git a/src/test/ui/resolve/token-error-correct-3.stderr b/src/test/ui/resolve/token-error-correct-3.stderr index 0b15c23909ca6..fdec0f1ef3869 100644 --- a/src/test/ui/resolve/token-error-correct-3.stderr +++ b/src/test/ui/resolve/token-error-correct-3.stderr @@ -34,8 +34,8 @@ error[E0308]: mismatched types 25 | fs::create_dir_all(path.as_ref()).map(|()| true) //~ ERROR: mismatched types | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found enum `std::result::Result` | - = note: expected type `()` - = note: found type `std::result::Result` + = expected type `()` + = found type `std::result::Result` = help: here are some functions which might fulfill your needs: - .unwrap() - .unwrap_err() diff --git a/src/test/ui/span/coerce-suggestions.stderr b/src/test/ui/span/coerce-suggestions.stderr index e316466150703..295d5555c02f3 100644 --- a/src/test/ui/span/coerce-suggestions.stderr +++ b/src/test/ui/span/coerce-suggestions.stderr @@ -4,8 +4,8 @@ error[E0308]: mismatched types 17 | let x: usize = String::new(); | ^^^^^^^^^^^^^ expected usize, found struct `std::string::String` | - = note: expected type `usize` - = note: found type `std::string::String` + = expected type `usize` + = found type `std::string::String` = help: here are some functions which might fulfill your needs: - .capacity() - .len() @@ -16,8 +16,8 @@ error[E0308]: mismatched types 23 | let x: &str = String::new(); | ^^^^^^^^^^^^^ expected &str, found struct `std::string::String` | - = note: expected type `&str` - = note: found type `std::string::String` + = expected type `&str` + = found type `std::string::String` = help: here are some functions which might fulfill your needs: - .as_str() - .trim() @@ -30,8 +30,8 @@ error[E0308]: mismatched types 30 | test(&y); | ^^ types differ in mutability | - = note: expected type `&mut std::string::String` - = note: found type `&std::string::String` + = expected type `&mut std::string::String` + = found type `&std::string::String` error[E0308]: mismatched types --> $DIR/coerce-suggestions.rs:36:11 @@ -39,8 +39,8 @@ error[E0308]: mismatched types 36 | test2(&y); | ^^ types differ in mutability | - = note: expected type `&mut i32` - = note: found type `&std::string::String` + = expected type `&mut i32` + = found type `&std::string::String` error[E0308]: mismatched types --> $DIR/coerce-suggestions.rs:42:9 @@ -48,8 +48,8 @@ error[E0308]: mismatched types 42 | f = box f; | ^^^^^ cyclic type of infinite size | - = note: expected type `_` - = note: found type `Box<_>` + = expected type `_` + = found type `Box<_>` error: aborting due to 5 previous errors diff --git a/src/test/ui/span/move-closure.stderr b/src/test/ui/span/move-closure.stderr index 251feded167d8..369d2f9ba7881 100644 --- a/src/test/ui/span/move-closure.stderr +++ b/src/test/ui/span/move-closure.stderr @@ -4,8 +4,8 @@ error[E0308]: mismatched types 15 | let x: () = move || (); | ^^^^^^^^^^ expected (), found closure | - = note: expected type `()` - = note: found type `[closure@$DIR/move-closure.rs:15:17: 15:27]` + = expected type `()` + = found type `[closure@$DIR/move-closure.rs:15:17: 15:27]` error: aborting due to previous error