aboutsummaryrefslogtreecommitdiff
path: root/crates/proc_macro_api/src
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2021-03-23 03:22:33 +0000
committerEdwin Cheng <[email protected]>2021-03-23 19:44:28 +0000
commitf41ae64722ab8e501e2123018d1b0101db32442e (patch)
treedc8b1bb7af970bdeb2fcad7316be9bb87a6ff928 /crates/proc_macro_api/src
parent4b997b86633b1c0ca134d89e8236d285422c04e3 (diff)
Ignore proc-macro stdout to prevent IPC crash
Diffstat (limited to 'crates/proc_macro_api/src')
-rw-r--r--crates/proc_macro_api/src/msg.rs25
1 files changed, 18 insertions, 7 deletions
diff --git a/crates/proc_macro_api/src/msg.rs b/crates/proc_macro_api/src/msg.rs
index 970f165ed..21e56cc83 100644
--- a/crates/proc_macro_api/src/msg.rs
+++ b/crates/proc_macro_api/src/msg.rs
@@ -77,13 +77,24 @@ impl Message for Request {}
77impl Message for Response {} 77impl Message for Response {}
78 78
79fn read_json(inp: &mut impl BufRead) -> io::Result<Option<String>> { 79fn read_json(inp: &mut impl BufRead) -> io::Result<Option<String>> {
80 let mut buf = String::new(); 80 loop {
81 inp.read_line(&mut buf)?; 81 let mut buf = String::new();
82 buf.pop(); // Remove trailing '\n' 82 inp.read_line(&mut buf)?;
83 Ok(match buf.len() { 83 buf.pop(); // Remove trailing '\n'
84 0 => None, 84
85 _ => Some(buf), 85 if buf.is_empty() {
86 }) 86 return Ok(None);
87 }
88
89 // Some ill behaved macro try to use stdout for debugging
90 // We ignore it here
91 if !buf.starts_with("{") {
92 log::error!("proc-macro tried to print : {}", buf);
93 continue;
94 }
95
96 return Ok(Some(buf));
97 }
87} 98}
88 99
89fn write_json(out: &mut impl Write, msg: &str) -> io::Result<()> { 100fn write_json(out: &mut impl Write, msg: &str) -> io::Result<()> {