Skip to content

Commit 909bd69

Browse files
committed
Remove note: prefix from type mismatch errors
Given file ``` fn main() { let x: usize = ""; } ``` provide the following output ```rust error[E0308]: mismatched types --> file.rs:2:20 | 2 | let x: usize = ""; | ^^ expected usize, found reference | = expected type `usize` = found type `&'static str` = help: here are some functions which might fulfill your needs: - .len() ```
1 parent 7e38a89 commit 909bd69

11 files changed

+45
-28
lines changed

src/librustc_errors/diagnostic.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,13 @@ impl Diagnostic {
9696
-> &mut Self
9797
{
9898
// For now, just attach these as notes
99-
self.note(&format!("expected {} `{}`{}", label, expected, expected_extra));
100-
self.note(&format!(" found {} `{}`{}", label, found, found_extra));
99+
self.top_level_note(&format!("expected {} `{}`{}", label, expected, expected_extra));
100+
self.top_level_note(&format!(" found {} `{}`{}", label, found, found_extra));
101+
self
102+
}
103+
104+
pub fn top_level_note(&mut self, msg: &str) -> &mut Self {
105+
self.sub(Level::TopLevel, msg, MultiSpan::new(), None);
101106
self
102107
}
103108

src/librustc_errors/diagnostic_builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ impl<'a> DiagnosticBuilder<'a> {
9191
Level::Warning |
9292
Level::Note |
9393
Level::Help |
94+
Level::TopLevel |
9495
Level::Cancelled => {
9596
}
9697
}

src/librustc_errors/emitter.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -719,11 +719,19 @@ impl EmitterWriter {
719719
buffer.prepend(0, " ", Style::NoStyle);
720720
}
721721
draw_note_separator(&mut buffer, 0, max_line_num_len + 1);
722-
buffer.append(0, &level.to_string(), Style::HeaderMsg);
723-
buffer.append(0, ": ", Style::NoStyle);
722+
match level {
723+
&Level::TopLevel => (),
724+
_ => {
725+
buffer.append(0, &level.to_string(), Style::HeaderMsg);
726+
buffer.append(0, ": ", Style::NoStyle);
727+
}
728+
}
724729
buffer.append(0, msg, Style::NoStyle);
725730
} else {
726-
buffer.append(0, &level.to_string(), Style::Level(level.clone()));
731+
match level {
732+
&Level::TopLevel => (),
733+
_ => buffer.append(0, &level.to_string(), Style::Level(level.clone())),
734+
}
727735
match code {
728736
&Some(ref code) => {
729737
buffer.append(0, "[", Style::Level(level.clone()));

src/librustc_errors/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,8 @@ pub enum Level {
496496
Note,
497497
Help,
498498
Cancelled,
499+
// A note without the `note: ` prefix in the presentation
500+
TopLevel,
499501
}
500502

501503
impl fmt::Display for Level {
@@ -515,7 +517,7 @@ impl Level {
515517
term::color::YELLOW
516518
}
517519
}
518-
Note => term::color::BRIGHT_GREEN,
520+
Note | TopLevel => term::color::BRIGHT_GREEN,
519521
Help => term::color::BRIGHT_CYAN,
520522
Cancelled => unreachable!(),
521523
}
@@ -527,6 +529,7 @@ impl Level {
527529
Fatal | PhaseFatal | Error => "error",
528530
Warning => "warning",
529531
Note => "note",
532+
TopLevel => "note",
530533
Help => "help",
531534
Cancelled => panic!("Shouldn't call on cancelled error"),
532535
}

src/test/ui/compare-method/reordered-type-param.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ error[E0053]: method `b` has an incompatible type for trait
77
26 | fn b<F:Clone,G>(&self, _x: G) -> G { panic!() } //~ ERROR method `b` has an incompatible type
88
| ^ expected type parameter, found a different type parameter
99
|
10-
= note: expected type `fn(&E, F) -> F`
11-
= note: found type `fn(&E, G) -> G`
10+
= expected type `fn(&E, F) -> F`
11+
= found type `fn(&E, G) -> G`
1212

1313
error: aborting due to previous error
1414

src/test/ui/mismatched_types/issue-35030.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error[E0308]: mismatched types
44
19 | Some(true)
55
| ^^^^ expected type parameter, found bool
66
|
7-
= note: expected type `bool` (type parameter)
8-
= note: found type `bool` (bool)
7+
= expected type `bool` (type parameter)
8+
= found type `bool` (bool)
99

1010
error: aborting due to previous error
1111

src/test/ui/mismatched_types/main.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ error[E0308]: mismatched types
66
13 | | );
77
| |_____^ ...ending here: expected u32, found ()
88
|
9-
= note: expected type `u32`
10-
= note: found type `()`
9+
= expected type `u32`
10+
= found type `()`
1111

1212
error: aborting due to previous error
1313

src/test/ui/mismatched_types/trait-impl-fn-incompatibility.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ error[E0053]: method `bar` has an incompatible type for trait
1616
22 | fn bar(&mut self, bar: &Bar) { }
1717
| ^^^^ types differ in mutability
1818
|
19-
= note: expected type `fn(&mut Bar, &mut Bar)`
20-
= note: found type `fn(&mut Bar, &Bar)`
19+
= expected type `fn(&mut Bar, &mut Bar)`
20+
= found type `fn(&mut Bar, &Bar)`
2121

2222
error: aborting due to 2 previous errors
2323

src/test/ui/resolve/token-error-correct-3.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ error[E0308]: mismatched types
3434
25 | fs::create_dir_all(path.as_ref()).map(|()| true) //~ ERROR: mismatched types
3535
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found enum `std::result::Result`
3636
|
37-
= note: expected type `()`
38-
= note: found type `std::result::Result<bool, std::io::Error>`
37+
= expected type `()`
38+
= found type `std::result::Result<bool, std::io::Error>`
3939
= help: here are some functions which might fulfill your needs:
4040
- .unwrap()
4141
- .unwrap_err()

src/test/ui/span/coerce-suggestions.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error[E0308]: mismatched types
44
17 | let x: usize = String::new();
55
| ^^^^^^^^^^^^^ expected usize, found struct `std::string::String`
66
|
7-
= note: expected type `usize`
8-
= note: found type `std::string::String`
7+
= expected type `usize`
8+
= found type `std::string::String`
99
= help: here are some functions which might fulfill your needs:
1010
- .capacity()
1111
- .len()
@@ -16,8 +16,8 @@ error[E0308]: mismatched types
1616
23 | let x: &str = String::new();
1717
| ^^^^^^^^^^^^^ expected &str, found struct `std::string::String`
1818
|
19-
= note: expected type `&str`
20-
= note: found type `std::string::String`
19+
= expected type `&str`
20+
= found type `std::string::String`
2121
= help: here are some functions which might fulfill your needs:
2222
- .as_str()
2323
- .trim()
@@ -30,26 +30,26 @@ error[E0308]: mismatched types
3030
30 | test(&y);
3131
| ^^ types differ in mutability
3232
|
33-
= note: expected type `&mut std::string::String`
34-
= note: found type `&std::string::String`
33+
= expected type `&mut std::string::String`
34+
= found type `&std::string::String`
3535

3636
error[E0308]: mismatched types
3737
--> $DIR/coerce-suggestions.rs:36:11
3838
|
3939
36 | test2(&y);
4040
| ^^ types differ in mutability
4141
|
42-
= note: expected type `&mut i32`
43-
= note: found type `&std::string::String`
42+
= expected type `&mut i32`
43+
= found type `&std::string::String`
4444

4545
error[E0308]: mismatched types
4646
--> $DIR/coerce-suggestions.rs:42:9
4747
|
4848
42 | f = box f;
4949
| ^^^^^ cyclic type of infinite size
5050
|
51-
= note: expected type `_`
52-
= note: found type `Box<_>`
51+
= expected type `_`
52+
= found type `Box<_>`
5353

5454
error: aborting due to 5 previous errors
5555

src/test/ui/span/move-closure.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error[E0308]: mismatched types
44
15 | let x: () = move || ();
55
| ^^^^^^^^^^ expected (), found closure
66
|
7-
= note: expected type `()`
8-
= note: found type `[closure@$DIR/move-closure.rs:15:17: 15:27]`
7+
= expected type `()`
8+
= found type `[closure@$DIR/move-closure.rs:15:17: 15:27]`
99

1010
error: aborting due to previous error
1111

0 commit comments

Comments
 (0)