mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Ignore proc-macro stdout to prevent IPC crash
This commit is contained in:
parent
4b997b8663
commit
f41ae64722
@ -77,13 +77,24 @@ impl Message for Request {}
|
|||||||
impl Message for Response {}
|
impl Message for Response {}
|
||||||
|
|
||||||
fn read_json(inp: &mut impl BufRead) -> io::Result<Option<String>> {
|
fn read_json(inp: &mut impl BufRead) -> io::Result<Option<String>> {
|
||||||
|
loop {
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
inp.read_line(&mut buf)?;
|
inp.read_line(&mut buf)?;
|
||||||
buf.pop(); // Remove trailing '\n'
|
buf.pop(); // Remove trailing '\n'
|
||||||
Ok(match buf.len() {
|
|
||||||
0 => None,
|
if buf.is_empty() {
|
||||||
_ => Some(buf),
|
return Ok(None);
|
||||||
})
|
}
|
||||||
|
|
||||||
|
// Some ill behaved macro try to use stdout for debugging
|
||||||
|
// We ignore it here
|
||||||
|
if !buf.starts_with("{") {
|
||||||
|
log::error!("proc-macro tried to print : {}", buf);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(Some(buf));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_json(out: &mut impl Write, msg: &str) -> io::Result<()> {
|
fn write_json(out: &mut impl Write, msg: &str) -> io::Result<()> {
|
||||||
|
@ -712,6 +712,10 @@ pub fn foo(_input: TokenStream) -> TokenStream {
|
|||||||
// We hard code the output here for preventing to use any deps
|
// We hard code the output here for preventing to use any deps
|
||||||
let mut res = TokenStream::new();
|
let mut res = TokenStream::new();
|
||||||
|
|
||||||
|
// ill behaved proc-macro will use the stdout
|
||||||
|
// we should ignore it
|
||||||
|
println!("I am bad guy");
|
||||||
|
|
||||||
// impl Bar for Foo { fn bar() {} }
|
// impl Bar for Foo { fn bar() {} }
|
||||||
let mut tokens = vec![t!("impl"), t!("Bar"), t!("for"), t!("Foo")];
|
let mut tokens = vec![t!("impl"), t!("Bar"), t!("for"), t!("Foo")];
|
||||||
let mut fn_stream = TokenStream::new();
|
let mut fn_stream = TokenStream::new();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user