diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2017-10-22 09:19:30 -0700 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2017-11-03 17:39:16 -0700 |
| commit | 9dc7abe06d2b2771b09b6dac6eef5ac83b58573f (patch) | |
| tree | b18ca574a970e3f54b58f73f5330a7429fe99298 /src/test | |
| parent | 5ce3d482e2313fe6795e6d688e62a092af424da8 (diff) | |
Detect `=` -> `:` typo in let bindings
When encountering a let binding type error, attempt to parse as
initializer instead. If successful, it is likely just a typo:
```rust
fn main() {
let x: Vec::with_capacity(10);
}
```
```
error: expected type, found `10`
--> file.rs:3:31
|
3 | let x: Vec::with_capacity(10, 20);
| -- ^^
| ||
| |help: did you mean assign here?: `=`
| while parsing the type for `x`
```
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/compile-fail/self-vs-path-ambiguity.rs | 1 | ||||
| -rw-r--r-- | src/test/parse-fail/issue-33413.rs | 1 | ||||
| -rw-r--r-- | src/test/ui/issue-44406.stderr | 11 | ||||
| -rw-r--r-- | src/test/ui/resolve/token-error-correct.stderr | 20 | ||||
| -rw-r--r-- | src/test/ui/suggestions/type-ascription-instead-of-initializer.rs | 13 | ||||
| -rw-r--r-- | src/test/ui/suggestions/type-ascription-instead-of-initializer.stderr | 17 |
6 files changed, 32 insertions, 31 deletions
diff --git a/src/test/compile-fail/self-vs-path-ambiguity.rs b/src/test/compile-fail/self-vs-path-ambiguity.rs index 9753014e781..b2dba3bd61b 100644 --- a/src/test/compile-fail/self-vs-path-ambiguity.rs +++ b/src/test/compile-fail/self-vs-path-ambiguity.rs @@ -17,7 +17,6 @@ impl S { fn g(&self::S: &S) {} fn h(&mut self::S: &mut S) {} fn i(&'a self::S: &S) {} //~ ERROR unexpected lifetime `'a` in pattern - //~^ ERROR expected one of `)` or `mut`, found `'a` } fn main() {} diff --git a/src/test/parse-fail/issue-33413.rs b/src/test/parse-fail/issue-33413.rs index 699af8ca7ab..25ae7b4c55a 100644 --- a/src/test/parse-fail/issue-33413.rs +++ b/src/test/parse-fail/issue-33413.rs @@ -12,5 +12,4 @@ impl S { fn f(*, a: u8) -> u8 {} //~ ERROR expected pattern, found `*` - //~^ ERROR expected one of `)`, `-`, `box`, `false`, `mut`, `ref`, or `true`, found `*` } diff --git a/src/test/ui/issue-44406.stderr b/src/test/ui/issue-44406.stderr index 9beae91540a..e7afbb574ef 100644 --- a/src/test/ui/issue-44406.stderr +++ b/src/test/ui/issue-44406.stderr @@ -13,14 +13,5 @@ error: expected type, found keyword `true` 18 | foo!(true); | ^^^^ expecting a type here because of type ascription -error: expected one of `!`, `&&`, `&`, `(`, `*`, `.`, `;`, `<`, `?`, `[`, `_`, `dyn`, `extern`, `fn`, `for`, `impl`, `unsafe`, `}`, an operator, or lifetime, found `true` - --> $DIR/issue-44406.rs:18:10 - | -13 | bar(baz: $rest) - | - expected one of 20 possible tokens here -... -18 | foo!(true); - | ^^^^ unexpected token - -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors diff --git a/src/test/ui/resolve/token-error-correct.stderr b/src/test/ui/resolve/token-error-correct.stderr index 281c21f6f85..6bd63f4fbbb 100644 --- a/src/test/ui/resolve/token-error-correct.stderr +++ b/src/test/ui/resolve/token-error-correct.stderr @@ -28,29 +28,11 @@ error: expected expression, found `;` 14 | foo(bar(; | ^ -error: expected one of `)`, `,`, `.`, `<`, `?`, `break`, `continue`, `false`, `for`, `if`, `loop`, `match`, `move`, `return`, `true`, `unsafe`, `while`, `yield`, or an operator, found `;` - --> $DIR/token-error-correct.rs:14:13 - | -14 | foo(bar(; - | ^ expected one of 19 possible tokens here - error: expected expression, found `)` --> $DIR/token-error-correct.rs:23:1 | 23 | } | ^ -error[E0425]: cannot find function `foo` in this scope - --> $DIR/token-error-correct.rs:14:5 - | -14 | foo(bar(; - | ^^^ not found in this scope - -error[E0425]: cannot find function `bar` in this scope - --> $DIR/token-error-correct.rs:14:9 - | -14 | foo(bar(; - | ^^^ not found in this scope - -error: aborting due to 7 previous errors +error: aborting due to 4 previous errors diff --git a/src/test/ui/suggestions/type-ascription-instead-of-initializer.rs b/src/test/ui/suggestions/type-ascription-instead-of-initializer.rs new file mode 100644 index 00000000000..bcd965f10fa --- /dev/null +++ b/src/test/ui/suggestions/type-ascription-instead-of-initializer.rs @@ -0,0 +1,13 @@ +// 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 main() { + let x: Vec::with_capacity(10, 20); +} diff --git a/src/test/ui/suggestions/type-ascription-instead-of-initializer.stderr b/src/test/ui/suggestions/type-ascription-instead-of-initializer.stderr new file mode 100644 index 00000000000..647e3f84685 --- /dev/null +++ b/src/test/ui/suggestions/type-ascription-instead-of-initializer.stderr @@ -0,0 +1,17 @@ +error: expected type, found `10` + --> $DIR/type-ascription-instead-of-initializer.rs:12:31 + | +12 | let x: Vec::with_capacity(10, 20); + | -- ^^ + | || + | |help: use `=` if you meant to assign + | while parsing the type for `x` + +error[E0061]: this function takes 1 parameter but 2 parameters were supplied + --> $DIR/type-ascription-instead-of-initializer.rs:12:31 + | +12 | let x: Vec::with_capacity(10, 20); + | ^^^^^^ expected 1 parameter + +error: aborting due to 2 previous errors + |
