Skip to content

Commit

Permalink
Switch from try!() to ? in generated code to make it work in Rust 2018
Browse files Browse the repository at this point in the history
Rust 2018 removes the `try!()` macro and makes `try` a reserved keyword in accordance with RFC 2388: rust-lang/rfcs#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.

rust-lang/rust#31436
  • Loading branch information
bmisiak authored Oct 6, 2018
1 parent 3502749 commit d8948de
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions capnpc/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Builder<'a,{}>> {{", 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]);
Expand Down Expand Up @@ -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<Reader<'a,{}>> {{",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,
Expand Down Expand Up @@ -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<Client<{}>> {{",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()))));

Expand All @@ -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<Client<{}>> {{", 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]));
Expand Down

0 comments on commit d8948de

Please sign in to comment.