Skip to content

Commit 95d27c3

Browse files
committed
syntax: Permit + in return types of function declarations
`+` is still disallowed in function types and function-like traits
1 parent 873b775 commit 95d27c3

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/libsyntax/parse/parser.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,7 @@ impl<'a> Parser<'a> {
13621362

13631363
self.expect_keyword(keywords::Fn)?;
13641364
let (inputs, variadic) = self.parse_fn_args(false, true)?;
1365-
let ret_ty = self.parse_ret_ty()?;
1365+
let ret_ty = self.parse_ret_ty(false)?;
13661366
let decl = P(FnDecl {
13671367
inputs,
13681368
output: ret_ty,
@@ -1501,9 +1501,9 @@ impl<'a> Parser<'a> {
15011501
}
15021502

15031503
/// Parse optional return type [ -> TY ] in function decl
1504-
pub fn parse_ret_ty(&mut self) -> PResult<'a, FunctionRetTy> {
1504+
fn parse_ret_ty(&mut self, allow_plus: bool) -> PResult<'a, FunctionRetTy> {
15051505
if self.eat(&token::RArrow) {
1506-
Ok(FunctionRetTy::Ty(self.parse_ty_no_plus()?))
1506+
Ok(FunctionRetTy::Ty(self.parse_ty_common(allow_plus, true)?))
15071507
} else {
15081508
Ok(FunctionRetTy::Default(self.span.with_hi(self.span.lo())))
15091509
}
@@ -4893,7 +4893,7 @@ impl<'a> Parser<'a> {
48934893
pub fn parse_fn_decl(&mut self, allow_variadic: bool) -> PResult<'a, P<FnDecl>> {
48944894

48954895
let (args, variadic) = self.parse_fn_args(true, allow_variadic)?;
4896-
let ret_ty = self.parse_ret_ty()?;
4896+
let ret_ty = self.parse_ret_ty(true)?;
48974897

48984898
Ok(P(FnDecl {
48994899
inputs: args,
@@ -5034,7 +5034,7 @@ impl<'a> Parser<'a> {
50345034
self.expect(&token::CloseDelim(token::Paren))?;
50355035
Ok(P(FnDecl {
50365036
inputs: fn_inputs,
5037-
output: self.parse_ret_ty()?,
5037+
output: self.parse_ret_ty(true)?,
50385038
variadic: false
50395039
}))
50405040
}
@@ -5056,7 +5056,7 @@ impl<'a> Parser<'a> {
50565056
args
50575057
}
50585058
};
5059-
let output = self.parse_ret_ty()?;
5059+
let output = self.parse_ret_ty(true)?;
50605060

50615061
Ok(P(FnDecl {
50625062
inputs: inputs_captures,

src/test/compile-fail/private-inferred-type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ mod m {
7272
impl TraitWithAssocTy for u8 { type AssocTy = Priv; }
7373
//~^ ERROR private type `m::Priv` in public interface
7474

75-
pub fn leak_anon1() -> (impl Trait + 'static) { 0 }
75+
pub fn leak_anon1() -> impl Trait + 'static { 0 }
7676
pub fn leak_anon2() -> impl TraitWithTyParam<Alias> { 0 }
7777
pub fn leak_anon3() -> impl TraitWithAssocTy<AssocTy = Alias> { 0 }
7878

0 commit comments

Comments
 (0)