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

Fixed cast expression parsing in ra_syntax. #280

Merged
merged 1 commit into from
Dec 17, 2018

Conversation

ruabmbua
Copy link
Contributor

@ruabmbua ruabmbua commented Dec 17, 2018

Fixes #279
Related to #273

The cast expression expected any type via types::type_() function,
but the language spec does only allow TypeNoBounds (types without direct extra bounds
via +).

Example:

fn test() {
	6i8 as i32 + 5;
}

This fails, because the types::type_() function which should parse the type after the
as keyword is greedy, and takes the plus sign after path types as extra type bounds.

My proposed fix is to replace the not implemented type_no_plus() just calls (type_())
function, which is used at several places. The replacement is type_with_bounds_cond(p: &mut Parser, allow_bounds: bool), which passes the condition to relevant sub-parsers.

This function is then called by type_() and the new public type_no_bounds().

The cast expression expected any type via types::type_() function,
but the language spec does only allow TypeNoBounds (types without direct extra bounds
via `+`).

**Example:**

```rust
fn test() {
	6i8 as i32 + 5;
}
```

This fails, because the types::type_() function which should parse the type after the
as keyword is greedy, and takes all plus sign after path types as extra.

My proposed fix is to replace the not implemented `type_no_plus()` just calls (`type_()`)
function, which is used at several places. The replacement is `type_with_bounds_cond(p: &mut Parser, allow_bounds: bool)`, which passes the condition to relevant sub-parsers.

This function is then called by `type_()` and the new public `type_no_bounds()`.
@matklad
Copy link
Member

matklad commented Dec 17, 2018

Excellent, this is exactly how this should work, thanks!

bors +

@matklad
Copy link
Member

matklad commented Dec 17, 2018

bors r+

bors bot added a commit that referenced this pull request Dec 17, 2018
280: Fixed cast expression parsing in ra_syntax. r=matklad a=ruabmbua

Fixes #279 
Related to #273

The cast expression expected any type via types::type_() function,
but the language spec does only allow TypeNoBounds (types without direct extra bounds
via `+`).

**Example:**

```rust
fn test() {
	6i8 as i32 + 5;
}
```

This fails, because the types::type_() function which should parse the type after the
as keyword is greedy, and takes the plus sign after path types as extra type bounds.

My proposed fix is to replace the not implemented `type_no_plus()` just calls (`type_()`)
function, which is used at several places. The replacement is `type_with_bounds_cond(p: &mut Parser, allow_bounds: bool)`, which passes the condition to relevant sub-parsers.

This function is then called by `type_()` and the new public `type_no_bounds()`.

Co-authored-by: Roland Ruckerbauer <roland.rucky@gmail.com>
@bors
Copy link
Contributor

bors bot commented Dec 17, 2018

Build succeeded

@bors bors bot merged commit d0f1334 into rust-lang:master Dec 17, 2018
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.

Bug: operator precedence around **as** keyword is wrong
2 participants