Auto merge of #40887 - estebank:ty-placeholder, r=petrochenkov

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.
This commit is contained in:
bors 2017-04-08 11:47:48 +00:00
commit fe39e94d6c
14 changed files with 113 additions and 5 deletions

View file

@ -0,0 +1,20 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn foo(Option<i32>, String) {}
fn bar(x, y: usize) {}
fn main() {
foo(Some(42), 2);
foo(Some(42), 2, "");
bar("", "");
bar(1, 2);
bar(1, 2, 3);
}

View file

@ -0,0 +1,49 @@
error: expected one of `:` or `@`, found `<`
--> $DIR/issue-34264.rs:11:14
|
11 | fn foo(Option<i32>, String) {}
| ^ expected one of `:` or `@` here
error: expected one of `:` or `@`, found `)`
--> $DIR/issue-34264.rs:11:27
|
11 | fn foo(Option<i32>, String) {}
| ^ expected one of `:` or `@` here
error: expected one of `:` or `@`, found `,`
--> $DIR/issue-34264.rs:12:9
|
12 | fn bar(x, y: usize) {}
| ^ expected one of `:` or `@` here
error[E0061]: this function takes 2 parameters but 3 parameters were supplied
--> $DIR/issue-34264.rs:16:9
|
11 | fn foo(Option<i32>, String) {}
| ------------------------------ defined here
...
16 | foo(Some(42), 2, "");
| ^^^^^^^^^^^^^^^ expected 2 parameters
error[E0308]: mismatched types
--> $DIR/issue-34264.rs:17:13
|
17 | bar("", "");
| ^^ expected usize, found reference
|
= note: expected type `usize`
found type `&'static str`
= help: here are some functions which might fulfill your needs:
- .len()
error[E0061]: this function takes 2 parameters but 3 parameters were supplied
--> $DIR/issue-34264.rs:19:9
|
12 | fn bar(x, y: usize) {}
| ---------------------- defined here
...
19 | bar(1, 2, 3);
| ^^^^^^^ expected 2 parameters
error: aborting due to 3 previous errors