Don't lose empty where clause when pretty-printing

Previously, we would parse `struct Foo where;` and `struct Foo;`
identically, leading to an 'empty' `where` clause being omitted during
pretty printing. This will cause us to lose spans when proc-macros
involved, since we will have a collected `where` token that does not
appear in the pretty-printed item.

We now explicitly track the presence of a `where` token during parsing,
so that we can distinguish between `struct Foo where;` and `struct Foo;`
during pretty-printing
This commit is contained in:
Aaron Hill 2020-06-08 21:09:54 -04:00
parent fd4b177aab
commit 0fcea2e423
No known key found for this signature in database
GPG key ID: B4087E510E98B164
7 changed files with 68 additions and 7 deletions

View file

@ -0,0 +1,18 @@
// aux-build:test-macros.rs
extern crate test_macros;
use test_macros::recollect_attr;
#[recollect_attr]
struct FieldStruct where {
field: MissingType1 //~ ERROR cannot find
}
#[recollect_attr]
struct TupleStruct(MissingType2) where; //~ ERROR cannot find
enum MyEnum where {
Variant(MissingType3) //~ ERROR cannot find
}
fn main() {}

View file

@ -0,0 +1,21 @@
error[E0412]: cannot find type `MissingType1` in this scope
--> $DIR/empty-where-clause.rs:8:12
|
LL | field: MissingType1
| ^^^^^^^^^^^^ not found in this scope
error[E0412]: cannot find type `MissingType2` in this scope
--> $DIR/empty-where-clause.rs:12:20
|
LL | struct TupleStruct(MissingType2) where;
| ^^^^^^^^^^^^ not found in this scope
error[E0412]: cannot find type `MissingType3` in this scope
--> $DIR/empty-where-clause.rs:15:13
|
LL | Variant(MissingType3)
| ^^^^^^^^^^^^ not found in this scope
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0412`.