Skip to content

Commit 6c681a8

Browse files
authored
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: 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
1 parent 9879cb9 commit 6c681a8

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

capnpc/src/codegen.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,7 @@ fn generate_node(gen: &GeneratorContext,
11541154
Indent(Box::new(Line("::capnp::traits::FromStructBuilder::new(builder.init_struct(_private::STRUCT_SIZE))".to_string()))),
11551155
Line("}".to_string()),
11561156
Line(format!("fn get_from_pointer(builder: ::capnp::private::layout::PointerBuilder<'a>) -> ::capnp::Result<Builder<'a,{}>> {{", params.params)),
1157-
Indent(Box::new(Line("::std::result::Result::Ok(::capnp::traits::FromStructBuilder::new(try!(builder.get_struct(_private::STRUCT_SIZE, ::std::ptr::null()))))".to_string()))),
1157+
Indent(Box::new(Line("::std::result::Result::Ok(::capnp::traits::FromStructBuilder::new(builder.get_struct(_private::STRUCT_SIZE, ::std::ptr::null())?))".to_string()))),
11581158
Line("}".to_string()))))),
11591159
Line("}".to_string()),
11601160
BlankLine]);
@@ -1218,7 +1218,7 @@ fn generate_node(gen: &GeneratorContext,
12181218
Indent(
12191219
Box::new(Branch(vec!(
12201220
Line(format!("fn get_from_pointer(reader: &::capnp::private::layout::PointerReader<'a>) -> ::capnp::Result<Reader<'a,{}>> {{",params.params)),
1221-
Indent(Box::new(Line("::std::result::Result::Ok(::capnp::traits::FromStructReader::new(try!(reader.get_struct(::std::ptr::null()))))".to_string()))),
1221+
Indent(Box::new(Line("::std::result::Result::Ok(::capnp::traits::FromStructReader::new(reader.get_struct(::std::ptr::null())?))".to_string()))),
12221222
Line("}".to_string()))))),
12231223
Line("}".to_string()),
12241224
BlankLine,
@@ -1551,7 +1551,7 @@ fn generate_node(gen: &GeneratorContext,
15511551
Indent(
15521552
Box::new(Branch(vec![
15531553
Line(format!("fn get_from_pointer(reader: &::capnp::private::layout::PointerReader<'a>) -> ::capnp::Result<Client<{}>> {{",params.params)),
1554-
Indent(Box::new(Line(format!("::std::result::Result::Ok(::capnp::capability::FromClientHook::new(try!(reader.get_capability())))")))),
1554+
Indent(Box::new(Line(format!("::std::result::Result::Ok(::capnp::capability::FromClientHook::new(reader.get_capability()?))")))),
15551555
Line("}".to_string())]))),
15561556
Line("}".to_string()))));
15571557

@@ -1565,7 +1565,7 @@ fn generate_node(gen: &GeneratorContext,
15651565
Indent(Box::new(Line("unimplemented!()".to_string()))),
15661566
Line("}".to_string()),
15671567
Line(format!("fn get_from_pointer(builder: ::capnp::private::layout::PointerBuilder<'a>) -> ::capnp::Result<Client<{}>> {{", params.params)),
1568-
Indent(Box::new(Line("::std::result::Result::Ok(::capnp::capability::FromClientHook::new(try!(builder.get_capability())))".to_string()))),
1568+
Indent(Box::new(Line("::std::result::Result::Ok(::capnp::capability::FromClientHook::new(builder.get_capability()?))".to_string()))),
15691569
Line("}".to_string())]))),
15701570
Line("}".to_string()),
15711571
BlankLine]));

0 commit comments

Comments
 (0)