-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add parser recovery for
const $ident = $expr;
.
Then use the diagnostics-stealing API to stash parser errors and enrich them with type information in typeck.
- Loading branch information
Showing
4 changed files
with
164 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// In the cases below, the type is missing from the `const` and `static` items. | ||
// | ||
// Here, we test that we: | ||
// | ||
// a) Perform parser recovery. | ||
// | ||
// b) Emit a diagnostic with the actual inferred type to RHS of `=` as the suggestion. | ||
|
||
fn main() {} | ||
|
||
// These will not reach typeck: | ||
|
||
#[cfg(FALSE)] | ||
const C2 = 42; | ||
//~^ ERROR missing type for `const` item | ||
//~| HELP provide a type for the item | ||
//~| SUGGESTION C2: <type> | ||
|
||
#[cfg(FALSE)] | ||
static S2 = "abc"; | ||
//~^ ERROR missing type for `static` item | ||
//~| HELP provide a type for the item | ||
//~| SUGGESTION S2: <type> | ||
|
||
#[cfg(FALSE)] | ||
static mut SM2 = "abc"; | ||
//~^ ERROR missing type for `static mut` item | ||
//~| HELP provide a type for the item | ||
//~| SUGGESTION SM2: <type> | ||
|
||
// These will, so the diagnostics should be stolen by typeck: | ||
|
||
const C = 42; | ||
//~^ ERROR missing type for `const` item | ||
//~| HELP provide a type for the item | ||
//~| SUGGESTION C: i32 | ||
|
||
static S = Vec::<String>::new(); | ||
//~^ ERROR missing type for `static` item | ||
//~| HELP provide a type for the item | ||
//~| SUGGESTION S: std::vec::Vec<std::string::String> | ||
|
||
static mut SM = "abc"; | ||
//~^ ERROR missing type for `static mut` item | ||
//~| HELP provide a type for the item | ||
//~| SUGGESTION &'static str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
error: missing type for `const` item | ||
--> $DIR/const-no-type.rs:33:7 | ||
| | ||
LL | const C = 42; | ||
| ^ help: provide a type for the item: `C: i32` | ||
|
||
error: missing type for `static` item | ||
--> $DIR/const-no-type.rs:38:8 | ||
| | ||
LL | static S = Vec::<String>::new(); | ||
| ^ help: provide a type for the item: `S: std::vec::Vec<std::string::String>` | ||
|
||
error: missing type for `static mut` item | ||
--> $DIR/const-no-type.rs:43:12 | ||
| | ||
LL | static mut SM = "abc"; | ||
| ^^ help: provide a type for the item: `SM: &'static str` | ||
|
||
error: missing type for `const` item | ||
--> $DIR/const-no-type.rs:14:7 | ||
| | ||
LL | const C2 = 42; | ||
| ^^ help: provide a type for the item: `C2: <type>` | ||
|
||
error: missing type for `static` item | ||
--> $DIR/const-no-type.rs:20:8 | ||
| | ||
LL | static S2 = "abc"; | ||
| ^^ help: provide a type for the item: `S2: <type>` | ||
|
||
error: missing type for `static mut` item | ||
--> $DIR/const-no-type.rs:26:12 | ||
| | ||
LL | static mut SM2 = "abc"; | ||
| ^^^ help: provide a type for the item: `SM2: <type>` | ||
|
||
error: aborting due to 6 previous errors | ||
|