Skip to content

Commit 2c6b7b9

Browse files
committed
remove FIXME(rust-lang#2543) and avoid bad copies
1 parent fd00755 commit 2c6b7b9

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/libsyntax/test.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -627,8 +627,15 @@ fn path_node(ids: Vec<Ident>) -> ast::Path {
627627
}
628628

629629
fn path_name_i(idents: &[Ident]) -> String {
630-
// FIXME: Bad copies (#2543 -- same for everything else that says "bad")
631-
idents.iter().map(|i| i.to_string()).collect::<Vec<String>>().join("::")
630+
let mut path_name = "".to_string();
631+
let mut idents_iter = idents.iter().peekable();
632+
while let Some(ident) = idents_iter.next() {
633+
path_name.push_str(&ident.name.as_str());
634+
if let Some(_) = idents_iter.peek() {
635+
path_name.push_str("::")
636+
}
637+
}
638+
path_name
632639
}
633640

634641
fn mk_tests(cx: &TestCtxt) -> P<ast::Item> {
@@ -681,7 +688,6 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> P<ast::Expr> {
681688
// gensym information.
682689

683690
let span = ignored_span(cx, test.span);
684-
let path = test.path.clone();
685691
let ecx = &cx.ext_cx;
686692
let self_id = ecx.ident_of("self");
687693
let test_id = ecx.ident_of("test");
@@ -693,10 +699,11 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> P<ast::Expr> {
693699
// creates $name: $expr
694700
let field = |name, expr| ecx.field_imm(span, ecx.ident_of(name), expr);
695701

696-
debug!("encoding {}", path_name_i(&path[..]));
697-
698702
// path to the #[test] function: "foo::bar::baz"
699-
let path_string = path_name_i(&path[..]);
703+
let path_string = path_name_i(&test.path[..]);
704+
705+
debug!("encoding {}", path_string);
706+
700707
let name_expr = ecx.expr_str(span, Symbol::intern(&path_string));
701708

702709
// self::test::StaticTestName($name_expr)
@@ -743,7 +750,7 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> P<ast::Expr> {
743750
diag.bug("expected to find top-level re-export name, but found None");
744751
}
745752
};
746-
visible_path.extend(path);
753+
visible_path.extend_from_slice(&test.path[..]);
747754

748755
// Rather than directly give the test function to the test
749756
// harness, we create a wrapper like one of the following:

0 commit comments

Comments
 (0)