File tree Expand file tree Collapse file tree 3 files changed +19
-9
lines changed
rustc_error_messages/locales/en-US Expand file tree Collapse file tree 3 files changed +19
-9
lines changed Original file line number Diff line number Diff line change @@ -306,7 +306,7 @@ parser_expected_identifier = expected identifier
306
306
parser_sugg_escape_to_use_as_identifier = escape `{ $ident_name } ` to use it as an identifier
307
307
308
308
parser_sugg_remove_comma = remove this comma
309
- parser_sugg_misplaced_generic = place the generic parameter list after the function name:
309
+ parser_sugg_misplaced_generic = place the generic parameter list after the function name: ` { $generic_as_string } `
310
310
311
311
parser_expected_semi_found_reserved_identifier_str = expected `;`, found reserved identifier `{ $token } `
312
312
parser_expected_semi_found_keyword_str = expected `;`, found keyword `{ $token } `
Original file line number Diff line number Diff line change @@ -882,10 +882,11 @@ pub(crate) struct SuggRemoveComma {
882
882
pub span : Span ,
883
883
}
884
884
885
- //SHREYS - should this be help, or a suggestion?
885
+ //TODO: SHREYS - should this be help, or a suggestion?
886
886
#[ derive( Subdiagnostic ) ]
887
- #[ help( parser:: sugg_misplaced_generic) ]
888
887
pub ( crate ) struct SuggMisplacedGeneric {
888
+ pub snippet : String ,
889
+ #[ suggestion( code = "<{snippet}>" ) ]
889
890
#[ primary_span]
890
891
pub span : Span ,
891
892
}
Original file line number Diff line number Diff line change @@ -330,12 +330,21 @@ impl<'a> Parser<'a> {
330
330
let token = self . token . clone ( ) ;
331
331
let suggest_misplaced_generic = if self . token == token:: Lt {
332
332
// store the span before the generic calculation starts
333
- if self . parse_generics ( ) . is_ok ( ) {
334
- // FIXME: need the span of the whole generic.
335
- Some ( SuggMisplacedGeneric { span : span. until ( self . token . span ) } )
336
- } else {
337
- None
338
- }
333
+ self . parse_generics ( ) . map_or ( None , |generic| {
334
+ // at this point, token should be Ident with the fn name
335
+
336
+ // FIXME: shreys the span should be the span of where the gneeric SHOULD go.
337
+ // TODO: shreys what does this look like with invalid generic
338
+ // TODO: shreys - what to do if no snippet? probably just HELP not suggestion
339
+
340
+ let snippet = match self . sess . source_map ( ) . span_to_snippet ( generic. span ) {
341
+ Ok ( snippet) => snippet,
342
+ _ => "" . to_string ( )
343
+ } ;
344
+
345
+ Some ( SuggMisplacedGeneric { span : self . token . span . to ( generic. span . shrink_to_hi ( ) ) , snippet } )
346
+ } )
347
+
339
348
} else {
340
349
None
341
350
} ;
You can’t perform that action at this time.
0 commit comments