]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #45294 - petrochenkov:prioplus, r=nikomatsakis
authorbors <bors@rust-lang.org>
Tue, 30 Jan 2018 08:23:41 +0000 (08:23 +0000)
committerbors <bors@rust-lang.org>
Tue, 30 Jan 2018 08:23:41 +0000 (08:23 +0000)
syntax: Lower priority of `+` in `impl Trait`/`dyn Trait`

Now you have to write `Fn() -> (impl A + B)` instead of `Fn() -> impl A + B`, this is consistent with priority of `+` in trait objects (`Fn() -> A + B` means `(Fn() -> A) + B`).

To make this viable I changed the syntax to also permit `+` in return types in function declarations
```
fn f() -> dyn A + B { ... } // OK, don't have to write `-> (dyn A + B)`

// This is acceptable, because `dyn A + B` here is an isolated type and
// not part of a larger type with various operator priorities in play
// like `dyn A + B` in `Fn() -> dyn A + B` despite syntax similarities.
```
but you still have to use `-> (dyn A + B)` in function types and function-like trait object types (see this PR's tests for examples).

This can be a breaking change for code using `impl Trait` on nightly. The thing that is most likely to break is `&impl A + B`, it needs to be rewritten as `&(impl A + B)`.

cc https://github.com/rust-lang/rust/issues/34511 https://github.com/rust-lang/rust/issues/44662 https://github.com/rust-lang/rfcs/pull/438

1  2 
src/libsyntax/parse/parser.rs

Simple merge