From 90a997fe11fccfce0f8b350e197f8356278d09a0 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 22 May 2014 15:06:07 -0700 Subject: [PATCH 1/2] RFC: Bounds on trait objects should be separated with `+` --- active/0000-trait-bounds-with-plus.md | 42 +++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 active/0000-trait-bounds-with-plus.md diff --git a/active/0000-trait-bounds-with-plus.md b/active/0000-trait-bounds-with-plus.md new file mode 100644 index 00000000000..65716031118 --- /dev/null +++ b/active/0000-trait-bounds-with-plus.md @@ -0,0 +1,42 @@ +- Start Date: 2014-05-22 +- RFC PR #: (leave this empty) +- Rust Issue #: (leave this empty) + +# Summary + +Bounds on trait objects should be separated with `+`. + +# Motivation + +With DST there is an ambiguity between the following two forms: + + trait X { + fn f(foo: b); + } + + +and + + trait X { + fn f(Trait: Share); + } + +See Rust issue #12778 for details. + +Also, since kinds are now just built-in traits, it makes sense to treat a bounded trait object as just a combination of traits. This could be extended in the future to allow objects consisting of arbitrary trait combinations. + +# Detailed design + +Instead of `:` in trait bounds for first-class traits (e.g. `&Trait:Share + Send`), we use `+` (e.g. `&Trait + Share + Send`). + +# Drawbacks + +It may be that `+` is ugly. Also, it messes with the precedence of `as`. (See Rust PR #14365 for the fallout of the latter.) + +# Alternatives + +The impact of not doing this is that the inconsistencies and ambiguities above remain. + +# Unresolved questions + +Where does the `'static` bound fit into all this? From 3eb709940d982e0e981d3da728f7cf2dfcd823c5 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 9 Jun 2014 13:40:30 -0700 Subject: [PATCH 2/2] Revision to add a type grammar restriction --- active/0000-trait-bounds-with-plus.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/active/0000-trait-bounds-with-plus.md b/active/0000-trait-bounds-with-plus.md index 65716031118..9238b126308 100644 --- a/active/0000-trait-bounds-with-plus.md +++ b/active/0000-trait-bounds-with-plus.md @@ -29,9 +29,13 @@ Also, since kinds are now just built-in traits, it makes sense to treat a bounde Instead of `:` in trait bounds for first-class traits (e.g. `&Trait:Share + Send`), we use `+` (e.g. `&Trait + Share + Send`). +`+` will not be permitted in `as` without parentheses. This will be done via a special *restriction* in the type grammar: the special `TYPE` production following `as` will be the same as the regular `TYPE` production, with the exception that it does not accept `+` as a binary operator. + # Drawbacks -It may be that `+` is ugly. Also, it messes with the precedence of `as`. (See Rust PR #14365 for the fallout of the latter.) +* It may be that `+` is ugly. + +* Adding a restriction complicates the type grammar more than I would prefer, but the community backlash against the previous proposal was overwhelming. # Alternatives