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

Introduce TyErr independent from TyInfer #40887

Merged
merged 2 commits into from
Apr 8, 2017

Conversation

estebank
Copy link
Contributor

@estebank estebank commented Mar 29, 2017

Add a TyErr type to represent unknown types in places where
parse errors have happened, while still able to build the AST.

Initially only used to represent incorrectly written fn arguments and
avoid "expected X parameters, found Y" errors when called with the
appropriate amount of parameters. We cannot use TyInfer for this as
_ is not allowed as a valid argument type.

Example output:

error: expected one of `:` or `@`, found `,`
  --> file.rs:12:9
   |
12 | fn bar(x, y: usize) {}
   |         ^

error[E0061]: this function takes 2 parameters but 3 parameters were supplied
  --> file.rs:19:9
   |
12 | fn bar(x, y) {}
   | --------------- defined here
...
19 |     bar(1, 2, 3);
   |         ^^^^^^^ expected 2 parameters

Fix #34264.

@rust-highfive
Copy link
Collaborator

r? @pnkfelix

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

@estebank estebank force-pushed the ty-placeholder branch 2 times, most recently from ed0e5dd to 0835f7c Compare March 29, 2017 02:11
@petrochenkov
Copy link
Contributor

TyError would be a more appropriate name (by analogy with TypeVariants::TyError or Def::Err doing the similar job).

@@ -4330,6 +4330,26 @@ impl<'a> Parser<'a> {

fn parse_fn_args(&mut self, named_args: bool, allow_variadic: bool)
-> PResult<'a, (Vec<Arg> , bool)> {

/// Create a placeholder argument
fn dummy_arg(span: Span) -> Arg {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: error reporting is a "cold" code for a reader trying to understand the main logic (syntax of fn arguments in this case), it often makes sense to factor it into a separate function (already done) and move it somewhere else, so it's invisible unless intentionally looked for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@estebank
Copy link
Contributor Author

estebank commented Apr 2, 2017

@petrochenkov done.

@estebank estebank changed the title Introduce TyPlaceholder independent from TyInfer Introduce TyErr independent from TyInfer Apr 2, 2017
Add a `TyErr` type to represent unknown types in places where
parse errors have happened, while still able to build the AST.

Initially only used to represent incorrectly written fn arguments and
avoid "expected X parameters, found Y" errors when called with the
appropriate amount of parameters. We cannot use `TyInfer` for this as
`_` is not allowed as a valid argument type.

Example output:

```rust
error: expected one of `:` or `@`, found `,`
  --> file.rs:12:9
   |
12 | fn bar(x, y: usize) {}
   |         ^

error[E0061]: this function takes 2 parameters but 3 parameters were supplied
  --> file.rs:19:9
   |
12 | fn bar(x, y) {}
   | --------------- defined here
...
19 |     bar(1, 2, 3);
   |         ^^^^^^^ expected 2 parameters
```
@arielb1
Copy link
Contributor

arielb1 commented Apr 6, 2017

r? @petrochenkov

@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Apr 6, 2017

📌 Commit b83352e has been approved by petrochenkov

@bors
Copy link
Contributor

bors commented Apr 7, 2017

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

@estebank estebank force-pushed the ty-placeholder branch 2 times, most recently from 60b37ee to d01bc33 Compare April 7, 2017 21:55
@estebank
Copy link
Contributor Author

estebank commented Apr 8, 2017

@bors r=petrochenkov
fixed merge conflicts

@bors
Copy link
Contributor

bors commented Apr 8, 2017

📌 Commit 8c31412 has been approved by petrochenkov

@bors
Copy link
Contributor

bors commented Apr 8, 2017

⌛ Testing commit 8c31412 with merge 566afe4...

@bors
Copy link
Contributor

bors commented Apr 8, 2017

💔 Test failed - status-appveyor

@TimNN
Copy link
Contributor

TimNN commented Apr 8, 2017

@bors retry

#41147

@bors
Copy link
Contributor

bors commented Apr 8, 2017

⌛ Testing commit 8c31412 with merge fe39e94...

bors added a commit that referenced this pull request Apr 8, 2017
Introduce `TyErr` independent from `TyInfer`

Add a `TyErr` type to represent unknown types in places where
parse errors have happened, while still able to build the AST.

Initially only used to represent incorrectly written fn arguments and
avoid "expected X parameters, found Y" errors when called with the
appropriate amount of parameters. We cannot use `TyInfer` for this as
`_` is not allowed as a valid argument type.

Example output:

```rust
error: expected one of `:` or `@`, found `,`
  --> file.rs:12:9
   |
12 | fn bar(x, y: usize) {}
   |         ^

error[E0061]: this function takes 2 parameters but 3 parameters were supplied
  --> file.rs:19:9
   |
12 | fn bar(x, y) {}
   | --------------- defined here
...
19 |     bar(1, 2, 3);
   |         ^^^^^^^ expected 2 parameters
```

Fix #34264.
@bors
Copy link
Contributor

bors commented Apr 8, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: petrochenkov
Pushing fe39e94 to master...

@bors bors merged commit 8c31412 into rust-lang:master Apr 8, 2017
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.

7 participants