diff options
| author | bors <bors@rust-lang.org> | 2018-03-27 07:16:29 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-03-27 07:16:29 +0000 |
| commit | 14ac1b5faab32d268a85dfde6c6592b7183c5864 (patch) | |
| tree | e276b99607fbb4e812cdde3857510407ccdc2f66 /src/libsyntax | |
| parent | 31ae4f9fde9b23100c26e5642030128a7e1444ef (diff) | |
| parent | ad50f3389a13d74aa0088bcb39c406193b721769 (diff) | |
| download | rust-14ac1b5faab32d268a85dfde6c6592b7183c5864.tar.gz rust-14ac1b5faab32d268a85dfde6c6592b7183c5864.zip | |
Auto merge of #49279 - varkor:generated-closure-return-type, r=alexcrichton
Fix implicit closure return type generation for libsyntax The `lambda` function for constructing closures in libsyntax was explicitly setting the return type to `_`, which resulted in incorrect corresponding syntax (as `|| -> _ x` is not valid, without the enclosing brackets). This meant the generated code, when printed, was invalid. I also took the opportunity to slightly improve the generated code for the `RustcEncodable::encode` method for unit structs. Fixes #42213.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/build.rs | 10 | ||||
| -rw-r--r-- | src/libsyntax/test.rs | 2 |
2 files changed, 6 insertions, 6 deletions
diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 9b53553bf69..269517e998f 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -214,7 +214,7 @@ pub trait AstBuilder { fn arg(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> ast::Arg; // FIXME unused self - fn fn_decl(&self, inputs: Vec<ast::Arg> , output: P<ast::Ty>) -> P<ast::FnDecl>; + fn fn_decl(&self, inputs: Vec<ast::Arg> , output: ast::FunctionRetTy) -> P<ast::FnDecl>; fn item_fn_poly(&self, span: Span, @@ -924,7 +924,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { -> P<ast::Expr> { let fn_decl = self.fn_decl( ids.iter().map(|id| self.arg(span, *id, self.ty_infer(span))).collect(), - self.ty_infer(span)); + ast::FunctionRetTy::Default(span)); // FIXME -- We are using `span` as the span of the `|...|` // part of the lambda, but it probably (maybe?) corresponds to @@ -970,10 +970,10 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } // FIXME unused self - fn fn_decl(&self, inputs: Vec<ast::Arg>, output: P<ast::Ty>) -> P<ast::FnDecl> { + fn fn_decl(&self, inputs: Vec<ast::Arg>, output: ast::FunctionRetTy) -> P<ast::FnDecl> { P(ast::FnDecl { inputs, - output: ast::FunctionRetTy::Ty(output), + output, variadic: false }) } @@ -1003,7 +1003,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.item(span, name, Vec::new(), - ast::ItemKind::Fn(self.fn_decl(inputs, output), + ast::ItemKind::Fn(self.fn_decl(inputs, ast::FunctionRetTy::Ty(output)), ast::Unsafety::Normal, dummy_spanned(ast::Constness::NotConst), Abi::Rust, diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index 6c01171d100..67a822e4e02 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -547,7 +547,7 @@ fn mk_main(cx: &mut TestCtxt) -> P<ast::Item> { // pub fn main() { ... } let main_ret_ty = ecx.ty(sp, ast::TyKind::Tup(vec![])); let main_body = ecx.block(sp, vec![call_test_main]); - let main = ast::ItemKind::Fn(ecx.fn_decl(vec![], main_ret_ty), + let main = ast::ItemKind::Fn(ecx.fn_decl(vec![], ast::FunctionRetTy::Ty(main_ret_ty)), ast::Unsafety::Normal, dummy_spanned(ast::Constness::NotConst), ::abi::Abi::Rust, ast::Generics::default(), main_body); |
