From d8948debc3ce983cd0639e1608afc242431cf09e Mon Sep 17 00:00:00 2001 From: bmisiak <2332213+bmisiak@users.noreply.github.com> Date: Sat, 6 Oct 2018 14:53:25 -0700 Subject: [PATCH] Switch from try!() to ? in generated code to make it work in Rust 2018 Rust 2018 removes the `try!()` macro and makes `try` a reserved keyword in accordance with RFC 2388: https://github.com/rust-lang/rfcs/pull/2388. On the other hand, the `?` operator was introduced way back in Rust 1.13 and is now stable. Without the change, rustc will refuse to compile the generated code starting with the 2018 edition. While this project itself is free to use `try!()` and not switch to Rust 2018, its output files - preferably - should be compatible with both editions. https://github.com/rust-lang/rust/issues/31436 --- capnpc/src/codegen.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/capnpc/src/codegen.rs b/capnpc/src/codegen.rs index af6d818a4..579143278 100644 --- a/capnpc/src/codegen.rs +++ b/capnpc/src/codegen.rs @@ -1154,7 +1154,7 @@ fn generate_node(gen: &GeneratorContext, Indent(Box::new(Line("::capnp::traits::FromStructBuilder::new(builder.init_struct(_private::STRUCT_SIZE))".to_string()))), Line("}".to_string()), Line(format!("fn get_from_pointer(builder: ::capnp::private::layout::PointerBuilder<'a>) -> ::capnp::Result> {{", params.params)), - Indent(Box::new(Line("::std::result::Result::Ok(::capnp::traits::FromStructBuilder::new(try!(builder.get_struct(_private::STRUCT_SIZE, ::std::ptr::null()))))".to_string()))), + Indent(Box::new(Line("::std::result::Result::Ok(::capnp::traits::FromStructBuilder::new(builder.get_struct(_private::STRUCT_SIZE, ::std::ptr::null())?))".to_string()))), Line("}".to_string()))))), Line("}".to_string()), BlankLine]); @@ -1218,7 +1218,7 @@ fn generate_node(gen: &GeneratorContext, Indent( Box::new(Branch(vec!( Line(format!("fn get_from_pointer(reader: &::capnp::private::layout::PointerReader<'a>) -> ::capnp::Result> {{",params.params)), - Indent(Box::new(Line("::std::result::Result::Ok(::capnp::traits::FromStructReader::new(try!(reader.get_struct(::std::ptr::null()))))".to_string()))), + Indent(Box::new(Line("::std::result::Result::Ok(::capnp::traits::FromStructReader::new(reader.get_struct(::std::ptr::null())?))".to_string()))), Line("}".to_string()))))), Line("}".to_string()), BlankLine, @@ -1551,7 +1551,7 @@ fn generate_node(gen: &GeneratorContext, Indent( Box::new(Branch(vec![ Line(format!("fn get_from_pointer(reader: &::capnp::private::layout::PointerReader<'a>) -> ::capnp::Result> {{",params.params)), - Indent(Box::new(Line(format!("::std::result::Result::Ok(::capnp::capability::FromClientHook::new(try!(reader.get_capability())))")))), + Indent(Box::new(Line(format!("::std::result::Result::Ok(::capnp::capability::FromClientHook::new(reader.get_capability()?))")))), Line("}".to_string())]))), Line("}".to_string())))); @@ -1565,7 +1565,7 @@ fn generate_node(gen: &GeneratorContext, Indent(Box::new(Line("unimplemented!()".to_string()))), Line("}".to_string()), Line(format!("fn get_from_pointer(builder: ::capnp::private::layout::PointerBuilder<'a>) -> ::capnp::Result> {{", params.params)), - Indent(Box::new(Line("::std::result::Result::Ok(::capnp::capability::FromClientHook::new(try!(builder.get_capability())))".to_string()))), + Indent(Box::new(Line("::std::result::Result::Ok(::capnp::capability::FromClientHook::new(builder.get_capability()?))".to_string()))), Line("}".to_string())]))), Line("}".to_string()), BlankLine]));