@@ -143,20 +143,21 @@ impl Diagnostic {
143
143
self
144
144
}
145
145
146
- pub fn note_expected_found ( & mut self ,
147
- label : & dyn fmt:: Display ,
148
- expected : DiagnosticStyledString ,
149
- found : DiagnosticStyledString )
150
- -> & mut Self
151
- {
152
- self . note_expected_found_extra ( label, expected, found, & "" , & "" )
153
- }
154
-
155
- pub fn note_unsuccessfull_coercion ( & mut self ,
156
- expected : DiagnosticStyledString ,
157
- found : DiagnosticStyledString )
158
- -> & mut Self
159
- {
146
+ pub fn note_expected_found (
147
+ & mut self ,
148
+ expected_label : & dyn fmt:: Display ,
149
+ expected : DiagnosticStyledString ,
150
+ found_label : & dyn fmt:: Display ,
151
+ found : DiagnosticStyledString ,
152
+ ) -> & mut Self {
153
+ self . note_expected_found_extra ( expected_label, expected, found_label, found, & "" , & "" )
154
+ }
155
+
156
+ pub fn note_unsuccessfull_coercion (
157
+ & mut self ,
158
+ expected : DiagnosticStyledString ,
159
+ found : DiagnosticStyledString ,
160
+ ) -> & mut Self {
160
161
let mut msg: Vec < _ > =
161
162
vec ! [ ( format!( "required when trying to coerce from type `" ) ,
162
163
Style :: NoStyle ) ] ;
@@ -178,27 +179,38 @@ impl Diagnostic {
178
179
self
179
180
}
180
181
181
- pub fn note_expected_found_extra ( & mut self ,
182
- label : & dyn fmt:: Display ,
183
- expected : DiagnosticStyledString ,
184
- found : DiagnosticStyledString ,
185
- expected_extra : & dyn fmt:: Display ,
186
- found_extra : & dyn fmt:: Display )
187
- -> & mut Self
188
- {
189
- let mut msg: Vec < _ > = vec ! [ ( format!( "expected {} `" , label) , Style :: NoStyle ) ] ;
182
+ pub fn note_expected_found_extra (
183
+ & mut self ,
184
+ expected_label : & dyn fmt:: Display ,
185
+ expected : DiagnosticStyledString ,
186
+ found_label : & dyn fmt:: Display ,
187
+ found : DiagnosticStyledString ,
188
+ expected_extra : & dyn fmt:: Display ,
189
+ found_extra : & dyn fmt:: Display ,
190
+ ) -> & mut Self {
191
+ let expected_label = format ! ( "expected {}" , expected_label) ;
192
+ let found_label = format ! ( "found {}" , found_label) ;
193
+ let ( found_padding, expected_padding) = if expected_label. len ( ) > found_label. len ( ) {
194
+ ( expected_label. len ( ) - found_label. len ( ) , 0 )
195
+ } else {
196
+ ( 0 , found_label. len ( ) - expected_label. len ( ) )
197
+ } ;
198
+ let mut msg: Vec < _ > = vec ! [ (
199
+ format!( "{}{} `" , " " . repeat( expected_padding) , expected_label) ,
200
+ Style :: NoStyle ,
201
+ ) ] ;
190
202
msg. extend ( expected. 0 . iter ( )
191
- . map ( |x| match * x {
192
- StringPart :: Normal ( ref s) => ( s. to_owned ( ) , Style :: NoStyle ) ,
193
- StringPart :: Highlighted ( ref s) => ( s. to_owned ( ) , Style :: Highlight ) ,
194
- } ) ) ;
203
+ . map ( |x| match * x {
204
+ StringPart :: Normal ( ref s) => ( s. to_owned ( ) , Style :: NoStyle ) ,
205
+ StringPart :: Highlighted ( ref s) => ( s. to_owned ( ) , Style :: Highlight ) ,
206
+ } ) ) ;
195
207
msg. push ( ( format ! ( "`{}\n " , expected_extra) , Style :: NoStyle ) ) ;
196
- msg. push ( ( format ! ( " found {} `" , label ) , Style :: NoStyle ) ) ;
208
+ msg. push ( ( format ! ( "{}{} `" , " " . repeat ( found_padding ) , found_label ) , Style :: NoStyle ) ) ;
197
209
msg. extend ( found. 0 . iter ( )
198
- . map ( |x| match * x {
199
- StringPart :: Normal ( ref s) => ( s. to_owned ( ) , Style :: NoStyle ) ,
200
- StringPart :: Highlighted ( ref s) => ( s. to_owned ( ) , Style :: Highlight ) ,
201
- } ) ) ;
210
+ . map ( |x| match * x {
211
+ StringPart :: Normal ( ref s) => ( s. to_owned ( ) , Style :: NoStyle ) ,
212
+ StringPart :: Highlighted ( ref s) => ( s. to_owned ( ) , Style :: Highlight ) ,
213
+ } ) ) ;
202
214
msg. push ( ( format ! ( "`{}" , found_extra) , Style :: NoStyle ) ) ;
203
215
204
216
// For now, just attach these as notes
0 commit comments