-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
syntax: Trait object types permit extra parentheses on the first bound #39318
Comments
Needs a P-tag. Thanks for the fixes @petrochenkov |
I'm removing Nominated -- it's not clear that we want to actually enforce this rule. See the discussion on #40043 |
Refactor parsing of trait object types Bugs are fixed and code is cleaned up. User visible changes: - `ty` matcher in macros accepts trait object types like `Write + Send` (#39080) - Buggy priority of `+` in trait object types starting with `for` is fixed (#39317). `&for<'a> Trait<'a> + Send` is now parsed as `(&for<'a> Trait<'a>) + Send` and requires parens `&(for<'a> Trait<'a> + Send)`. For comparison, `&Send + for<'a> Trait<'a>` was parsed like this since [Nov 27, 2014](#19298). - Trailing `+`s are supported in trait objects, like in other bounds. - Better error reporting for trait objects starting with `?Sized`. Fixes #39080 Fixes #39317 [breaking-change] Closes #39298 cc #39085 (fixed, then reverted #40043 (comment)) cc #39318 (fixed, then reverted #40043 (comment)) r? @nikomatsakis
Nominating for lang-team discussion: there was some back and forth on the original PR. We should figure out what is the right venue/process to finalize decision here. |
OK, we talked about this in @rust-lang/lang meeting. We decided that it'd be best to have the discussion stay on this issue, and we can just do a "rfcbot" final decision here when needed. I think there was also some agreement @petrochenkov that it makes sense to support Nonetheless there was some reluctance to break code that is using parentheses. It's not entirely clear why that should be required. So one question that @pnkfelix wanted to clarify was: Can you elaborate on why you would not want to permit
Is it simply that there are no other operators in where-clauses, and hence supporting parentheses is sort of unnecessary? (Put another way, the idea of allowing all bounds to accepts parens is appealing and seems natural enough.) |
Ok, I'll try to elaborate. |
I. The parens are only for backward compatibility and not useful enough on their own. Assume for a minute that the 1.6 regression never happened, the parens are not accepted, and I'm submitting a new RFC proposing to add parentheses to the bounds grammar. The best solution from this position is what I did in #40043 originally - continue parsing the parens around the first bound, as they are parsed now, but issue a warning. The warning can be turned into a hard error eventually, maybe in half a year, maybe later, it's not especially important. |
II. The parens are legitimately useful. It may be reasonable to visually emphasize that Nicer grouping is still not a very strong motivation, so even if we add it, we should not sacrifice other important properties. Now let's explore some possible syntax additions.
|
Ok, now I spent more than an hour of time fleshing out the details of this completely worthless feature. |
Until I read #39318 (comment) , I agreed with the first position: only useful for backward compatibility. However, I find your example of Based on that comment, in the absence of some hard conflict with another grammar feature, I'd be tempted to say "keep parentheses, and don't deprecate them". I'd even be inclined to say that the style guide should recommend them around |
@petrochenkov I agree we shouldn't spend too much time on this; I don't even want to spend the time to track a deprecation. That's why I want to just accept parens in bounds and be done with it. There are a number of quirks that we accept for backwards compatibility reasons (especially in bounds syntax, such as trailing |
Seems like lang team has an idea what to do here. Let's try to resolve quickly one way or the other. |
Deprecation is certainly easier (add couple of lines of code + test, then remove them) and affects only rustc. |
@petrochenkov A parsing impl needs to support it and the reference needs to mention it, but paren grouping of operations is not a very foreign concept to most users (if it is they'll have to learn it anyway for other uses) & we don't ever recommend using it. I really don't see these as significant costs. Deprecation of course does not only impact rustc but it also impacts any users who were using parens in their trait objects. Do we have crater results on that? Its also plausible that we will create bound operators someday other than I don't feel strongly about this and it seems like you do, so a part of me is inclined to just say we should do whatever. |
#40043 (comment) - three regressions, all are fixed upstream. |
@petrochenkov it feels funny to me to support parens but not |
As for your other examples:
I would reject this for now, but I could see eventually that it might be useful to be able to share the quantifier over multiple bounds (e.g., |
Every syntactic addition in this area adds more ambiguities and I'd want to avoid them unless really necessary. |
I think I'd really prefer to agree to a particular grammar here. It seems surprising to me to allow some forms of bounds to be parenthesized but not others -- e.g. I also don't have a problem with |
Disambiguation code just continues piling up when you add |
…akis syntax: Support parentheses around trait bounds An implementation for rust-lang#39318 (comment) r? @nikomatsakis
syntax: Parse trait object types starting with a lifetime bound Fixes #39085 This was originally implemented in #40043, then reverted, then there was some [agreement](#39318 (comment)) that it should be supported. (This is hopefully the last PR related to bound parsing.)
The syntax for object types is the same as for other bounds -
Bound + Bound + Bound + ....
and parentheses are not a part of bound syntax.This is a stable-stable regression, introduced in Rust 1.6 by #29870.
cc #39169 #39179
Current status
(Bound) + Bound + ....
is still parsed, but with a warning. This is a "hardcoded" warning and not a lint, lints cannot be reported from.libsyntax
The text was updated successfully, but these errors were encountered: