@@ -21,30 +21,30 @@ import rustc::syntax::codemap;
21
21
import rustc:: syntax:: parse:: parser;
22
22
import rustc:: syntax:: print:: pprust;
23
23
24
- fn write_file ( filename : & str , content : & str ) {
25
- io:: file_writer ( istr :: from_estr ( filename) , [ io:: create, io:: truncate] ) . write_str ( istr :: from_estr ( content) ) ;
24
+ fn write_file ( filename : & istr , content : & istr ) {
25
+ io:: file_writer ( filename, [ io:: create, io:: truncate] ) . write_str ( content) ;
26
26
// Work around https://github.com/graydon/rust/issues/726
27
- std:: run:: run_program ( ~"chmod", [ ~"644 ", istr :: from_estr ( filename) ] ) ;
27
+ std:: run:: run_program ( ~"chmod", [ ~"644 ", filename] ) ;
28
28
}
29
29
30
- fn file_contains ( filename : & str , needle : & str ) -> bool {
31
- let contents = istr :: to_estr ( io:: read_whole_file_str ( istr :: from_estr ( filename) ) ) ;
32
- ret str :: find ( contents, needle) != -1 ;
30
+ fn file_contains ( filename : & istr , needle : & istr ) -> bool {
31
+ let contents = io:: read_whole_file_str ( filename) ;
32
+ ret istr :: find ( contents, needle) != -1 ;
33
33
}
34
34
35
- fn contains ( haystack : & str , needle : & str ) -> bool {
36
- str :: find ( haystack, needle) != -1
35
+ fn contains ( haystack : & istr , needle : & istr ) -> bool {
36
+ istr :: find ( haystack, needle) != -1
37
37
}
38
38
39
- fn find_rust_files ( files : & mutable [ str ] , path : str ) {
40
- if str :: ends_with ( path, ".rs" ) {
41
- if file_contains ( path, "xfail-test" ) {
39
+ fn find_rust_files ( files : & mutable [ istr ] , path : & istr ) {
40
+ if istr :: ends_with ( path, ~ ". rs") {
41
+ if file_contains ( path, ~ "xfail-test") {
42
42
//log_err "Skipping " + path + " because it is marked as xfail-test";
43
43
} else { files += [ path] ; }
44
- } else if fs:: file_is_dir ( istr :: from_estr ( path) )
45
- && str :: find ( path, "compile-fail" ) == -1 {
46
- for p in fs:: list_dir ( istr :: from_estr ( path) ) {
47
- find_rust_files ( files, istr :: to_estr ( p ) ) ;
44
+ } else if fs:: file_is_dir ( path)
45
+ && istr :: find ( path, ~ "compile-fail") == -1 {
46
+ for p in fs:: list_dir ( path) {
47
+ find_rust_files ( files, p ) ;
48
48
}
49
49
}
50
50
}
@@ -151,14 +151,14 @@ iter under(n: uint) -> uint {
151
151
152
152
fn devnull ( ) -> io:: writer { std : : io:: string_writer ( ) . get_writer ( ) }
153
153
154
- fn as_str ( f : fn ( io:: writer) ) -> str {
154
+ fn as_str ( f : fn ( io:: writer) ) -> istr {
155
155
let w = std:: io:: string_writer ( ) ;
156
156
f ( w. get_writer ( ) ) ;
157
- ret istr :: to_estr ( w. get_str ( ) ) ;
157
+ ret w. get_str ( ) ;
158
158
}
159
159
160
160
fn check_variants_of_ast ( crate : & ast:: crate, codemap: & codemap:: codemap,
161
- filename : & str ) {
161
+ filename: & istr ) {
162
162
let exprs = steal_exprs ( crate ) ;
163
163
let exprsL = vec:: len ( exprs) ;
164
164
if exprsL < 100 u {
@@ -171,7 +171,7 @@ fn check_variants_of_ast(crate: &ast::crate, codemap: &codemap::codemap,
171
171
// string for stability is easier and ok for now.
172
172
let str3 =
173
173
as_str(bind pprust::print_crate(codemap, crate2,
174
- istr::from_estr( filename) ,
174
+ filename,
175
175
io::string_reader(~" ") , _,
176
176
pprust:: no_ann( ) ) ) ;
177
177
// 1u would be sane here, but the pretty-printer currently has lots of whitespace and paren issues,
@@ -187,93 +187,93 @@ fn check_variants_of_ast(crate: &ast::crate, codemap: &codemap::codemap,
187
187
// - that would find many "false positives" or unimportant bugs
188
188
// - that would be tricky, requiring use of tasks or serialization or randomness.
189
189
// This seems to find plenty of bugs as it is :)
190
- fn check_whole_compiler ( code : & str ) {
191
- let filename = "test.rs" ;
190
+ fn check_whole_compiler( code: & istr ) {
191
+ let filename = ~ "test. rs";
192
192
write_file ( filename, code) ;
193
193
let p =
194
194
std:: run:: program_output(
195
195
~"/Users /jruderman/code/rust/build/stage1/rustc",
196
- [ ~"-c", istr::from_estr( filename) ]);
196
+ [ ~"-c", filename]);
197
197
198
198
//log_err #ifmt(" Status : %d", p. status ) ;
199
199
//log_err "Output: " + p.out;
200
200
if p. err != ~"" {
201
- if contains ( istr :: to_estr ( p. err ) , "argument of incompatible type" ) {
201
+ if contains ( p. err , ~ "argument of incompatible type") {
202
202
log_err "https://github.com/graydon/rust/issues/769" ;
203
- } else if contains ( istr :: to_estr ( p. err ) ,
204
- "Cannot create binary operator with two operands of differing type" )
203
+ } else if contains ( p. err ,
204
+ ~ "Cannot create binary operator with two operands of differing type")
205
205
{
206
206
log_err "https://github.com/graydon/rust/issues/770" ;
207
- } else if contains ( istr :: to_estr ( p. err ) , "May only branch on boolean predicates!" ) {
207
+ } else if contains( p. err , ~ "May only branch on boolean predicates!") {
208
208
log_err " https: //github. com /graydon/rust/issues/770 or https: //github. com /graydon/rust/issues/776 ";
209
- } else if contains ( istr :: to_estr ( p. err ) , "Invalid constantexpr cast!" ) &&
210
- contains ( code, "!" ) {
209
+ } else if contains( p. err , ~ "Invalid constantexpr cast!") &&
210
+ contains(code, ~ " !") {
211
211
log_err " https: //github. com /graydon/rust/issues/777 ";
212
- } else if contains ( istr :: to_estr ( p. err ) ,
213
- "Both operands to ICmp instruction are not of the same type!" )
214
- && contains ( code, "!" ) {
212
+ } else if contains( p. err ,
213
+ ~ "Both operands to ICmp instruction are not of the same type!")
214
+ && contains(code, ~ " !") {
215
215
log_err " https: //github. com /graydon/rust/issues/777 #issuecomment-1678487 ";
216
- } else if contains ( istr :: to_estr ( p. err ) , "Ptr must be a pointer to Val type!" ) &&
217
- contains ( code, "!" ) {
216
+ } else if contains( p. err , ~ "Ptr must be a pointer to Val type!") &&
217
+ contains(code, ~ " !") {
218
218
log_err " https: //github. com /graydon/rust/issues/779 ";
219
- } else if contains ( istr :: to_estr ( p. err ) , "Calling a function with bad signature!" ) &&
220
- ( contains ( code, "iter" ) || contains ( code, "range" ) ) {
219
+ } else if contains ( p. err , ~ "Calling a function with bad signature!") &&
220
+ (contains(code, ~ " iter") || contains ( code, ~ "range") ) {
221
221
log_err "https://github.com/graydon/rust/issues/771 - calling an iter fails" ;
222
- } else if contains ( istr :: to_estr ( p. err ) , "Calling a function with a bad signature!" )
223
- && contains ( code, "empty" ) {
222
+ } else if contains ( p. err , ~ "Calling a function with a bad signature!")
223
+ && contains(code, ~ " empty") {
224
224
log_err "https://github.com/graydon/rust/issues/775 - possibly a modification of run-pass/import-glob-crate.rs" ;
225
- } else if contains ( istr :: to_estr ( p. err ) , "Invalid type for pointer element!" ) &&
226
- contains ( code, "put" ) {
225
+ } else if contains( p. err , ~ "Invalid type for pointer element!") &&
226
+ contains(code, ~ " put") {
227
227
log_err "https://github.com/graydon/rust/issues/773 - put put ()" ;
228
- } else if contains ( istr :: to_estr ( p. err ) , "pointer being freed was not allocated" ) &&
229
- contains ( istr :: to_estr ( p. out ) , "Out of stack space, sorry" ) {
228
+ } else if contains ( p. err , ~ "pointer being freed was not allocated") &&
229
+ contains ( p. out , ~ "Out of stack space, sorry") {
230
230
log_err "https://github.com/graydon/rust/issues/768 + https://github.com/graydon/rust/issues/778"
231
231
} else {
232
232
log_err ~"Stderr : " + p.err;
233
233
fail " Unfamiliar error message";
234
234
}
235
- } else if contains( istr :: to_estr ( p. out ) , "non-exhaustive match failure" ) &&
236
- contains ( istr :: to_estr ( p. out ) , "alias.rs" ) {
235
+ } else if contains( p. out , ~ "non-exhaustive match failure") &&
236
+ contains ( p. out , ~ "alias. rs ") {
237
237
log_err "https://github.com/graydon/rust/issues/772" ;
238
- } else if contains ( istr :: to_estr ( p. out ) , "non-exhaustive match failure" ) &&
239
- contains ( istr :: to_estr ( p. out ) , "trans.rs" ) && contains ( code, "put" ) {
238
+ } else if contains( p. out , ~ "non-exhaustive match failure") &&
239
+ contains ( p. out , ~ "trans. rs ") && contains ( code, ~ "put") {
240
240
log_err "https://github.com/graydon/rust/issues/774" ;
241
- } else if contains ( istr :: to_estr ( p. out ) , "Out of stack space, sorry" ) {
241
+ } else if contains ( p. out , ~ "Out of stack space, sorry") {
242
242
log_err "Possibly a variant of https://github.com/graydon/rust/issues/768" ;
243
243
} else if p. status == 256 {
244
- if !contains ( istr :: to_estr ( p. out ) , "error:" ) {
244
+ if !contains ( p. out , ~ "error: ") {
245
245
fail "Exited with status 256 without a span-error" ;
246
246
}
247
247
} else if p. status == 11 {
248
248
log_err "What is this I don't even" ;
249
249
} else if p. status != 0 { fail "Unfamiliar status code" ; }
250
250
}
251
251
252
- fn parse_and_print( code: & str ) -> str {
253
- let filename = "tmp.rs" ;
252
+ fn parse_and_print ( code: & istr ) -> istr {
253
+ let filename = ~ "tmp. rs";
254
254
let sess = @{ cm : codemap:: new_codemap ( ) , mutable next_id : 0 } ;
255
255
//write_file(filename, code);
256
256
let crate = parser:: parse_crate_from_source_str (
257
- istr :: from_estr ( filename) , istr :: from_estr ( code) , [ ] , sess) ;
257
+ filename, code, [ ] , sess) ;
258
258
ret as_str ( bind pprust:: print_crate ( sess. cm , crate ,
259
- istr :: from_estr ( filename) ,
260
- io:: string_reader ( istr :: from_estr ( code) ) , _,
259
+ filename,
260
+ io:: string_reader ( code) , _,
261
261
pprust:: no_ann ( ) ) ) ;
262
262
}
263
263
264
- fn content_is_dangerous_to_modify ( code : & str ) -> bool {
264
+ fn content_is_dangerous_to_modify ( code: & istr ) -> bool {
265
265
let dangerous_patterns =
266
- [ "obj" , // not safe to steal; https://github.com/graydon/rust/issues/761
267
- "#macro" , // not safe to steal things inside of it, because they have a special syntax
268
- "#" , // strange representation of the arguments to #ifmt, for example
269
- " be " , // don't want to replace its child with a non-call: "Non-call expression in tail call"
270
- "@" ] ; // hangs when compiling: https://github.com/graydon/rust/issues/768
266
+ [ ~ "obj", // not safe to steal; https://github.com/graydon/rust/issues/761
267
+ ~ "#macro", // not safe to steal things inside of it, because they have a special syntax
268
+ ~ "#", // strange representation of the arguments to #ifmt, for example
269
+ ~ " be ", // don't want to replace its child with a non-call: " Non -call expression in tail call"
270
+ ~ "@"] ; // hangs when compiling: https://github.com/graydon/rust/issues/768
271
271
272
- for p: str in dangerous_patterns { if contains ( code, p) { ret true ; } }
272
+ for p: istr in dangerous_patterns { if contains ( code, p) { ret true ; } }
273
273
ret false;
274
274
}
275
275
276
- fn content_is_confusing ( code : & str ) ->
276
+ fn content_is_confusing( code : & istr ) ->
277
277
bool { // https://github.com/graydon/rust/issues/671
278
278
// https://github.com/graydon/rust/issues/669
279
279
// https://github.com/graydon/rust/issues/669
@@ -283,16 +283,16 @@ fn content_is_confusing(code: &str) ->
283
283
// more precedence issues?
284
284
285
285
let confusing_patterns =
286
- [ "#macro" , "][]" , "][mutable]" , "][mutable ]" , "self" , "spawn" ,
287
- "bind" , "\n \n \n \n \n " , // https://github.com/graydon/rust/issues/759
288
- " : " , // https://github.com/graydon/rust/issues/760
289
- "if ret" , "alt ret" , "if fail" , "alt fail" ] ;
286
+ [ ~ "#macro", ~ "] [ ] ", ~ "] [ mutable] ", ~ "] [ mutable ] ", ~ "self ", ~ "spawn",
287
+ ~ "bind", ~ "\n \n \n \n \n ", // https://github.com/graydon/rust/issues/759
288
+ ~ " : ", // https://github.com/graydon/rust/issues/760
289
+ ~ " if ret", ~ "alt ret", ~ "if fail", ~ "alt fail"] ;
290
290
291
- for p: str in confusing_patterns { if contains ( code, p) { ret true ; } }
291
+ for p: istr in confusing_patterns { if contains ( code, p) { ret true ; } }
292
292
ret false ;
293
293
}
294
294
295
- fn file_is_confusing ( filename : & str ) -> bool {
295
+ fn file_is_confusing ( filename : & istr ) -> bool {
296
296
297
297
// https://github.com/graydon/rust/issues/674
298
298
@@ -303,16 +303,16 @@ fn file_is_confusing(filename: &str) -> bool {
303
303
// which i can't reproduce using "rustc
304
304
// --pretty normal"???
305
305
let confusing_files =
306
- [ "block-expr-precedence.rs" , "nil-pattern.rs" ,
307
- "syntax-extension-fmt.rs" ,
308
- "newtype.rs" ] ; // modifying it hits something like https://github.com/graydon/rust/issues/670
306
+ [ ~ "block-expr-precedence. rs ", ~ "nil-pattern. rs ",
307
+ ~ "syntax-extension-fmt. rs ",
308
+ ~ "newtype. rs "] ; // modifying it hits something like https://github.com/graydon/rust/issues/670
309
309
310
310
for f in confusing_files { if contains ( filename, f) { ret true ; } }
311
311
312
312
ret false;
313
313
}
314
314
315
- fn check_roundtrip_convergence ( code : & str , maxIters : uint ) {
315
+ fn check_roundtrip_convergence ( code : & istr , maxIters : uint ) {
316
316
317
317
let i = 0 u;
318
318
let new = code;
@@ -330,54 +330,55 @@ fn check_roundtrip_convergence(code: &str, maxIters: uint) {
330
330
log_err #ifmt[ "Converged after %u iterations" , i] ;
331
331
} else {
332
332
log_err #ifmt[ "Did not converge after %u iterations!" , i] ;
333
- write_file ( "round-trip-a.rs" , old) ;
334
- write_file ( "round-trip-b.rs" , new) ;
333
+ write_file ( ~ "round-trip-a. rs ", old) ;
334
+ write_file ( ~ "round-trip-b. rs ", new) ;
335
335
std:: run:: run_program ( ~"diff",
336
336
[ ~"-w", ~"-u", ~"round-trip-a. rs ",
337
337
~"round-trip-b. rs "] ) ;
338
338
fail "Mismatch" ;
339
339
}
340
340
}
341
341
342
- fn check_convergence ( files : & [ str ] ) {
342
+ fn check_convergence ( files : & [ istr ] ) {
343
343
log_err #ifmt[ "pp convergence tests: %u files" , vec:: len ( files) ] ;
344
344
for file in files {
345
345
if !file_is_confusing ( file) {
346
- let s = istr :: to_estr ( io:: read_whole_file_str ( istr :: from_estr ( file) ) ) ;
346
+ let s = io:: read_whole_file_str ( file) ;
347
347
if !content_is_confusing ( s) {
348
- log_err #ifmt[ "pp converge: %s" , istr :: from_estr ( file) ] ;
348
+ log_err #ifmt[ "pp converge: %s" , file] ;
349
349
// Change from 7u to 2u when https://github.com/graydon/rust/issues/759 is fixed
350
350
check_roundtrip_convergence ( s, 7 u) ;
351
351
}
352
352
}
353
353
}
354
354
}
355
355
356
- fn check_variants ( files : & [ str ] ) {
356
+ fn check_variants( files : & [ istr ] ) {
357
357
for file in files {
358
358
if !file_is_confusing ( file) {
359
- let s = istr :: to_estr ( io:: read_whole_file_str ( istr :: from_estr ( file) ) ) ;
359
+ let s = io:: read_whole_file_str ( file) ;
360
360
if content_is_dangerous_to_modify ( s) || content_is_confusing ( s) {
361
361
cont;
362
362
}
363
- log_err "check_variants: " + file;
363
+ log_err ~ "check_variants: " + file;
364
364
let sess = @{cm: codemap::new_codemap(), mutable next_id: 0};
365
365
let crate =
366
366
parser::parse_crate_from_source_str(
367
- istr :: from_estr ( file) ,
368
- istr :: from_estr ( s ) , [ ] , sess) ;
367
+ file,
368
+ s , [], sess);
369
369
log_err as_str(bind pprust::print_crate(sess.cm, crate,
370
- istr :: from_estr ( file) ,
371
- io:: string_reader ( istr :: from_estr ( s ) ) , _,
370
+ file,
371
+ io::string_reader(s ), _,
372
372
pprust::no_ann()));
373
373
check_variants_of_ast(*crate, sess.cm, file);
374
374
}
375
375
}
376
376
}
377
377
378
378
fn main(args: [str]) {
379
+ let args = istr::from_estrs(args);
379
380
if vec::len(args) != 2u {
380
- log_err #ifmt[ "usage: %s <testdir>" , istr :: from_estr ( args[ 0 ] ) ] ;
381
+ log_err #ifmt[" usage: %s <testdir>", args[0]];
381
382
ret;
382
383
}
383
384
let files = [];
0 commit comments