@@ -15,7 +15,7 @@ pub enum Message {
15
15
UnboundName {
16
16
range : FileRange ,
17
17
name : Symbol ,
18
- suggestion : Option < Symbol > ,
18
+ suggested_name : Option < Symbol > ,
19
19
} ,
20
20
RefutablePattern {
21
21
pattern_range : FileRange ,
@@ -47,7 +47,7 @@ pub enum Message {
47
47
head_type : String ,
48
48
label_range : FileRange ,
49
49
label : Symbol ,
50
- suggestion : Option < Symbol > ,
50
+ suggested_label : Option < Symbol > ,
51
51
} ,
52
52
MismatchedFieldLabels {
53
53
range : FileRange ,
@@ -148,21 +148,16 @@ impl Message {
148
148
Message :: UnboundName {
149
149
range,
150
150
name,
151
- suggestion ,
151
+ suggested_name ,
152
152
} => {
153
153
let name = name. resolve ( ) ;
154
154
155
- let mut diagnostic = Diagnostic :: error ( )
155
+ Diagnostic :: error ( )
156
156
. with_message ( format ! ( "cannot find `{name}` in scope" ) )
157
- . with_labels ( vec ! [ primary_label( range) . with_message( "unbound name" ) ] ) ;
158
-
159
- if let Some ( suggestion) = suggestion {
160
- diagnostic = diagnostic. with_notes ( vec ! [ format!(
161
- "help: did you mean `{}`?" ,
162
- suggestion. resolve( )
163
- ) ] )
164
- }
165
- diagnostic
157
+ . with_labels ( vec ! [ primary_label( range) . with_message( "unbound name" ) ] )
158
+ . with_notes ( suggested_name. map_or ( Vec :: new ( ) , |name| {
159
+ vec ! [ format!( "help: did you mean `{}`?" , name. resolve( ) ) ]
160
+ } ) )
166
161
}
167
162
Message :: RefutablePattern { pattern_range } => Diagnostic :: error ( )
168
163
. with_message ( "refutable patterns found in binding" )
@@ -219,24 +214,20 @@ impl Message {
219
214
head_type,
220
215
label_range,
221
216
label,
222
- suggestion ,
217
+ suggested_label ,
223
218
} => {
224
219
let label = label. resolve ( ) ;
225
220
226
- let mut diagnostic = Diagnostic :: error ( )
221
+ Diagnostic :: error ( )
227
222
. with_message ( format ! ( "cannot find `{label}` in expression" ) )
228
223
. with_labels ( vec ! [
229
224
primary_label( label_range) . with_message( "unknown label" ) ,
230
225
secondary_label( head_range)
231
226
. with_message( format!( "expression of type {head_type}" ) ) ,
232
- ] ) ;
233
- if let Some ( suggestion) = suggestion {
234
- diagnostic = diagnostic. with_notes ( vec ! [ format!(
235
- "help: did you mean `{}`?" ,
236
- suggestion. resolve( )
237
- ) ] ) ;
238
- }
239
- diagnostic
227
+ ] )
228
+ . with_notes ( suggested_label. map_or ( Vec :: new ( ) , |label| {
229
+ vec ! [ format!( "help: did you mean `{}`?" , label. resolve( ) ) ]
230
+ } ) )
240
231
}
241
232
Message :: MismatchedFieldLabels {
242
233
range,
0 commit comments