Commit Graph

2941 Commits

Author SHA1 Message Date
bors c2ecab1121 Auto merge of #46732 - estebank:silence-recovered-blocks, r=petrochenkov
Do not emit type errors on recovered blocks

When a parse error occurs on a block, the parser will recover and create
a block with the statements collected until that point. Now a flag
stating that a recovery has been performed in this block is propagated
so that the type checker knows that the type of the block (which will be
identified as `()`) shouldn't be checked against the expectation to
reduce the amount of irrelevant diagnostic errors shown to the user.

Fix #44579.
2017-12-22 07:22:33 +00:00
Esteban Küber aaf3e318fc Do not emit type errors on recovered blocks
When a parse error occurs on a block, the parser will recover and create
a block with the statements collected until that point. Now a flag
stating that a recovery has been performed in this block is propagated
so that the type checker knows that the type of the block (which will be
identified as `()`) shouldn't be checked against the expectation to
reduce the amount of irrelevant diagnostic errors shown to the user.
2017-12-21 14:57:42 -08:00
bors 250b492052 Auto merge of #45930 - jplatte:generics_refactoring, r=eddyb
Generics refactoring (groundwork for const generics)

These changes were suggested by @eddyb.

After this change, the `Generics` contain one `Vec` of an enum for the generic parameters, rather than two separate `Vec`s for lifetime and type parameters. Type params and const params will need to be in a shared `Vec` to preserve their ordering, and moving lifetimes into the same `Vec` should simplify the code that processes `Generics`.
2017-12-21 20:12:13 +00:00
Jonas Platte 78493ed21a Add GenericParam, refactor Generics in ast, hir, rustdoc
The Generics now contain one Vec of an enum for the generic parameters,
rather than two separate Vec's for lifetime and type parameters.

Additionally, places that previously used Vec<LifetimeDef> now use
Vec<GenericParam> instead.
2017-12-21 13:38:10 +01:00
Guillaume Gomez 2917ac6b59 Rollup merge of #46827 - petrochenkov:assocrecov2, r=estebank
syntax: Follow-up to the incorrect qpath recovery PR

cc https://github.com/rust-lang/rust/pull/46788

Add tests checking that "priority" of qpath recovery is higher than priority of unary and binary operators
Fix regressed parsing of paths with fn-like generic arguments
r? @estebank
2017-12-21 13:18:18 +01:00
bors 957dc8de63 Auto merge of #46531 - cramertj:no-mo-modrs, r=nikomatsakis
Implement non-mod.rs mod statements

Fixes https://github.com/rust-lang/rust/issues/45385, cc https://github.com/rust-lang/rust/issues/44660

This will fail tidy right now because it doesn't recognize my UI tests as feature-gate tests. However, I'm not sure if compile-fail will work out either because compile-fail usually requires there to be error patterns in the top-level file, which isn't possible with this feature. What's the recommended way to handle this?
2017-12-21 05:24:45 +00:00
Vadim Petrochenkov d333752f5c Fix parsing of paths with fn-like generic arguments 2017-12-20 22:55:57 +03:00
Vadim Petrochenkov 9a68098e87 Move impls for qpath recovery trait from ast.rs 2017-12-20 22:43:47 +03:00
Taylor Cramer 07f51fb868 Implement non-mod.rs mod statements 2017-12-19 14:58:51 -08:00
topecongiro 7374fdcf54 Remove a token after closing delimiter from the span of macro in type position 2017-12-19 21:18:30 +09:00
Vadim Petrochenkov 70e5c37319 syntax: recovery for incorrect associated item paths like [T; N]::clone 2017-12-17 19:00:50 +03:00
Vadim Petrochenkov a4aa26aaa0 syntax: Rename P::unwrap into P::into_inner 2017-12-17 02:21:29 +03:00
Zack M. Davis d40197c471 in which .. is suggested for erroneous ... in struct field patterns
Resolves #46718.
2017-12-16 00:58:19 -08:00
Esteban Küber c60aab29f1 When attempting to write str with single quote suggest double quotes 2017-12-14 22:51:42 -08:00
Alex Burka d4a28268cc add trait aliases to AST 2017-12-14 12:56:26 -05:00
Oliver Schneider d732da813b Use PathBuf instead of String where applicable 2017-12-14 11:22:08 +01:00
Matt Brubeck 3024c1434a Use Try syntax for Option in place of macros or match 2017-12-09 14:18:33 -08:00
bors c8ddf28527 Auto merge of #46497 - AgustinCB:issue-46311, r=petrochenkov
Modify message for keyword as identifier name

This is a temporary solution to #46311.

The message is generic enough to cover both cases and is probably a fine enough solution to the specific problem described in the task. However, the underlying reason for this to be wrong is that `next_token_inner` returns `Lifetime` even if the token is a label. That's not simple, as the syntax for both can be quite similar and it may need to take a look to the next token to make a decision. I'm not sure I have enough knowledge about the project to be able to solve that (yet!), so I thought I'll fix the immediate problem first.
2017-12-07 21:05:49 +00:00
Agustin Chiappe Berrini ce1fed7f52 address comments 2017-12-07 03:52:25 -05:00
bors 7b637b778d Auto merge of #46187 - notriddle:patch-1, r=QuietMisdreavus
Rename C-like enum to Field-less enum

There is no need to reference the C programming language to explain this concept.
2017-12-07 07:16:44 +00:00
Agustin Chiappe Berrini 65ccf24ce8 and refactor to just move the checking 2017-12-06 04:28:01 -05:00
bors f9b0897c5d Auto merge of #46381 - estebank:expected-span, r=nikomatsakis
Point to next token when it is in the expected line

r? @nikomatsakis
2017-12-02 20:06:42 +00:00
bors e0d11f39d8 Auto merge of #46343 - jseyfried:fix_hygiene_bug, r=nrc
Fix hygiene bug.

Fixes #42708.
r? @nrc
2017-12-02 10:15:21 +00:00
bors ddaebe938b Auto merge of #45904 - sunjay:gat-parser, r=nikomatsakis
Generic Associated Types Parsing & Name Resolution

Hi!
This PR adds parsing for generic associated types! 🎉 🎉 🎉

Tracking Issue: #44265

## Notes For Reviewers
* [x] I still need to add the stdout and stderr files to my ui tests. It takes me a *long* time to compile the compiler locally, so I'm going to add this as soon as possible in the next day or so.
* [ ] My current ui tests aren't very good or very thorough. I'm reusing the `parse_generics` and `parse_where_clause` methods from elsewhere in the parser, so my changes work without being particularly complex. I'm not sure if I should duplicate all of the generics test cases for generic associated types. It might actually be appropriate to duplicate everything here, since we don't want to rely on an implementation detail in case it changes in the future. If you think so too, I'll adapt all of the generics test cases into the generic associated types test cases.
* [ ] There is still more work required to make the run-pass tests pass here. In particular, we need to make the following errors disappear:
```
error[E0110]: lifetime parameters are not allowed on this type
  --> ./src/test/run-pass/rfc1598-generic-associated-types/streaming_iterator.rs:23:41
   |
23 |     bar: <T as StreamingIterator>::Item<'static>,
   |                                         ^^^^^^^ lifetime parameter not allowed on this type
```
```
error[E0261]: use of undeclared lifetime name `'a`
  --> ./src/test/run-pass/rfc1598-generic-associated-types/iterable.rs:15:47
   |
15 |     type Iter<'a>: Iterator<Item = Self::Item<'a>>;
   |                                               ^^ undeclared lifetime
```
There is a FIXME comment in streaming_iterator. If you uncomment that line, you get the following:
```
error: expected one of `!`, `+`, `,`, `::`, or `>`, found `=`
  --> ./src/test/run-pass/rfc1598-generic-associated-types/streaming_iterator.rs:29:45
   |
29 | fn foo<T: for<'a> StreamingIterator<Item<'a>=&'a [i32]>>(iter: T) { /* ... */ }
   |                                             ^ expected one of `!`, `+`, `,`, `::`, or `>` here
```

r? @nikomatsakis
2017-12-02 00:15:19 +00:00
Sunjay Varma 38c2a73017 Testing and fixes 2017-12-01 01:26:29 -05:00
Sunjay Varma 223d091744 Parsing where clauses correctly and documenting the grammar being parsed 2017-12-01 01:26:29 -05:00
Sunjay Varma 6bd8ea1a6b Added run-pass tests for associated generic types 2017-12-01 01:24:53 -05:00
Sunjay Varma 19e25b61d1 Parsing generics in both trait items and impl items 2017-12-01 01:24:53 -05:00
bors d1364a65c0 Auto merge of #45997 - estebank:pub-ident, r=nikomatsakis
Account for missing keyword in fn/struct definition

Fix #38911.
2017-12-01 06:06:06 +00:00
Pietro Albini 91ba8b42fc Implement RFC 2128 (use_nested_groups)
This commit adds support for nested groups inside `use` declarations,
such as `use foo::{bar, sub::{baz::Foo, *}};`.
2017-11-30 13:10:26 +01:00
Esteban Küber fe89740957 Point to next token when it is in the expected line 2017-11-29 13:28:47 -08:00
Jeffrey Seyfried dfa6c25afd Fix hygiene bug. 2017-11-28 18:59:12 -08:00
colinmarsh19 3e8883e2aa Changed from note to span_suggestion_short 2017-11-25 18:34:20 -07:00
colinmarsh19 306f4da69a Fixed Err by passing "err" 2017-11-25 08:47:05 -07:00
colinmarsh19 aabacf791a Remove semicolon note
Added note that specifies a semicolon should be removed after a given struct
2017-11-25 08:38:30 -07:00
Esteban Küber f103342b8f Consume trailing doc comments to avoid parse errors 2017-11-24 08:32:01 -08:00
Esteban Küber 0e93b75d27 Revert to correct recovery behavior 2017-11-24 07:34:33 -08:00
Esteban Küber 4e2d1b9466 Emit DocComment in bad location error but continue parsing struct fields 2017-11-24 07:34:32 -08:00
Esteban Küber df357b20be Suggest macro call when not sure that it is fn definition 2017-11-24 07:34:32 -08:00
Esteban Küber c82e9e8e1e Do not attemt to continue parsing after pub ident
Try to identify the following code in order to provide better
diagnostics, but return the error to bail out early during the parse.
2017-11-24 07:34:32 -08:00
Esteban Küber 7c0387e36a Do not rewind parser and ignore following blocks
When encountering `pub ident`, attempt to identify the code that comes
afterwards, wether it is a brace block (assume it is a struct), a paren
list followed by a colon (assume struct) or a paren list followed by a
block (assume a fn). Consume those blocks to avoid any further parser
errors and return a `Placeholder` item in order to allow the parser to
continue. In the case of unenclosed blocks, the behavior is the same as
it is currently: no further errors are processed.
2017-11-24 07:34:31 -08:00
Esteban Küber 547873aa54 Account for missing keyword in fn/struct definition 2017-11-24 07:34:31 -08:00
Michael Howell 06a75e4d1f Update parser.rs 2017-11-22 10:59:14 -07:00
bors f28df20026 Auto merge of #45771 - petrochenkov:crate, r=nikomatsakis
Support `::crate` in paths

cc https://github.com/rust-lang/rust/issues/45477
Fixes https://github.com/rust-lang/rust/issues/45229
2017-11-21 12:32:59 +00:00
Vadim Petrochenkov 2e9b89ddc5 Support ::crate in paths 2017-11-21 00:21:24 +03:00
Alex Burka b34a7ffb25 address review comments 2017-11-20 18:03:20 +00:00
Alex Burka 7a5a1f9857 use -Z flag instead of env var 2017-11-19 22:30:14 +00:00
Vadim Petrochenkov 1055bdfb2a Accept interpolated patterns in trait method parameters
Remove some outdated messages from "no patterns allowed" errors
2017-11-11 15:44:19 +03:00
bors d5ff0e6422 Auto merge of #45773 - Badel2:dotdoteq, r=petrochenkov
Add error for `...` in expressions

Follow-up to https://github.com/rust-lang/rust/pull/44709
Tracking issue: https://github.com/rust-lang/rust/issues/28237

* Using `...` in expressions was a warning, now it's an error
* The error message suggests using `..` or `..=` instead, and explains the difference
* Updated remaining occurrences of `...` to `..=`

r? petrochenkov
2017-11-10 01:40:21 +00:00
bors 02004ef783 Auto merge of #45452 - estebank:colon-typo, r=nikomatsakis
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`
```

Fix #43703.
2017-11-08 20:00:41 +00:00