Skip to content

Commit 1d69925

Browse files
committed
Tweak diff printing
When highlighting type comparisons, if both sides are for the same type, we use only the type name instead of the full def path. This is beneficial when we are dealing with longer, more complex types where it is easy to lose track of where we are, so reducing the verbosity a bit in an element that doesn't contribute to the users' understanding is a net positive.
1 parent 0681ba9 commit 1d69925

9 files changed

+38
-36
lines changed

compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
925925
let path1 = self.tcx.def_path_str(did1);
926926
let path2 = self.tcx.def_path_str(did2);
927927
if did1 == did2 {
928+
let path1 = self.tcx.item_name(did1).to_string();
929+
let path2 = self.tcx.item_name(did2).to_string();
928930
// Easy case. Replace same types with `_` to shorten the output and highlight
929931
// the differing ones.
930932
// let x: Foo<Bar, Qux> = y::<Foo<Quz, Qux>>();

tests/ui/higher-ranked/higher-ranked-lifetime-equality.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ error[E0308]: mismatched types
44
LL | let foo: Foo<Two> = foo;
55
| ^^^ one type is more general than the other
66
|
7-
= note: expected struct `my_api::Foo<for<'a, 'b> fn(&'a (), &'b ())>`
8-
found struct `my_api::Foo<for<'a> fn(&'a (), &'a ())>`
7+
= note: expected struct `Foo<for<'a, 'b> fn(&'a (), &'b ())>`
8+
found struct `Foo<for<'a> fn(&'a (), &'a ())>`
99

1010
error[E0308]: mismatched types
1111
--> $DIR/higher-ranked-lifetime-equality.rs:34:25
1212
|
1313
LL | let foo: Foo<Two> = foo;
1414
| ^^^ one type is more general than the other
1515
|
16-
= note: expected struct `my_api::Foo<for<'a, 'b> fn(&'a (), &'b ())>`
17-
found struct `my_api::Foo<for<'a> fn(&'a (), &'a ())>`
16+
= note: expected struct `Foo<for<'a, 'b> fn(&'a (), &'b ())>`
17+
found struct `Foo<for<'a> fn(&'a (), &'a ())>`
1818
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
1919

2020
error: aborting due to 2 previous errors

tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ LL | type Foo = impl PartialEq<(Foo, i32)>;
77
LL | fn eq(&self, _other: &(Foo, i32)) -> bool {
88
| ^^^^^^^^^^^ expected `a::Bar`, found opaque type
99
|
10-
= note: expected signature `fn(&a::Bar, &(a::Bar, _)) -> _`
11-
found signature `fn(&a::Bar, &(a::Foo, _)) -> _`
10+
= note: expected signature `fn(&Bar, &(a::Bar, _)) -> _`
11+
found signature `fn(&Bar, &(a::Foo, _)) -> _`
1212
help: change the parameter type to match the trait
1313
|
1414
LL | fn eq(&self, _other: &(a::Bar, i32)) -> bool {
@@ -44,8 +44,8 @@ LL | type Foo = impl PartialEq<(Foo, i32)>;
4444
LL | fn eq(&self, _other: &(Bar, i32)) -> bool {
4545
| ^^^^^^^^^^^ expected opaque type, found `b::Bar`
4646
|
47-
= note: expected signature `fn(&b::Bar, &(b::Foo, _)) -> _`
48-
found signature `fn(&b::Bar, &(b::Bar, _)) -> _`
47+
= note: expected signature `fn(&Bar, &(b::Foo, _)) -> _`
48+
found signature `fn(&Bar, &(b::Bar, _)) -> _`
4949
note: this item must have the opaque type in its signature in order to be able to register hidden types
5050
--> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:25:12
5151
|

tests/ui/proc-macro/proc-macro-abi.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@ error: function-like proc macro has incorrect signature
44
LL | pub extern "C" fn abi(a: TokenStream) -> TokenStream {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected "Rust" fn, found "C" fn
66
|
7-
= note: expected signature `fn(proc_macro::TokenStream) -> proc_macro::TokenStream`
8-
found signature `extern "C" fn(proc_macro::TokenStream) -> proc_macro::TokenStream`
7+
= note: expected signature `fn(TokenStream) -> TokenStream`
8+
found signature `extern "C" fn(TokenStream) -> TokenStream`
99

1010
error: function-like proc macro has incorrect signature
1111
--> $DIR/proc-macro-abi.rs:17:1
1212
|
1313
LL | pub extern "system" fn abi2(a: TokenStream) -> TokenStream {
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected "Rust" fn, found "system" fn
1515
|
16-
= note: expected signature `fn(proc_macro::TokenStream) -> proc_macro::TokenStream`
17-
found signature `extern "system" fn(proc_macro::TokenStream) -> proc_macro::TokenStream`
16+
= note: expected signature `fn(TokenStream) -> TokenStream`
17+
found signature `extern "system" fn(TokenStream) -> TokenStream`
1818

1919
error: function-like proc macro has incorrect signature
2020
--> $DIR/proc-macro-abi.rs:23:1
2121
|
2222
LL | pub extern fn abi3(a: TokenStream) -> TokenStream {
2323
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected "Rust" fn, found "C" fn
2424
|
25-
= note: expected signature `fn(proc_macro::TokenStream) -> proc_macro::TokenStream`
26-
found signature `extern "C" fn(proc_macro::TokenStream) -> proc_macro::TokenStream`
25+
= note: expected signature `fn(TokenStream) -> TokenStream`
26+
found signature `extern "C" fn(TokenStream) -> TokenStream`
2727

2828
error: aborting due to 3 previous errors
2929

tests/ui/proc-macro/signature-proc-macro-attribute.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error: attribute proc macro has incorrect signature
44
LL | pub fn bad_input(input: String) -> TokenStream {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ incorrect number of function parameters
66
|
7-
= note: expected signature `fn(proc_macro::TokenStream, proc_macro::TokenStream) -> proc_macro::TokenStream`
8-
found signature `fn(std::string::String) -> proc_macro::TokenStream`
7+
= note: expected signature `fn(proc_macro::TokenStream, proc_macro::TokenStream) -> TokenStream`
8+
found signature `fn(std::string::String) -> TokenStream`
99

1010
error: attribute proc macro has incorrect signature
1111
--> $DIR/signature-proc-macro-attribute.rs:16:1
@@ -31,8 +31,8 @@ error: attribute proc macro has incorrect signature
3131
LL | pub fn too_many(a: TokenStream, b: TokenStream, c: String) -> TokenStream {
3232
| ^^^^^^ incorrect number of function parameters
3333
|
34-
= note: expected signature `fn(proc_macro::TokenStream, proc_macro::TokenStream) -> proc_macro::TokenStream`
35-
found signature `fn(proc_macro::TokenStream, proc_macro::TokenStream, std::string::String) -> proc_macro::TokenStream`
34+
= note: expected signature `fn(proc_macro::TokenStream, proc_macro::TokenStream) -> TokenStream`
35+
found signature `fn(proc_macro::TokenStream, proc_macro::TokenStream, std::string::String) -> TokenStream`
3636

3737
error: aborting due to 4 previous errors
3838

tests/ui/proc-macro/signature-proc-macro-derive.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ error: derive proc macro has incorrect signature
44
LL | pub fn bad_input(input: String) -> TokenStream {
55
| ^^^^^^ expected `proc_macro::TokenStream`, found `std::string::String`
66
|
7-
= note: expected signature `fn(proc_macro::TokenStream) -> proc_macro::TokenStream`
8-
found signature `fn(std::string::String) -> proc_macro::TokenStream`
7+
= note: expected signature `fn(proc_macro::TokenStream) -> TokenStream`
8+
found signature `fn(std::string::String) -> TokenStream`
99

1010
error: derive proc macro has incorrect signature
1111
--> $DIR/signature-proc-macro-derive.rs:16:42
1212
|
1313
LL | pub fn bad_output(input: TokenStream) -> String {
1414
| ^^^^^^ expected `proc_macro::TokenStream`, found `std::string::String`
1515
|
16-
= note: expected signature `fn(proc_macro::TokenStream) -> proc_macro::TokenStream`
17-
found signature `fn(proc_macro::TokenStream) -> std::string::String`
16+
= note: expected signature `fn(TokenStream) -> proc_macro::TokenStream`
17+
found signature `fn(TokenStream) -> std::string::String`
1818

1919
error: derive proc macro has incorrect signature
2020
--> $DIR/signature-proc-macro-derive.rs:22:30
@@ -31,8 +31,8 @@ error: derive proc macro has incorrect signature
3131
LL | pub fn too_many(a: TokenStream, b: TokenStream, c: String) -> TokenStream {
3232
| ^^^^^^^^^^^ incorrect number of function parameters
3333
|
34-
= note: expected signature `fn(proc_macro::TokenStream) -> proc_macro::TokenStream`
35-
found signature `fn(proc_macro::TokenStream, proc_macro::TokenStream, std::string::String) -> proc_macro::TokenStream`
34+
= note: expected signature `fn(proc_macro::TokenStream) -> TokenStream`
35+
found signature `fn(proc_macro::TokenStream, proc_macro::TokenStream, std::string::String) -> TokenStream`
3636

3737
error: aborting due to 4 previous errors
3838

tests/ui/proc-macro/signature-proc-macro.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ error: function-like proc macro has incorrect signature
44
LL | pub fn bad_input(input: String) -> TokenStream {
55
| ^^^^^^ expected `proc_macro::TokenStream`, found `std::string::String`
66
|
7-
= note: expected signature `fn(proc_macro::TokenStream) -> proc_macro::TokenStream`
8-
found signature `fn(std::string::String) -> proc_macro::TokenStream`
7+
= note: expected signature `fn(proc_macro::TokenStream) -> TokenStream`
8+
found signature `fn(std::string::String) -> TokenStream`
99

1010
error: function-like proc macro has incorrect signature
1111
--> $DIR/signature-proc-macro.rs:16:42
1212
|
1313
LL | pub fn bad_output(input: TokenStream) -> String {
1414
| ^^^^^^ expected `proc_macro::TokenStream`, found `std::string::String`
1515
|
16-
= note: expected signature `fn(proc_macro::TokenStream) -> proc_macro::TokenStream`
17-
found signature `fn(proc_macro::TokenStream) -> std::string::String`
16+
= note: expected signature `fn(TokenStream) -> proc_macro::TokenStream`
17+
found signature `fn(TokenStream) -> std::string::String`
1818

1919
error: function-like proc macro has incorrect signature
2020
--> $DIR/signature-proc-macro.rs:22:30
@@ -31,8 +31,8 @@ error: function-like proc macro has incorrect signature
3131
LL | pub fn too_many(a: TokenStream, b: TokenStream, c: String) -> TokenStream {
3232
| ^^^^^^^^^^^ incorrect number of function parameters
3333
|
34-
= note: expected signature `fn(proc_macro::TokenStream) -> proc_macro::TokenStream`
35-
found signature `fn(proc_macro::TokenStream, proc_macro::TokenStream, std::string::String) -> proc_macro::TokenStream`
34+
= note: expected signature `fn(proc_macro::TokenStream) -> TokenStream`
35+
found signature `fn(proc_macro::TokenStream, proc_macro::TokenStream, std::string::String) -> TokenStream`
3636

3737
error: aborting due to 4 previous errors
3838

tests/ui/range/issue-73553-misinterp-range-literal.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ LL | demo(tell(1)..tell(10));
66
| |
77
| arguments to this function are incorrect
88
|
9-
= note: expected reference `&std::ops::Range<_>`
10-
found struct `std::ops::Range<_>`
9+
= note: expected reference `&Range<_>`
10+
found struct `Range<_>`
1111
note: function defined here
1212
--> $DIR/issue-73553-misinterp-range-literal.rs:3:4
1313
|
@@ -26,8 +26,8 @@ LL | demo(1..10);
2626
| |
2727
| arguments to this function are incorrect
2828
|
29-
= note: expected reference `&std::ops::Range<usize>`
30-
found struct `std::ops::Range<{integer}>`
29+
= note: expected reference `&Range<usize>`
30+
found struct `Range<{integer}>`
3131
note: function defined here
3232
--> $DIR/issue-73553-misinterp-range-literal.rs:3:4
3333
|

tests/ui/regions/resolve-re-error-ice.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ note: ...so that the method type is compatible with trait
1414
|
1515
LL | fn key_set(&self) -> Subject<'a, Keys<K, V>, (), R> {
1616
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17-
= note: expected `fn(&Subject<'_, _, _, _>) -> Subject<'_, std::collections::hash_map::Keys<'_, _, _>, _, _>`
18-
found `fn(&Subject<'_, _, _, _>) -> Subject<'a, std::collections::hash_map::Keys<'_, _, _>, _, _>`
17+
= note: expected `fn(&Subject<'_, _, _, _>) -> Subject<'_, Keys<'_, _, _>, _, _>`
18+
found `fn(&Subject<'_, _, _, _>) -> Subject<'a, Keys<'_, _, _>, _, _>`
1919
note: but, the lifetime must be valid for the lifetime `'a` as defined here...
2020
--> $DIR/resolve-re-error-ice.rs:10:6
2121
|

0 commit comments

Comments
 (0)