Commit Graph

116 Commits

Author SHA1 Message Date
Vadim Petrochenkov
9be233cbfe Use Token::uninterpolate in couple more places matching on (Nt)Ident 2020-03-09 12:42:41 +03:00
Vadim Petrochenkov
43b27df5b2 rustc_ast: Introduce Token::uninterpolate 2020-03-09 12:42:41 +03:00
Vadim Petrochenkov
f4a03c44d5 rustc_ast: Introduce Token::uninterpolated_span 2020-03-09 12:42:41 +03:00
Vadim Petrochenkov
925e9a2188 rustc_parse: Use Token::ident where possible 2020-03-09 12:42:41 +03:00
Mazdak Farrokhzad
10f999b72d
Rollup merge of #69773 - matthiaskrgr:typos, r=petrochenkov
fix various typos
2020-03-07 17:27:32 +01:00
Mazdak Farrokhzad
5d1433b1f4
Rollup merge of #69656 - matthiaskrgr:iter_nth_zero, r=oli-obk
Use .next() instead of .nth(0) on iterators.
2020-03-07 08:15:24 +01:00
Mazdak Farrokhzad
111724f5e2
Rollup merge of #68985 - daboross:fix-35813, r=Centril
Parse & reject postfix operators after casts

This adds an explicit error messages for when parsing `x as Type[0]` or similar expressions. Our add an extra parse case for parsing any postfix operator (dot, indexing, method calls, await) that triggers directly after parsing `as` expressions.

My friend and I worked on this together, but they're still deciding on a github username and thus I'm submitting this for both of us.

It will immediately error out, but will also provide the rest of the parser with a useful parse tree to deal with.

There's one decision we made in how this produces the parse tree. In the situation `&x as T[0]`, one could imagine this parsing as either `&((x as T)[0])` or `((&x) as T)[0]`. We chose the latter for ease of implementation, and as it seemed the most intuitive.

Feedback welcome! This is our first change to the parser section, and it might be completely horrible.

Fixes #35813.
2020-03-07 08:15:21 +01:00
Matthias Krüger
136ad015b6 fix various typos 2020-03-06 15:19:31 +01:00
Matthias Krüger
d3e5177f81 Use .next() instead of .nth(0) on iterators. 2020-03-03 03:15:03 +01:00
Yuki Okushi
4439bb09aa
Rollup merge of #69579 - petrochenkov:noprevspan, r=Centril
parser: Remove `Parser::prev_span`

Follow-up to https://github.com/rust-lang/rust/pull/69384.
r? @Centril
2020-03-01 19:28:10 +09:00
David
453c505147 Replace ptr hashing with ptr casting
Implementes suggeseted changes by Centril.

This checks whether the memory location of the cast remains the same
after atttempting to parse a postfix operator after a cast has been
parsed. If the address is not the same, an illegal postfix operator
was parsed.

Previously the code generated a hash of the pointer, which was overly
complex and inefficent. Casting the pointers and comparing them
is simpler and more effcient.
2020-02-29 11:05:39 -08:00
Vadim Petrochenkov
e08c279eac Rename syntax to rustc_ast in source code 2020-02-29 21:59:09 +03:00
Vadim Petrochenkov
7de9a72ca3 parser: Remove Parser::prev_span 2020-02-29 15:00:58 +03:00
Vadim Petrochenkov
d0ba4387c2 parser: prev_span -> prev_token.span 2020-02-29 14:57:14 +03:00
Mazdak Farrokhzad
07d9ed2c09
Rollup merge of #69481 - matthiaskrgr:single_char, r=ecstatic-morse
use char instead of &str for single char patterns
2020-02-28 17:17:30 +01:00
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
7c84ba1124 use char instead of &str for single char patterns 2020-02-27 14:57:22 +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
David Ross
f434c6e636 Use multipart suggestion
This is a modified version of estebank's suggestion, with a bit of
extra cleanup now that we don't need the different cases for if we can
turn a span into a string or not.
2020-02-22 12:33:06 -08: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
David Ross
e3eefe2667 Remove extra debug print in unreachable! 2020-02-15 19:51:02 -08:00
David Ross
0cf204930a Keep better fix suggestion if type ascription is likely unintended 2020-02-15 19:51:02 -08:00
David Ross
4fc0532269 Type ascription outputs a Type, not Cast
Previously this just errored out on all usages of type ascription,
which isn't helpful.
2020-02-15 19:51:02 -08:00
David Ross
5ce9b80c0f Refactor out error case & apply suggestions.
This is almost entirely refactoring and message changing, with the
single behavioral change of panicking for unexpected output.
2020-02-15 19:51:02 -08:00
David Ross
940f65782c Parse & reject postfix operators after casts
This adds parsing for expressions like 'x as Ty[0]' which will
immediately error out, but still give the rest of the parser a valid
parse tree to continue.
2020-02-15 19:50:50 -08: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