@@ -80,13 +80,12 @@ impl EarlyProps {
80
80
return false ;
81
81
}
82
82
83
- if !line. contains ( "ignore-gdb-version" ) &&
84
- config. parse_name_directive ( line, "ignore-gdb" ) {
83
+ if config. parse_name_directive ( line, "ignore-gdb" ) {
85
84
return true ;
86
85
}
87
86
88
87
if let Some ( actual_version) = config. gdb_version {
89
- if line. contains ( "min-gdb-version" ) {
88
+ if line. starts_with ( "min-gdb-version" ) {
90
89
let ( start_ver, end_ver) = extract_gdb_version_range ( line) ;
91
90
92
91
if start_ver != end_ver {
@@ -95,7 +94,7 @@ impl EarlyProps {
95
94
// Ignore if actual version is smaller the minimum required
96
95
// version
97
96
actual_version < start_ver
98
- } else if line. contains ( "ignore-gdb-version" ) {
97
+ } else if line. starts_with ( "ignore-gdb-version" ) {
99
98
let ( min_version, max_version) = extract_gdb_version_range ( line) ;
100
99
101
100
if max_version < min_version {
@@ -119,20 +118,21 @@ impl EarlyProps {
119
118
fn extract_gdb_version_range ( line : & str ) -> ( u32 , u32 ) {
120
119
const ERROR_MESSAGE : & ' static str = "Malformed GDB version directive" ;
121
120
122
- let range_components = line. split ( ' ' )
123
- . flat_map ( |word| word. split ( '-' ) )
124
- . filter ( |word| word. len ( ) > 0 )
125
- . skip_while ( |word| extract_gdb_version ( word) . is_none ( ) )
126
- . collect :: < Vec < & str > > ( ) ;
121
+ let range_components = line. split ( & [ ' ' , '-' ] [ ..] )
122
+ . filter ( |word| !word. is_empty ( ) )
123
+ . map ( extract_gdb_version)
124
+ . skip_while ( Option :: is_none)
125
+ . take ( 3 ) // 3 or more = invalid, so take at most 3.
126
+ . collect :: < Vec < Option < u32 > > > ( ) ;
127
127
128
128
match range_components. len ( ) {
129
129
1 => {
130
- let v = extract_gdb_version ( range_components[ 0 ] ) . unwrap ( ) ;
130
+ let v = range_components[ 0 ] . unwrap ( ) ;
131
131
( v, v)
132
132
}
133
133
2 => {
134
- let v_min = extract_gdb_version ( range_components[ 0 ] ) . unwrap ( ) ;
135
- let v_max = extract_gdb_version ( range_components[ 1 ] ) . expect ( ERROR_MESSAGE ) ;
134
+ let v_min = range_components[ 0 ] . unwrap ( ) ;
135
+ let v_max = range_components[ 1 ] . expect ( ERROR_MESSAGE ) ;
136
136
( v_min, v_max)
137
137
}
138
138
_ => panic ! ( ERROR_MESSAGE ) ,
@@ -149,10 +149,10 @@ impl EarlyProps {
149
149
}
150
150
151
151
if let Some ( ref actual_version) = config. lldb_version {
152
- if line. contains ( "min-lldb-version" ) {
153
- let min_version = line. trim ( )
154
- . split ( ' ' )
155
- . last ( )
152
+ if line. starts_with ( "min-lldb-version" ) {
153
+ let min_version = line. trim_right ( )
154
+ . rsplit ( ' ' )
155
+ . next ( )
156
156
. expect ( "Malformed lldb version directive" ) ;
157
157
// Ignore if actual version is smaller the minimum required
158
158
// version
@@ -167,10 +167,10 @@ impl EarlyProps {
167
167
168
168
fn ignore_llvm ( config : & Config , line : & str ) -> bool {
169
169
if let Some ( ref actual_version) = config. llvm_version {
170
- if line. contains ( "min-llvm-version" ) {
171
- let min_version = line. trim ( )
172
- . split ( ' ' )
173
- . last ( )
170
+ if line. starts_with ( "min-llvm-version" ) {
171
+ let min_version = line. trim_right ( )
172
+ . rsplit ( ' ' )
173
+ . next ( )
174
174
. expect ( "Malformed llvm version directive" ) ;
175
175
// Ignore if actual version is smaller the minimum required
176
176
// version
@@ -413,14 +413,14 @@ fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut FnMut(&str)) {
413
413
None => false ,
414
414
} ;
415
415
if matches {
416
- it ( & ln[ close_brace + 1 ..] ) ;
416
+ it ( ln[ ( close_brace + 1 ) ..] . trim_left ( ) ) ;
417
417
}
418
418
} else {
419
419
panic ! ( "malformed condition directive: expected `//[foo]`, found `{}`" ,
420
420
ln)
421
421
}
422
422
} else if ln. starts_with ( "//" ) {
423
- it ( & ln[ 2 ..] ) ;
423
+ it ( ln[ 2 ..] . trim_left ( ) ) ;
424
424
}
425
425
}
426
426
return ;
@@ -528,15 +528,18 @@ impl Config {
528
528
}
529
529
530
530
fn parse_name_directive ( & self , line : & str , directive : & str ) -> bool {
531
- // This 'no-' rule is a quick hack to allow pretty-expanded and
532
- // no-pretty-expanded to coexist
533
- line. contains ( directive) && !line. contains ( & ( "no-" . to_owned ( ) + directive) )
531
+ // Ensure the directive is a whole word. Do not match "ignore-x86" when
532
+ // the line says "ignore-x86_64".
533
+ line. starts_with ( directive) && match line. as_bytes ( ) . get ( directive. len ( ) ) {
534
+ None | Some ( & b' ' ) | Some ( & b':' ) => true ,
535
+ _ => false
536
+ }
534
537
}
535
538
536
539
pub fn parse_name_value_directive ( & self , line : & str , directive : & str ) -> Option < String > {
537
- let keycolon = format ! ( "{}:" , directive) ;
538
- if let Some ( colon) = line . find ( & keycolon ) {
539
- let value = line[ ( colon + keycolon . len ( ) ) ..line . len ( ) ] . to_owned ( ) ;
540
+ let colon = directive. len ( ) ;
541
+ if line . starts_with ( directive ) && line . as_bytes ( ) . get ( colon) == Some ( & b':' ) {
542
+ let value = line[ ( colon + 1 ) .. ] . to_owned ( ) ;
540
543
debug ! ( "{}: {}" , directive, value) ;
541
544
Some ( expand_variables ( value, self ) )
542
545
} else {
0 commit comments