@@ -982,93 +982,6 @@ impl SourceMap {
982982 self . files ( ) . iter ( ) . fold ( 0 , |a, f| a + f. count_lines ( ) )
983983 }
984984
985- pub fn generate_fn_name_span ( & self , span : Span ) -> Option < Span > {
986- let prev_span = self . span_extend_to_prev_str ( span, "fn" , true , true ) ?;
987- if let Ok ( snippet) = self . span_to_snippet ( prev_span) {
988- debug ! (
989- "generate_fn_name_span: span={:?}, prev_span={:?}, snippet={:?}" ,
990- span, prev_span, snippet
991- ) ;
992-
993- if snippet. is_empty ( ) {
994- return None ;
995- } ;
996-
997- let len = snippet
998- . find ( |c : char | !c. is_alphanumeric ( ) && c != '_' )
999- . expect ( "no label after fn" ) ;
1000- Some ( prev_span. with_hi ( BytePos ( prev_span. lo ( ) . 0 + len as u32 ) ) )
1001- } else {
1002- None
1003- }
1004- }
1005-
1006- /// Takes the span of a type parameter in a function signature and try to generate a span for
1007- /// the function name (with generics) and a new snippet for this span with the pointed type
1008- /// parameter as a new local type parameter.
1009- ///
1010- /// For instance:
1011- /// ```rust,ignore (pseudo-Rust)
1012- /// // Given span
1013- /// fn my_function(param: T)
1014- /// // ^ Original span
1015- ///
1016- /// // Result
1017- /// fn my_function(param: T)
1018- /// // ^^^^^^^^^^^ Generated span with snippet `my_function<T>`
1019- /// ```
1020- ///
1021- /// Attention: The method used is very fragile since it essentially duplicates the work of the
1022- /// parser. If you need to use this function or something similar, please consider updating the
1023- /// `SourceMap` functions and this function to something more robust.
1024- pub fn generate_local_type_param_snippet ( & self , span : Span ) -> Option < ( Span , String ) > {
1025- // Try to extend the span to the previous "fn" keyword to retrieve the function
1026- // signature.
1027- if let Some ( sugg_span) = self . span_extend_to_prev_str ( span, "fn" , false , true ) {
1028- if let Ok ( snippet) = self . span_to_snippet ( sugg_span) {
1029- // Consume the function name.
1030- let mut offset = snippet
1031- . find ( |c : char | !c. is_alphanumeric ( ) && c != '_' )
1032- . expect ( "no label after fn" ) ;
1033-
1034- // Consume the generics part of the function signature.
1035- let mut bracket_counter = 0 ;
1036- let mut last_char = None ;
1037- for c in snippet[ offset..] . chars ( ) {
1038- match c {
1039- '<' => bracket_counter += 1 ,
1040- '>' => bracket_counter -= 1 ,
1041- '(' => {
1042- if bracket_counter == 0 {
1043- break ;
1044- }
1045- }
1046- _ => { }
1047- }
1048- offset += c. len_utf8 ( ) ;
1049- last_char = Some ( c) ;
1050- }
1051-
1052- // Adjust the suggestion span to encompass the function name with its generics.
1053- let sugg_span = sugg_span. with_hi ( BytePos ( sugg_span. lo ( ) . 0 + offset as u32 ) ) ;
1054-
1055- // Prepare the new suggested snippet to append the type parameter that triggered
1056- // the error in the generics of the function signature.
1057- let mut new_snippet = if last_char == Some ( '>' ) {
1058- format ! ( "{}, " , & snippet[ ..( offset - '>' . len_utf8( ) ) ] )
1059- } else {
1060- format ! ( "{}<" , & snippet[ ..offset] )
1061- } ;
1062- new_snippet
1063- . push_str ( & self . span_to_snippet ( span) . unwrap_or_else ( |_| "T" . to_string ( ) ) ) ;
1064- new_snippet. push ( '>' ) ;
1065-
1066- return Some ( ( sugg_span, new_snippet) ) ;
1067- }
1068- }
1069-
1070- None
1071- }
1072985 pub fn ensure_source_file_source_present ( & self , source_file : Lrc < SourceFile > ) -> bool {
1073986 source_file. add_external_src ( || {
1074987 match source_file. name {
0 commit comments