From 5f3327a6b8925791ecdd9dbecb1bf1537c3ef9fc Mon Sep 17 00:00:00 2001 From: KarlWithK Date: Thu, 17 Feb 2022 20:27:37 -0600 Subject: [PATCH] Correctly fix formatting doc tests with generics Before the doc_test would be outputted like this: "Foo::t" However, this would cause shells with shell redirection. I've changed it so when generics are involved we simply wrap the expression under escape chanters as so: "\"Foo::t\"" Note: At the cost of adding this, I had to allocate a new string via format!{}. However, I argue this is alright as this for just for outputting the name of the doc test. The following tests have been changed: runnables::tests::doc_test_type_params runnables::tests::test_doc_runnables_impl_mod runnables::tests::test_runnables_doc_test_in_impl --- crates/ide/src/runnables.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index 67062654d6..39af47ebc6 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs @@ -426,8 +426,8 @@ fn module_def_doctest(db: &RootDatabase, def: Definition) -> Option { ty_args.format_with(", ", |ty, cb| cb(&ty.display(db))) ); } - format_to!(path, "::{}", def_name); - return Some(path); + format_to!(path, "::{}\"", def_name); + return Some(format!("\"{}", path)); } } } @@ -966,7 +966,7 @@ impl Data { }, kind: DocTest { test_id: Path( - "Data::foo", + "\"Data::foo\"", ), }, cfg: None, @@ -1360,7 +1360,7 @@ impl Foo { }, kind: DocTest { test_id: Path( - "foo::Foo::foo", + "\"foo::Foo::foo\"", ), }, cfg: None, @@ -2066,7 +2066,7 @@ impl Foo { }, kind: DocTest { test_id: Path( - "Foo::t", + "\"Foo::t\"", ), }, cfg: None,