Skip to content
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

Bounds parsing refactoring 2 #39158

Merged
merged 5 commits into from
Jan 27, 2017
Merged

Bounds parsing refactoring 2 #39158

merged 5 commits into from
Jan 27, 2017

Conversation

petrochenkov
Copy link
Contributor

@petrochenkov petrochenkov commented Jan 18, 2017

See #37511 for previous discussion.
cc @matklad

Relaxed parsing rules:

  • zero bounds after : are allowed in all contexts.
  • zero predicates are allowed after where.
  • trailing separator , is allowed after predicates in where clauses not followed by {.

Other parsing rules:

  • trailing separator + is still allowed in all bound lists.

Code is also cleaned up and tests added.

I haven't touched parsing of trait object types yet, I'll do it later.

@rust-highfive
Copy link
Collaborator

r? @nikomatsakis

(rust_highfive has picked a reviewer for you, use r? to override)

@durka
Copy link
Contributor

durka commented Jan 18, 2017

Why disallow trailing + when trailing , is allowed? Does it create an ambiguity?

@petrochenkov
Copy link
Contributor Author

@durka
No ambiguity, it's a lang team decision.

(I'd personally keep it though, because 1) uniformity (other trailing separators are allowed), 2) it was accepted since 1.0 until now, 3) it's "naturally" allowed and you have to add extra code to the parser to prohibit it)

@petrochenkov
Copy link
Contributor Author

@durka
Do you have an example of trailing + being useful in macros?

@durka
Copy link
Contributor

durka commented Jan 18, 2017 via email

@durka
Copy link
Contributor

durka commented Jan 18, 2017 via email

@petrochenkov
Copy link
Contributor Author

But then again you don't want "1 + 1 +" to be a valid
arithmetic expression.

Expression + and type + are actually different! 🙂
Expression + is a binary operator and lists like 1 + 1 + 1 + 1 are desugared into several operator applications ((1 + 1) + 1) + 1.
Type + is not a binary operator and summands in lists like Trait + Trait + Trait can't be grouped. (Trait + Trait) + Trait and ArbitraryType + Trait in general are not valid.

@nikomatsakis
Copy link
Contributor

@petrochenkov I feel like I would keep it too -- which is probably why it's parsed in the first place. I wonder if it's worth revisiting this. I found your three points convincing, and I'm not sure that we focus on the backwards compatibility point in the meeting.

cc @rust-lang/lang -- we had previously decided to not accept T: Foo + Bar + (where + acts as a trailing separator) because it "looks weird" (which is indisputably true). However, @petrochenkov points out that it is accepted today (also indisputably true). "Looking weird" doesn't feel like reason enough to break backwards compatibility to me, particularly since accepting trailing separators is known to be useful for macros. So I think I'd like to revisit this decision. What do people think?

@withoutboats
Copy link
Contributor

I think when we agreed on that we thought we were talking about expanding what is accepted to include trailing +. I agree we shouldn't break the language.

@joshtriplett
Copy link
Member

@nikomatsakis If we accept this today, we should continue doing so, and document it for potential use by macros. Not worth breaking backward compatibility over.

@aturon
Copy link
Member

aturon commented Jan 21, 2017

@nikomatsakis I agree with your reasoning; let's keep it.

@nikomatsakis
Copy link
Contributor

@petrochenkov care to update the PR to accept trailing +?

@nrc you were the main one who objected, I think, so I'd like to get your input in particular

(Does anyone feel we need to use rfcbot here?)

@nrc
Copy link
Member

nrc commented Jan 23, 2017

@nikomatsakis yeah, I agree its not worth breaking for.

@petrochenkov
Copy link
Contributor Author

Updated with trailing +s permitted.

@nikomatsakis
Copy link
Contributor

@bors r+

Thanks @petrochenkov !

@bors
Copy link
Contributor

bors commented Jan 25, 2017

📌 Commit 65aeafa has been approved by nikomatsakis

@nikomatsakis
Copy link
Contributor

@bors r-

@nikomatsakis
Copy link
Contributor

Oops :) had one thing I wanted to ask

}
}
for predicate in &g.where_clause.predicates {
if let WherePredicate::EqPredicate(ref predicate) = *predicate {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh, we should really remove this variant from the compiler (and parser)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be clear, not as part of this PR =)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no plans to implement this?
Then #20041 should be officially closed or something before removing WherePredicate::EqPredicate.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, eventually perhaps, but at the moment there are some theoretical limitations that I do not yet know how to overcome. I would say "we may implement it eventually, but in that case we can add that stuff back in to the compiler".

// BORROWED POINTER
self.expect_and()?;
self.parse_borrowed_pointee()?
} else if self.check_keyword(keywords::For) {
// FIXME plus priority
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify what this FIXME means? Ideally, if there's an actual bug we care about here, we'd open an issue describing what is going on. Otherwise, maybe just leave it out. =)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+ still has high priority in some cases.

The first case is when trait object type starts with for:

trait Tr<'a> {}
fn f(arg: &for<'a> Tr<'a> + Send){} // Parsed as &(for<'a> Tr<'a> + Send)

I'm going to fix this in upcoming PR so I didn't create an issue.

The second case is impl Trait1 + Trait2 and it seems to be known.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated with better comments for FIXMEs.

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jan 26, 2017

📌 Commit bd4d5ec has been approved by nikomatsakis

@bors
Copy link
Contributor

bors commented Jan 26, 2017

⌛ Testing commit bd4d5ec with merge d68ec42...

@bors
Copy link
Contributor

bors commented Jan 26, 2017

💔 Test failed - status-travis

@alexcrichton
Copy link
Member

alexcrichton commented Jan 26, 2017 via email

@bors
Copy link
Contributor

bors commented Jan 27, 2017

⌛ Testing commit bd4d5ec with merge 989cc5d...

@alexcrichton
Copy link
Member

@bors: retry

  • fiddling with homu

@bors
Copy link
Contributor

bors commented Jan 27, 2017

⌛ Testing commit bd4d5ec with merge 23a9469...

bors added a commit that referenced this pull request Jan 27, 2017
Bounds parsing refactoring 2

See #37511 for previous discussion.
cc @matklad

Relaxed parsing rules:
 - zero bounds after `:` are allowed in all contexts.
 - zero predicates are allowed after `where`.
- trailing separator `,` is allowed after predicates in `where` clauses not followed by `{`.

Other parsing rules:
 - trailing separator `+` is still allowed in all bound lists.

Code is also cleaned up and tests added.

I haven't touched parsing of trait object types yet, I'll do it later.
@bors
Copy link
Contributor

bors commented Jan 27, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: nikomatsakis
Pushing 23a9469 to master...

@bors bors merged commit bd4d5ec into rust-lang:master Jan 27, 2017
@petrochenkov petrochenkov deleted the bounds branch March 16, 2017 19:43
matklad added a commit to intellij-rust/intellij-rust that referenced this pull request Mar 21, 2017
@bors
Copy link
Contributor

bors commented Apr 12, 2017

💥 Test timed out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants