1
Fork 0
rust/compiler/rustc_expand/src
Esteban Küber e5f83bcd04 Detect blocks that could be struct expr bodies
This approach lives exclusively in the parser, so struct expr bodies
that are syntactically correct on their own but are otherwise incorrect
will still emit confusing errors, like in the following case:

```rust
fn foo() -> Foo {
    bar: Vec::new()
}
```

```
error[E0425]: cannot find value `bar` in this scope
 --> src/file.rs:5:5
  |
5 |     bar: Vec::new()
  |     ^^^ expecting a type here because of type ascription

error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
 --> src/file.rs:5:15
  |
5 |     bar: Vec::new()
  |               ^^^^^ only `Fn` traits may use parentheses

error[E0107]: wrong number of type arguments: expected 1, found 0
 --> src/file.rs:5:10
  |
5 |     bar: Vec::new()
  |          ^^^^^^^^^^ expected 1 type argument
  ```

If that field had a trailing comma, that would be a parse error and it
would trigger the new, more targetted, error:

```
error: struct literal body without path
 --> file.rs:4:17
  |
4 |   fn foo() -> Foo {
  |  _________________^
5 | |     bar: Vec::new(),
6 | | }
  | |_^
  |
help: you might have forgotten to add the struct literal inside the block
  |
4 | fn foo() -> Foo { Path {
5 |     bar: Vec::new(),
6 | } }
  |
```

Partially address last part of #34255.
2020-10-07 13:40:52 -07:00
..
mbe Rename IsJoint -> Spacing 2020-09-03 17:32:45 +02:00
mut_visit mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
parse Move lexer unit tests to rustc_lexer 2020-08-30 19:53:36 +02:00
tokenstream mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
base.rs expand: Minor fn ptr call cleanup 2020-09-28 23:10:48 +03:00
build.rs Attach tokens to ast::Stmt 2020-09-10 17:33:06 -04:00
config.rs Syntactically permit unsafety on mods 2020-09-10 06:56:33 -07:00
expand.rs Detect blocks that could be struct expr bodies 2020-10-07 13:40:52 -07:00
lib.rs Remove redundant #![feature(...)] 's from compiler/ 2020-09-17 07:58:45 +02:00
mbe.rs mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
module.rs Syntactically permit unsafety on mods 2020-09-10 06:56:33 -07:00
placeholders.rs Attach tokens to ast::Stmt 2020-09-10 17:33:06 -04:00
proc_macro.rs Improve E0777 help message 2020-10-02 16:33:44 +02:00
proc_macro_server.rs Rollup merge of #75146 - tmiasko:range-overflow, r=Mark-Simulacrum 2020-09-16 01:30:30 +02:00
tests.rs mv compiler to compiler/ 2020-08-30 18:45:07 +03:00