@@ -19,7 +19,6 @@ use std::path::PathBuf;
19
19
/// it was written like so in the source code: `foo-` but not when written like so `foo -`
20
20
///
21
21
/// Returns None if we couldn't detect whether they are touching (eg, our heuristics don't work with rust-analyzer)
22
- #[ rustversion:: since( 1.88 ) ]
23
22
fn are_token_touching ( token1 : proc_macro:: Span , token2 : proc_macro:: Span ) -> Option < bool > {
24
23
let t1 = token1. end ( ) ;
25
24
let t2 = token2. start ( ) ;
@@ -31,63 +30,6 @@ fn are_token_touching(token1: proc_macro::Span, token2: proc_macro::Span) -> Opt
31
30
}
32
31
Some ( t1. line ( ) == t2. line ( ) && t1_column == t2. column ( ) )
33
32
}
34
- #[ rustversion:: before( 1.88 ) ]
35
- fn are_token_touching ( token1 : proc_macro:: Span , token2 : proc_macro:: Span ) -> Option < bool > {
36
- // There is no way with stable API to find out if the token are touching, so do it by
37
- // extracting the range from the debug representation of the span
38
- are_token_touching_impl ( & format ! ( "{token1:?}" ) , & format ! ( "{token2:?}" ) )
39
- }
40
-
41
- #[ rustversion:: before( 1.88 ) ]
42
- fn are_token_touching_impl ( token1_debug : & str , token2_debug : & str ) -> Option < bool > {
43
- // The debug representation of a span look like this: "#0 bytes(6662789..6662794)"
44
- // we just have to find out if the first number of the range of second span
45
- // is the same as the second number of the first span
46
- let is_byte_char = |c : char | c. is_numeric ( ) || c == ':' ;
47
- let not_is_byte_char = |c : char | !is_byte_char ( c) ;
48
- let end_of_token1 = token1_debug
49
- . trim_end_matches ( not_is_byte_char)
50
- . rsplit ( not_is_byte_char)
51
- . next ( ) ?
52
- . trim_matches ( ':' ) ;
53
- let begin_of_token2 = token2_debug
54
- . trim_end_matches ( not_is_byte_char)
55
- . strip_suffix ( is_byte_char) ?
56
- . trim_end_matches ( is_byte_char)
57
- . trim_end_matches ( not_is_byte_char)
58
- . rsplit ( not_is_byte_char)
59
- . next ( ) ?
60
- . trim_matches ( ':' ) ;
61
- ( !begin_of_token2. is_empty ( ) ) . then_some ( end_of_token1 == begin_of_token2)
62
- }
63
-
64
- #[ rustversion:: before( 1.88 ) ]
65
- #[ test]
66
- fn are_token_touching_impl_test ( ) {
67
- assert ! ( are_token_touching_impl( "#0 bytes(6662788..6662789)" , "#0 bytes(6662789..6662794)" )
68
- . unwrap( ) ) ;
69
- assert ! ( !are_token_touching_impl( "#0 bytes(6662788..6662789)" , "#0 bytes(6662790..6662794)" )
70
- . unwrap( ) ) ;
71
- assert ! ( !are_token_touching_impl( "#0 bytes(6662789..6662794)" , "#0 bytes(6662788..6662789)" )
72
- . unwrap( ) ) ;
73
- assert ! (
74
- !are_token_touching_impl( "#0 bytes(6662788..6662789)" , "#0 bytes(662789..662794)" ) . unwrap( )
75
- ) ;
76
- assert ! ( are_token_touching_impl( "#0 bytes(123..456)" , "#0 bytes(456..789)" ) . unwrap( ) ) ;
77
-
78
- // Alternative representation on nightly with a special flag
79
- assert ! ( are_token_touching_impl( "/foo/bar.rs:12:7: 12:18" , "/foo/bar.rs:12:18: 12:19" ) . unwrap( ) ) ;
80
- assert ! ( are_token_touching_impl( "/foo/bar.rs:2:7: 13:18" , "/foo/bar.rs:13:18: 14:29" ) . unwrap( ) ) ;
81
- assert ! ( !are_token_touching_impl( "/foo/bar.rs:2:7: 13:18" , "/foo/bar.rs:14:18: 14:29" ) . unwrap( ) ) ;
82
- assert ! ( !are_token_touching_impl( "/foo/bar.rs:2:7: 2:8" , "/foo/bar.rs:2:18: 2:29" ) . unwrap( ) ) ;
83
-
84
- // What happens if the representation change
85
- assert ! ( are_token_touching_impl( "hello" , "hello" ) . is_none( ) ) ;
86
- assert ! ( are_token_touching_impl( "hello42" , "hello42" ) . is_none( ) ) ;
87
-
88
- // rust-analyzer just has indices that means nothing
89
- assert ! ( are_token_touching_impl( "55" , "56" ) . is_none( ) ) ;
90
- }
91
33
92
34
fn fill_token_vec ( stream : impl Iterator < Item = TokenTree > , vec : & mut Vec < parser:: Token > ) {
93
35
let mut prev_spacing = Spacing :: Alone ;
@@ -410,14 +352,9 @@ pub fn slint(stream: TokenStream) -> TokenStream {
410
352
let mut tokens = vec ! [ ] ;
411
353
fill_token_vec ( token_iter, & mut tokens) ;
412
354
413
- #[ rustversion:: since( 1.88 ) ]
414
355
fn local_file ( tokens : & [ parser:: Token ] ) -> Option < PathBuf > {
415
356
tokens. first ( ) ?. span ?. local_file ( )
416
357
}
417
- #[ rustversion:: before( 1.88 ) ]
418
- fn local_file ( _: & [ parser:: Token ] ) -> Option < PathBuf > {
419
- None
420
- }
421
358
422
359
let source_file = if let Some ( path) = local_file ( & tokens) {
423
360
diagnostics:: SourceFileInner :: from_path_only ( path)
0 commit comments