Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 5f3327a

Browse files
author
KarlWithK
committed
Correctly fix formatting doc tests with generics
Before the doc_test would be outputted like this: "Foo<T, U>::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, U>::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
1 parent 89faff7 commit 5f3327a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

crates/ide/src/runnables.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,8 @@ fn module_def_doctest(db: &RootDatabase, def: Definition) -> Option<Runnable> {
426426
ty_args.format_with(", ", |ty, cb| cb(&ty.display(db)))
427427
);
428428
}
429-
format_to!(path, "::{}", def_name);
430-
return Some(path);
429+
format_to!(path, "::{}\"", def_name);
430+
return Some(format!("\"{}", path));
431431
}
432432
}
433433
}
@@ -966,7 +966,7 @@ impl Data {
966966
},
967967
kind: DocTest {
968968
test_id: Path(
969-
"Data::foo",
969+
"\"Data::foo\"",
970970
),
971971
},
972972
cfg: None,
@@ -1360,7 +1360,7 @@ impl Foo {
13601360
},
13611361
kind: DocTest {
13621362
test_id: Path(
1363-
"foo::Foo::foo",
1363+
"\"foo::Foo::foo\"",
13641364
),
13651365
},
13661366
cfg: None,
@@ -2066,7 +2066,7 @@ impl<T, U> Foo<T, U> {
20662066
},
20672067
kind: DocTest {
20682068
test_id: Path(
2069-
"Foo<T, U>::t",
2069+
"\"Foo<T, U>::t\"",
20702070
),
20712071
},
20722072
cfg: None,

0 commit comments

Comments
 (0)