about summary refs log tree commit diff
path: root/src/librustc_parse/parser/expr.rs
AgeCommit message (Collapse)AuthorLines
2020-04-30Rollup merge of #71433 - antoyo:error/missing-right-operand, r=Dylan-DPCDylan DPC-0/+5
Add help message for missing right operand in condition closes #30035
2020-04-22Rollup merge of #71256 - cuviper:must_use_replace, r=estebankDylan DPC-4/+3
Lint must_use on mem::replace This adds a hint on `mem::replace`, "if you don't need the old value, you can just assign the new value directly". This is in similar spirit to the `must_use` on `ManuallyDrop::take`.
2020-04-22Add help message for missing right operand in conditionAntoni Boucher-0/+5
2020-04-17Fix unused results from mem::replaceJosh Stone-4/+3
2020-04-17Improved try_macro_suggestionDuddino-1/+1
2020-04-17Moved is_try check into try_macro_suggestionDuddino-3/+1
2020-04-17Account for use of `try!()` in 2018 edition and guide users in the right ↵Duddino-0/+2
direction
2020-04-14allow try as scrutinee, e.g. `match try ...`Bastian Kauschke-5/+3
2020-03-30parse_and_disallow_postfix_after_cast: account for `ExprKind::Err`.Mazdak Farrokhzad-0/+1
2020-03-22Rollup merge of #70209 - Centril:recover-quant-closure, r=petrochenkovDylan DPC-2/+31
parser: recover on `for<'a> |...| body` closures When encountering `for` and `<` is 1 token ahead, interpret this as an explicitly quantified generic closure and recover, rather than attempting to parse a `for` loop. This provides both improved diagnostics as well as an insurance policy for the ability to use this as the syntax for generic closures in the future. As requested by r? @eddyb
2020-03-21recover on `for<'a> |...| body` closures.Mazdak Farrokhzad-2/+31
2020-03-21Rollup merge of #70187 - matthiaskrgr:cl2ppy, r=Mark-SimulacrumMazdak Farrokhzad-2/+2
more clippy fixes * remove redundant returns (clippy::needless_return) * remove redundant import (clippy::single_component_path_imports) * remove redundant format!() call (clippy::useless_format) * don't use ok() before calling expect() (clippy::ok_expect)
2020-03-20remove redundant returns (clippy::needless_return)Matthias Krüger-2/+2
2020-03-20can_begin_literal_maybe_minus: `true` on `"-"? lit` NTs.Mazdak Farrokhzad-0/+1
2020-03-12ast: `Mac`/`Macro` -> `MacCall`Vadim Petrochenkov-4/+4
2020-03-10parse_if_expr: recover on attributesMazdak Farrokhzad-6/+37
2020-03-10use check_path moreMazdak Farrokhzad-1/+1
2020-03-10parser: add note for `'label expr`.Mazdak Farrokhzad-0/+1
2020-03-10parse_labeled_expr: add a suggestion on missing colon.Mazdak Farrokhzad-3/+13
2020-03-10parse: recover on `&'lt $expr` / `'lt $expr`.Mazdak Farrokhzad-4/+31
2020-03-10more reuse in block parsing & improve diagnostics.Mazdak Farrokhzad-7/+9
2020-03-10parse_labeled_expr: simplifyMazdak Farrokhzad-15/+13
2020-03-09Rollup merge of #69801 - petrochenkov:nonorm, r=CentrilMazdak Farrokhzad-35/+38
rustc_parse: Remove `Parser::normalized(_prev)_token` Perform the "normalization" (renamed to "uninterpolation") on the fly when necessary. The final part of https://github.com/rust-lang/rust/pull/69579 https://github.com/rust-lang/rust/pull/69384 https://github.com/rust-lang/rust/pull/69376 https://github.com/rust-lang/rust/pull/69211 https://github.com/rust-lang/rust/pull/69034 https://github.com/rust-lang/rust/pull/69006. r? @Centril
2020-03-09Rollup merge of #69201 - Aaron1011:feature/permit-if-attr, r=CentrilMazdak Farrokhzad-9/+0
Permit attributes on 'if' expressions Previously, attributes on 'if' expressions (e.g. `#[attr] if true {}`) were disallowed during parsing. This made it impossible for macros to perform any custom handling of such attributes (e.g. stripping them away), since a compilation error would be emitted before they ever had a chance to run. This PR permits attributes on 'if' expressions ('if-attrs' from here on). Both built-in attributes (e.g. `#[allow]`, `#[cfg]`) and proc-macro attributes are supported. We still do *not* accept attributes on 'other parts' of an if-else chain. That is, the following code snippet still fails to parse: ```rust if true {} #[attr] else if false {} else #[attr] if false {} #[attr] else {} ``` Closes https://github.com/rust-lang/rust/issues/68618
2020-03-09Address review commentsVadim Petrochenkov-7/+6
2020-03-09Use `Token::uninterpolate` in couple more places matching on `(Nt)Ident`Vadim Petrochenkov-2/+1
2020-03-09rustc_ast: Introduce `Token::uninterpolate`Vadim Petrochenkov-2/+2
2020-03-09rustc_ast: Introduce `Token::uninterpolated_span`Vadim Petrochenkov-7/+10
2020-03-09rustc_parse: Use `Token::ident` where possibleVadim Petrochenkov-24/+26
2020-03-07Rollup merge of #69773 - matthiaskrgr:typos, r=petrochenkovMazdak Farrokhzad-1/+1
fix various typos
2020-03-07Rollup merge of #69656 - matthiaskrgr:iter_nth_zero, r=oli-obkMazdak Farrokhzad-1/+1
Use .next() instead of .nth(0) on iterators.
2020-03-07Rollup merge of #68985 - daboross:fix-35813, r=CentrilMazdak Farrokhzad-5/+58
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-06fix various typosMatthias Krüger-1/+1
2020-03-04Permit attributes on 'if' expressionsAaron Hill-9/+0
Previously, attributes on 'if' expressions (e.g. #[attr] if true {}) were disallowed during parsing. This made it impossible for macros to perform any custom handling of such attributes (e.g. stripping them away), since a compilation error would be emitted before they ever had a chance to run. This PR permits attributes on 'if' expressions ('if-attrs' from here on). Both built-in attributes (e.g. `#[allow]`, `#[cfg]`) are supported. We still do *not* accept attributes on 'other parts' of an if-else chain. That is, the following code snippet still fails to parse: ```rust if true {} #[attr] else if false {} else #[attr] if false {} #[attr] else {} ```
2020-03-03Use .next() instead of .nth(0) on iterators.Matthias Krüger-1/+1
2020-03-01Rollup merge of #69579 - petrochenkov:noprevspan, r=CentrilYuki Okushi-60/+69
parser: Remove `Parser::prev_span` Follow-up to https://github.com/rust-lang/rust/pull/69384. r? @Centril
2020-02-29Replace ptr hashing with ptr castingDavid-15/+6
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-29Rename `syntax` to `rustc_ast` in source codeVadim Petrochenkov-8/+8
2020-02-29parser: Remove `Parser::prev_span`Vadim Petrochenkov-1/+1
2020-02-29parser: `prev_span` -> `prev_token.span`Vadim Petrochenkov-59/+68
2020-02-28Rollup merge of #69481 - matthiaskrgr:single_char, r=ecstatic-morseMazdak Farrokhzad-1/+1
use char instead of &str for single char patterns
2020-02-28Rollup merge of #69384 - petrochenkov:nounnorm, r=CentrilMazdak Farrokhzad-21/+18
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-27use char instead of &str for single char patternsMatthias Krüger-1/+1
2020-02-27use find(x) instead of filter(x).next()Matthias Krüger-6/+2
2020-02-24parser: `token` -> `normalized_token`, `nonnormalized_token` -> `token`Vadim Petrochenkov-21/+18
2020-02-22Use multipart suggestionDavid Ross-13/+9
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-22Rename CodeMap to SourceMap follow upMaxim Zholobak-2/+2
2020-02-17parser: Remove `Option`s from unnormalized tokensVadim Petrochenkov-2/+2
They are always set synchronously with normalized tokens now
2020-02-17Rename `FunctionRetTy` to `FnRetTy`Yuki Okushi-4/+2
2020-02-15Remove extra debug print in unreachable!David Ross-2/+1