@@ -549,26 +549,8 @@ fn path_node(ids: Vec<ast::Ident> ) -> ast::Path {
549549fn mk_tests ( cx : & TestCtxt ) -> P < ast:: Item > {
550550 // The vector of test_descs for this crate
551551 let test_descs = mk_test_descs ( cx) ;
552-
553- // FIXME #15962: should be using quote_item, but that stringifies
554- // __test_reexports, causing it to be reinterned, losing the
555- // gensym information.
556- let sp = DUMMY_SP ;
557- let ecx = & cx. ext_cx ;
558- let struct_type = ecx. ty_path ( ecx. path ( sp, vec ! [ ecx. ident_of( "self" ) ,
559- ecx. ident_of( "test" ) ,
560- ecx. ident_of( "TestDescAndFn" ) ] ) ) ;
561- let static_lt = ecx. lifetime ( sp, token:: special_idents:: static_lifetime. name ) ;
562- // &'static [self::test::TestDescAndFn]
563- let static_type = ecx. ty_rptr ( sp,
564- ecx. ty ( sp, ast:: TyVec ( struct_type) ) ,
565- Some ( static_lt) ,
566- ast:: MutImmutable ) ;
567- // static TESTS: $static_type = &[...];
568- ecx. item_const ( sp,
569- ecx. ident_of ( "TESTS" ) ,
570- static_type,
571- test_descs)
552+ quote_item ! ( & cx. ext_cx, const TESTS : & ' static [ self :: test:: TestDescAndFn ] = $test_descs; )
553+ . unwrap ( )
572554}
573555
574556fn is_test_crate ( krate : & ast:: Crate ) -> bool {
@@ -596,57 +578,31 @@ fn mk_test_descs(cx: &TestCtxt) -> P<ast::Expr> {
596578}
597579
598580fn mk_test_desc_and_fn_rec ( cx : & TestCtxt , test : & Test ) -> P < ast:: Expr > {
599- // FIXME #15962: should be using quote_expr, but that stringifies
600- // __test_reexports, causing it to be reinterned, losing the
601- // gensym information.
602-
603581 let span = ignored_span ( cx, test. span ) ;
604582 let path = test. path . clone ( ) ;
605583 let ecx = & cx. ext_cx ;
606- let self_id = ecx. ident_of ( "self" ) ;
607- let test_id = ecx. ident_of ( "test" ) ;
608-
609- // creates self::test::$name
610- let test_path = |name| {
611- ecx. path ( span, vec ! [ self_id, test_id, ecx. ident_of( name) ] )
612- } ;
613- // creates $name: $expr
614- let field = |name, expr| ecx. field_imm ( span, ecx. ident_of ( name) , expr) ;
615-
616- debug ! ( "encoding {}" , ast_util:: path_name_i( & path[ ..] ) ) ;
617584
618585 // path to the #[test] function: "foo::bar::baz"
619- let path_string = ast_util:: path_name_i ( & path[ ..] ) ;
620- let name_expr = ecx. expr_str ( span, token:: intern_and_get_ident ( & path_string[ ..] ) ) ;
621-
622- // self::test::StaticTestName($name_expr)
623- let name_expr = ecx. expr_call ( span,
624- ecx. expr_path ( test_path ( "StaticTestName" ) ) ,
625- vec ! [ name_expr] ) ;
586+ let path_string = ast_util:: path_name_i ( & path) ;
587+ debug ! ( "encoding {}" , path_string) ;
626588
627589 let ignore_expr = ecx. expr_bool ( span, test. ignore ) ;
628- let should_panic_path = |name| {
629- ecx. path ( span, vec ! [ self_id, test_id, ecx. ident_of( "ShouldPanic" ) , ecx. ident_of( name) ] )
630- } ;
631590 let fail_expr = match test. should_panic {
632- ShouldPanic :: No => ecx . expr_path ( should_panic_path ( "No" ) ) ,
591+ ShouldPanic :: No => quote_expr ! ( ecx , self :: test :: ShouldPanic :: No ) ,
633592 ShouldPanic :: Yes ( ref msg) => {
634- let path = should_panic_path ( "Yes" ) ;
635593 let arg = match * msg {
636594 Some ( ref msg) => ecx. expr_some ( span, ecx. expr_str ( span, msg. clone ( ) ) ) ,
637595 None => ecx. expr_none ( span) ,
638596 } ;
639- ecx . expr_call ( span , ecx. expr_path ( path ) , vec ! [ arg] )
597+ quote_expr ! ( ecx, self :: test :: ShouldPanic :: Yes ( $ arg) )
640598 }
641599 } ;
642600
643- // self::test::TestDesc { ... }
644- let desc_expr = ecx. expr_struct (
645- span,
646- test_path ( "TestDesc" ) ,
647- vec ! [ field( "name" , name_expr) ,
648- field( "ignore" , ignore_expr) ,
649- field( "should_panic" , fail_expr) ] ) ;
601+ let desc_expr = quote_expr ! ( ecx, self :: test:: TestDesc {
602+ name: self :: test:: StaticTestName ( $path_string) ,
603+ ignore: $ignore_expr,
604+ should_panic: $fail_expr,
605+ } ) ;
650606
651607
652608 let mut visible_path = match cx. toplevel_reexport {
@@ -660,13 +616,10 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> P<ast::Expr> {
660616
661617 let fn_expr = ecx. expr_path ( ecx. path_global ( span, visible_path) ) ;
662618
663- let variant_name = if test. bench { "StaticBenchFn" } else { "StaticTestFn" } ;
664- // self::test::$variant_name($fn_expr)
665- let testfn_expr = ecx. expr_call ( span, ecx. expr_path ( test_path ( variant_name) ) , vec ! [ fn_expr] ) ;
619+ let variant_name = ecx. ident_of ( if test. bench { "StaticBenchFn" } else { "StaticTestFn" } ) ;
666620
667- // self::test::TestDescAndFn { ... }
668- ecx. expr_struct ( span,
669- test_path ( "TestDescAndFn" ) ,
670- vec ! [ field( "desc" , desc_expr) ,
671- field( "testfn" , testfn_expr) ] )
621+ quote_expr ! ( ecx, self :: test:: TestDescAndFn {
622+ desc: $desc_expr,
623+ testfn: self :: test:: $variant_name( $fn_expr) ,
624+ } )
672625}
0 commit comments