summary refs log tree commit diff
path: root/src/librustc_parse/parser
AgeCommit message (Collapse)AuthorLines
2020-04-03parse_and_disallow_postfix_after_cast: account for `ExprKind::Err`.Mazdak Farrokhzad-0/+1
2020-03-21can_begin_literal_maybe_minus: `true` on `"-"? lit` NTs.Mazdak Farrokhzad-2/+3
2020-03-09Rollup merge of #69801 - petrochenkov:nonorm, r=CentrilMazdak Farrokhzad-103/+75
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-8/+7
2020-03-09Use `Token::uninterpolate` in couple more places matching on `(Nt)Ident`Vadim Petrochenkov-3/+4
2020-03-09rustc_parse: Remove `Parser::normalized(_prev)_token`Vadim Petrochenkov-37/+5
2020-03-09rustc_ast: Introduce `Token::uninterpolate`Vadim Petrochenkov-4/+4
2020-03-09rustc_ast: Introduce `Token::uninterpolated_span`Vadim Petrochenkov-12/+15
2020-03-09rustc_parse: Use `Token::ident` where possibleVadim Petrochenkov-47/+48
2020-03-07Rollup merge of #69773 - matthiaskrgr:typos, r=petrochenkovMazdak Farrokhzad-3/+3
fix various typos
2020-03-07Rollup merge of #69656 - matthiaskrgr:iter_nth_zero, r=oli-obkMazdak Farrokhzad-3/+3
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-3/+3
2020-03-06Auto merge of #69586 - petrochenkov:unmerge, r=Centrilbors-20/+20
ast: Unmerge structures for associated items and foreign items Follow-up to https://github.com/rust-lang/rust/pull/69194. r? @Centril
2020-03-05Rollup merge of #69736 - matthiaskrgr:even_more_clippy, r=Dylan-DPCDylan DPC-1/+1
even more clippy cleanups * Don't pass &mut where immutable reference (&) is sufficient (clippy::unnecessary_mut_passed) * Use more efficient &&str to String conversion (clippy::inefficient_to_string) * Don't always eval arguments inside .expect(), use unwrap_or_else and closure. (clippy::expect_fun_call) * Use righthand '&' instead of lefthand "ref". (clippy::toplevel_ref_arg) * Use simple 'for i in x' loops instead of 'while let Some(i) = x.next()' loops on iterators. (clippy::while_let_on_iterator) * Const items have by default a static lifetime, there's no need to annotate it. (clippy::redundant_static_lifetimes) * Remove redundant patterns when matching ( x @ _ to x) (clippy::redundant_pattern)
2020-03-05Const items have by default a static lifetime, there's no need to annotate ↵Matthias Krüger-1/+1
it. (clippy::redundant_static_lifetimes)
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-04Use .map() to modify data inside Options instead of using .and_then(|x| ↵Matthias Krüger-1/+1
Some(y)) (clippy::option_and_then_some)
2020-03-03Use .next() instead of .nth(0) on iterators.Matthias Krüger-3/+3
2020-03-01encode `;` stmt w/o expr as `StmtKind::Empty`Mazdak Farrokhzad-20/+7
2020-03-01ast: Implement `TryFrom<ItemKind>` for associated and foreign itemsVadim Petrochenkov-20/+20
2020-03-01Rollup merge of #69579 - petrochenkov:noprevspan, r=CentrilYuki Okushi-207/+224
parser: Remove `Parser::prev_span` Follow-up to https://github.com/rust-lang/rust/pull/69384. r? @Centril
2020-03-01Auto merge of #69592 - petrochenkov:nosyntax, r=Centrilbors-63/+73
Rename `libsyntax` to `librustc_ast` This was the last rustc crate that wasn't following the `rustc_*` naming convention. Follow-up to https://github.com/rust-lang/rust/pull/67763.
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-63/+73
2020-02-29rustc_parse: Tweak the function parameter name checkVadim Petrochenkov-3/+4
2020-02-29parser: Remove `Parser::prev_span`Vadim Petrochenkov-10/+12
2020-02-29parser: `prev_span` -> `prev_token.span`Vadim Petrochenkov-197/+212
2020-02-29Auto merge of #69570 - Dylan-DPC:rollup-d6boczt, r=Dylan-DPCbors-2/+2
Rollup of 6 pull requests Successful merges: - #69477 (docs: add mention of async blocks in move keyword docs) - #69504 (Use assert_ne in hash tests) - #69546 (use to_vec() instead of .iter().cloned().collect() to convert slices to vecs.) - #69551 (use is_empty() instead of len() == x to determine if structs are empty.) - #69563 (Fix no_std detection for target triples) - #69567 (use .to_string() instead of format!() macro to create strings) Failed merges: r? @ghost
2020-02-29Auto merge of #69255 - estebank:e0599-details, r=varkorbors-2/+4
Add more context to E0599 errors Point at the intermediary unfulfilled trait bounds. Fix #52523, fix #61661, cc #36513, fix #68131, fix #64417, fix #61768, cc #57457, cc #9082, fix #57994, cc #64934, cc #65149.
2020-02-29Rollup merge of #69567 - matthiaskrgr:useless_fmt, r=nagisaDylan DPC-1/+1
use .to_string() instead of format!() macro to create strings handles what is left after https://github.com/rust-lang/rust/pull/69541
2020-02-29Rollup merge of #69551 - matthiaskrgr:len_zero, r=Mark-SimulacrumDylan DPC-1/+1
use is_empty() instead of len() == x to determine if structs are empty.
2020-02-29use .to_string() instead of format!() macro to create stringsMatthias Krüger-1/+1
2020-02-28Suggest constraining type parametersEsteban Küber-2/+4
2020-02-28Rollup merge of #69547 - matthiaskrgr:more_misc, r=Mark-SimulacrumMazdak Farrokhzad-1/+1
remove redundant clones, references to operands, explicit boolean comparisons and filter(x).next() calls.
2020-02-28Rollup merge of #69541 - dotdash:format, r=Mark-SimulacrumMazdak Farrokhzad-9/+6
Remove unneeded calls to format!()
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-69/+59
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-28use is_empty() instead of len() == x to determine if structs are empty.Matthias Krüger-1/+1
2020-02-28remove redundant clones, references to operands, explicit boolean ↵Matthias Krüger-1/+1
comparisons and filter(x).next() calls.
2020-02-28Rollup merge of #69529 - matthiaskrgr:clippy_identity_conversion, ↵Dylan DPC-5/+4
r=Mark-Simulacrum don't use .into() to convert types into identical types. This removes redundant `.into()` calls. example: `let s: String = format!("hello").into();`
2020-02-27don't use .into() to convert types into identical types.Matthias Krüger-5/+4
example: let s: String = format!("hello").into();
2020-02-27Remove unneeded calls to format!()Björn Steinbrink-9/+6
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-26Rollup merge of #69447 - Centril:minor-stmt-refactor, r=estebankDylan DPC-94/+87
Minor refactoring of statement parsing Extracted out of https://github.com/rust-lang/rust/pull/69445. r? @estebank
2020-02-26Rollup merge of #69423 - petrochenkov:nont, r=CentrilDylan DPC-8/+0
syntax: Remove `Nt(Impl,Trait,Foreign)Item` Follow-up to https://github.com/rust-lang/rust/pull/69366. r? @Centril
2020-02-25parse: address nitpickMazdak Farrokhzad-3/+2
2020-02-25parse: move condition into guardMazdak Farrokhzad-28/+28