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

Add error for trailing angle brackets. #57817

Merged
merged 3 commits into from
Jan 24, 2019
Merged

Conversation

davidtwco
Copy link
Member

Fixes #54521.

This PR adds a error (and accompanying machine applicable
suggestion) for trailing angle brackets on function calls with a
turbofish.

r? @estebank

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 21, 2019
@davidtwco
Copy link
Member Author

I think you can change this to use any instead of map().unwrap_or().

I might be missing something, but I don't think I can because this is a Option<P<GenericArgs>>?

@estebank
Copy link
Contributor

I might be missing something, but I don't think I can because this is a Option<P>?

Ah, you're right. I thought it was something like Vec<P<GenericArg>>. Carry on.

@estebank

This comment has been minimized.

@rust-highfive

This comment has been minimized.

This commit adds a error (and accompanying machine applicable
suggestion) for trailing angle brackets on function calls with a
turbofish.
This commit pluralizes error messages when more than a single trailing
`>` character is present.
This commit extends the trailing `>` detection to also work for paths
such as `Foo::<Bar>>:Baz`.

This involves making the existing check take the token that is expected
to follow the path being checked as a parameter.

Care is taken to ensure that this only happens on the construction of a
whole path segment and not a partial path segment (during recursion).

Through this enhancement, it was also observed that the ordering of
right shift token and greater than tokens was overfitted to the examples
being tested.

In practice, given a sequence of `>` characters: `>>>>>>>>>`
..then they will be split into `>>` eagerly: `>> >> >> >> >`.
..but when a `<` is prepended, then the first `>>` is split:
`<T> > >> >> >> >`
..and then when another `<` is prepended, a right shift is first again:
`Vec<<T>> >> >> >> >`

In the previous commits, a example that had two `<<` characters was
always used and therefore it was incorrectly assumed that `>>` would
always be first - but when there is a single `<`, this is not the case.
Copy link
Member Author

@davidtwco davidtwco left a comment

Choose a reason for hiding this comment

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

@estebank I've added a new commit handling another case, would appreciate if you could re-review.

//
// `PathStyle::Expr` is only provided at the root invocation and never in
// `parse_path_segment` to recurse and therefore can be checked to maintain
// this invariant.
Copy link
Member Author

Choose a reason for hiding this comment

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

@estebank do you know if this last sentence is accurate? It works and passes tests but I'm not sure if PathStyle::Expr was intended to make this condition hold.

Copy link
Contributor

Choose a reason for hiding this comment

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

It should be ok.

@estebank
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jan 22, 2019

📌 Commit 914d142 has been approved by estebank

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 22, 2019
Centril added a commit to Centril/rust that referenced this pull request Jan 23, 2019
Add error for trailing angle brackets.

Fixes rust-lang#54521.

This PR adds a error (and accompanying machine applicable
suggestion) for trailing angle brackets on function calls with a
turbofish.

r? @estebank
Centril added a commit to Centril/rust that referenced this pull request Jan 23, 2019
Add error for trailing angle brackets.

Fixes rust-lang#54521.

This PR adds a error (and accompanying machine applicable
suggestion) for trailing angle brackets on function calls with a
turbofish.

r? @estebank
bors added a commit that referenced this pull request Jan 24, 2019
Rollup of 11 pull requests

Successful merges:

 - #57179 (Update std/lib.rs docs to reflect Rust 2018 usage)
 - #57730 (Merge visitors in AST validation)
 - #57779 (Recover from parse errors in literal struct fields and incorrect float literals)
 - #57793 (Explain type mismatch cause pointing to return type when it is `impl Trait`)
 - #57795 (Use structured suggestion in stead of notes)
 - #57817 (Add error for trailing angle brackets.)
 - #57834 (Stabilize Any::get_type_id and rename to type_id)
 - #57836 (Fix some cross crate existential type ICEs)
 - #57840 (Fix issue 57762)
 - #57844 (use port 80 for retrieving GPG key)
 - #57858 (Ignore line ending on older git versions)

Failed merges:

r? @ghost
@bors
Copy link
Contributor

bors commented Jan 24, 2019

☔ The latest upstream changes (presumably #57869) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 24, 2019
@bors bors merged commit 914d142 into rust-lang:master Jan 24, 2019
@davidtwco davidtwco deleted the issue-54521 branch January 24, 2019 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants