Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove note: prefix from type mismatch errors #38902

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/librustc_errors/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_errors/diagnostic_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ impl<'a> DiagnosticBuilder<'a> {
Level::Warning |
Level::Note |
Level::Help |
Level::Expected |
Level::Found |
Level::Cancelled => {
}
}
Expand Down
38 changes: 34 additions & 4 deletions src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<&str>>();
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 {
Expand All @@ -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
Expand Down Expand Up @@ -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(())
}
Expand Down
7 changes: 6 additions & 1 deletion src/librustc_errors/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,9 @@ pub enum Level {
Note,
Help,
Cancelled,
// Expected/Found type/struct/variant
Expected,
Found,
}

impl fmt::Display for Level {
Expand All @@ -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!(),
}
Expand All @@ -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"),
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_errors/snippet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,5 @@ pub enum Style {
NoStyle,
ErrorCode,
Level(Level),
Highlight,
}
4 changes: 2 additions & 2 deletions src/test/compile-fail-fulldeps/proc-macro/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
}
4 changes: 2 additions & 2 deletions src/test/ui/compare-method/reordered-type-param.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ error[E0053]: method `b` has an incompatible type for trait
26 | fn b<F:Clone,G>(&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

4 changes: 2 additions & 2 deletions src/test/ui/mismatched_types/issue-35030.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 2 additions & 2 deletions src/test/ui/mismatched_types/main.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 2 additions & 2 deletions src/test/ui/resolve/token-error-correct-3.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool, std::io::Error>`
= expected type `()`
= found type `std::result::Result<bool, std::io::Error>`
= help: here are some functions which might fulfill your needs:
- .unwrap()
Copy link
Contributor

@durka durka Jan 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider indenting these suggestions? (out of scope for this PR maybe)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that, I'll prepare a separate PR for it.

Copy link
Contributor Author

@estebank estebank Jan 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #38916 for this.

- .unwrap_err()
Expand Down
20 changes: 10 additions & 10 deletions src/test/ui/span/coerce-suggestions.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -30,26 +30,26 @@ 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
|
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
|
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

4 changes: 2 additions & 2 deletions src/test/ui/span/move-closure.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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