internal: cleanup proc macro server error handlig

When dealing with proc macros, there are two very different kinds of
errors:

* first, usual errors of "proc macro panicked on this particular input"
* second, the proc macro server might day if the user, eg, kills it

First kind of errors are expected and are a normal output, while the
second kind are genuine IO-errors.

For this reason, we use a curious nested result here: `Result<Result<T,
E1>, E2>` pattern, which is 100% inspired by http://sled.rs/errors.html
This commit is contained in:
Aleksey Kladov 2021-08-31 19:01:39 +03:00
parent 722a2a4690
commit d8a3d6f378
12 changed files with 242 additions and 271 deletions

View file

@ -3,7 +3,6 @@
use crate::dylib;
use crate::ProcMacroSrv;
use expect_test::Expect;
use proc_macro_api::ListMacrosTask;
use std::str::FromStr;
pub mod fixtures {
@ -40,9 +39,9 @@ fn assert_expand_impl(macro_name: &str, input: &str, attr: Option<&str>, expect:
expect.assert_eq(&format!("{:?}", res));
}
pub fn list() -> Vec<String> {
let task = ListMacrosTask { lib: fixtures::proc_macro_test_dylib_path() };
pub(crate) fn list() -> Vec<String> {
let dylib_path = fixtures::proc_macro_test_dylib_path();
let mut srv = ProcMacroSrv::default();
let res = srv.list_macros(&task).unwrap();
res.macros.into_iter().map(|(name, kind)| format!("{} [{:?}]", name, kind)).collect()
let res = srv.list_macros(&dylib_path).unwrap();
res.into_iter().map(|(name, kind)| format!("{} [{:?}]", name, kind)).collect()
}