Commit Graph

94 Commits

Author SHA1 Message Date
Mazdak Farrokhzad 3828fa2852 Rollup merge of #69384 - petrochenkov:nounnorm, r=Centril
parser: `token` -> `normalized_token`, `nonnormalized_token` -> `token`

So, after https://github.com/rust-lang/rust/pull/69006, its follow-ups and an attempt to remove `Parser::prev_span` I came to the conclusion that the unnormalized token and its span is what you want in most cases, so it should be default.

Normalization only makes difference in few cases where we are checking against `token::Ident` or `token::Lifetime` specifically.
This PR uses `normalized_token` for those cases.

Using normalization explicitly means that people writing code should remember about `NtIdent` and `NtLifetime` in general. (That is alleviated by the fact that `token.ident()` and `fn parse_ident_*` are already written.)
Remembering about `NtIdent`, was, however, already the case, kind of, because the implicit normalization was performed only for the current/previous token, but not for things like `look_ahead`.
As a result, most of token classification methods in `token.rs` already take `NtIdent` into account (this PR fixes a few pre-existing minor mistakes though).

The next step is removing `normalized(_prev)_token` entirely and replacing it with `token.ident()` (mostly) and `token.normalize()` (occasionally).
I want to make it a separate PR for that and run it though perf.
`normalized_token` filled on every bump has both a potential to avoid repeated normalization, and to do unnecessary work in advance (it probably doesn't matter anyway, the normalization is very cheap).

r? @Centril
2020-02-28 17:17:26 +01:00
Matthias Krüger 896a081442 use find(x) instead of filter(x).next() 2020-02-27 14:50:54 +01:00
Vadim Petrochenkov b2605c118d parser: token -> normalized_token, nonnormalized_token -> token 2020-02-24 13:04:13 +03:00
Maxim Zholobak 20c9a40fec Rename CodeMap to SourceMap follow up 2020-02-22 16:17:31 +02:00
Vadim Petrochenkov 06fbb0b4fa parser: Remove Options from unnormalized tokens
They are always set synchronously with normalized tokens now
2020-02-17 22:12:39 +03:00
Yuki Okushi eb12ed889d Rename FunctionRetTy to FnRetTy 2020-02-17 11:24:29 +09:00
Aaron Hill 98757f14d0 Suggest a comma if a struct initializer field fails to parse
Currently, we emit a "try adding a comma" suggestion if a comma is
missing in a struct definition. However, we emit no such suggestion if a
comma is missing in a struct initializer.

This commit adds a "try adding a comma" suggestion when we don't find a
comma during the parsing of a struct initializer field.

The change to `src/test/ui/parser/removed-syntax-with-1.stderr` isn't
great, but I don't see a good way of avoiding it.
2020-02-14 22:28:13 -05:00
Mazdak Farrokhzad c30f068dc8 IsAsync -> enum Async { Yes { span: Span, .. }, No }
use new span for better diagnostics.
2020-02-13 10:39:24 +01:00
Dylan DPC 2a3c1a30c8 Rollup merge of #68981 - estebank:silence, r=davidtwco
Account for type params on method without parentheses

Account for those type parameters in the structured suggestion when forgetting to call method:

```
error[E0615]: attempted to take value of method `collect` on type `std::vec::IntoIter<_>`
  --> $DIR/method-missing-parentheses.rs:2:32
   |
LL |     let _ = vec![].into_iter().collect::<usize>;
   |                                ^^^^^^^---------
   |                                |
   |                                help: use parentheses to call the method: `collect::<usize>()`
```
2020-02-12 20:36:53 +01:00
Dylan DPC 42f371c2eb Rollup merge of #69034 - petrochenkov:notokind, r=Centril
parser: Remove `Parser::prev_token_kind`

Follow-up to https://github.com/rust-lang/rust/pull/69006.
r? @Centril
2020-02-12 14:21:11 +01:00
Esteban Küber 9d91489526 review comment: wording 2020-02-10 13:58:36 -08:00
Vadim Petrochenkov 8d799218ab parser: Remove Parser::prev_token_kind 2020-02-10 20:29:37 +03:00
Matthias Prechtl f35a7c38da Make issue references consistent 2020-02-09 20:43:49 +01:00
Mazdak Farrokhzad c0b7b41cff parse_ty_common: use enums instead of bools. 2020-02-05 01:27:08 +01:00
Mazdak Farrokhzad e233331a51 syntax::print -> new crate rustc_ast_pretty 2020-02-01 18:59:49 +01:00
Mazdak Farrokhzad 82c19b4388 Rollup merge of #68108 - varkor:chained-comparison-suggestions, r=Centril
Add suggestions when encountering chained comparisons

Ideally, we'd also prevent the type error, which is just extra noise, but that will require moving the error from the parser, and I think the suggestion makes things clear enough for now.

Fixes https://github.com/rust-lang/rust/issues/65659.
2020-01-12 03:28:02 +01:00
Mazdak Farrokhzad 4eee796679 Rollup merge of #68120 - Centril:ban-range-to-dotdotdot, r=oli-obk
Ban `...X` pats, harden tests, and improve diagnostics

Follow up to https://github.com/rust-lang/rust/pull/67258#issuecomment-565656155 and https://github.com/rust-lang/rust/pull/67258#discussion_r357879932.

r? @cramertj @oli-obk
2020-01-11 12:36:15 +01:00
Mazdak Farrokhzad 883932c6ba Ban ...X pats, harden tests, and improve diagnostics.
Also fix a bug with the span passed in `mk_range`.
2020-01-11 08:58:58 +01:00
Mazdak Farrokhzad cacda2d7a0 Rollup merge of #68084 - estebank:ice-68000, r=varkor
Do not ICE on unicode next point

Use `shrink_to_hi` instead of `next_point` and fix `next_point`.

Fix #68000, fix #68091, fix #68092.
2020-01-11 04:02:28 +01:00
varkor 088a1808d2 Add suggestions when encountering chained comparisons 2020-01-11 01:56:25 +00:00
Esteban Küber b93ef68245 Change next_point when shrink_to_hi is more appropriate 2020-01-10 11:23:59 -08:00
Mazdak Farrokhzad d5598aa7a0 Introduce #![feature(half_open_range_patterns)].
This feature adds `X..`, `..X`, and `..=X` patterns.
2020-01-10 07:29:04 +01:00
Vadim Petrochenkov 70f1d57048 Rename syntax_pos to rustc_span in source code 2020-01-01 09:15:18 +03:00
Mazdak Farrokhzad 2e7806146c parser: bug -> span_bug 2019-12-31 04:33:34 +01:00
Mazdak Farrokhzad 6fba125912 parser::path: remove .fatal calls 2019-12-31 04:33:34 +01:00
Mazdak Farrokhzad 5a64ba6386 parser: span_fatal -> struct_span_err 2019-12-31 04:33:34 +01:00
Mazdak Farrokhzad b6fc87c5b9 de-fatalize some errors 2019-12-31 04:33:34 +01:00
Mazdak Farrokhzad 2091062bf6 parser: call .struct_span_err directly 2019-12-31 04:33:34 +01:00
bors da3629b05f Auto merge of #67112 - Centril:expr-polish, r=estebank
Refactor expression parsing thoroughly

Based on https://github.com/rust-lang/rust/pull/66994 together with which this has refactored basically the entirety of `expr.rs`.

r? @estebank
2019-12-29 19:30:53 +00:00
Mazdak Farrokhzad 05c26a445b refactor assoc op parsing 2019-12-23 13:55:45 +01:00
Mazdak Farrokhzad e43a7ef1d4 simplify parse_prefix_range_expr 2019-12-23 13:55:10 +01:00
Mazdak Farrokhzad 8456c403e1 extract parse_not_expr 2019-12-23 13:55:04 +01:00
Mazdak Farrokhzad efdea63c43 extract parse_prefix_expr 2019-12-23 13:51:21 +01:00
Mazdak Farrokhzad 4cfcfe9e20 extract parse_neg_expr 2019-12-23 13:51:02 +01:00
Mazdak Farrokhzad f6ab439436 extract parse_deref_expr 2019-12-23 13:50:56 +01:00
Mazdak Farrokhzad ada388b2b8 extract is_mistaken_not_ident_negation 2019-12-23 13:50:50 +01:00
Mazdak Farrokhzad 80eeefb05f extract recover_not_expr 2019-12-23 13:49:14 +01:00
Mazdak Farrokhzad 00cc8a1b0c simplify parse_assoc_op_cast 2019-12-23 13:48:47 +01:00
Mazdak Farrokhzad 84f9bf1a06 refactor parse_address_of -> parse_borrow_expr 2019-12-23 13:48:45 +01:00
Mazdak Farrokhzad af5ac23a23 simplify parse_dot_call_or_expr 2019-12-23 13:47:52 +01:00
Mazdak Farrokhzad 7ae12c9385 extract parse_dot_base_expr 2019-12-23 13:47:44 +01:00
Mazdak Farrokhzad bc95228f1b extract parse_dot_suffix_expr 2019-12-23 13:45:45 +01:00
Mazdak Farrokhzad 9c6bbf1252 extract error_unexpected_after_dot and de-fatalize 2019-12-23 13:45:13 +01:00
Mazdak Farrokhzad ff5762b78a extract recover_field_access_by_float_lit 2019-12-23 13:44:38 +01:00
Mazdak Farrokhzad a15d0cde57 extract parse_tuple_field_access_expr 2019-12-23 13:44:12 +01:00
Mazdak Farrokhzad 287ba5d0c8 extract parse_fn_call_expr 2019-12-23 13:44:06 +01:00
Mazdak Farrokhzad 98701b2c61 extract parse_index_expr & refactor parse_dot_suffix 2019-12-23 13:44:02 +01:00
Mazdak Farrokhzad 0bb3dad5a6 extract error_float_lits-must_have_int_part 2019-12-23 13:43:35 +01:00
Mazdak Farrokhzad aa8adba8fb simplify parse_literal_maybe_minus 2019-12-23 13:43:28 +01:00
Mazdak Farrokhzad f647c11121 simplify parse_fn_block_decl 2019-12-23 13:43:21 +01:00