about summary refs log tree commit diff
path: root/compiler/rustc_parse/src
AgeCommit message (Collapse)AuthorLines
2021-03-26Always preserve `None`-delimited groups in a captured `TokenStream`Aaron Hill-15/+55
Previously, we would silently remove any `None`-delimiters when capturing a `TokenStream`, 'flattenting' them to their inner tokens. This was not normally visible, since we usually have `TokenKind::Interpolated` (which gets converted to a `None`-delimited group during macro invocation) instead of an actual `None`-delimited group. However, there are a couple of cases where this becomes visible to proc-macros: 1. A cross-crate `macro_rules!` macro has a `None`-delimited group stored in its body (as a result of being produced by another `macro_rules!` macro). The cross-crate `macro_rules!` invocation can then expand to an attribute macro invocation, which needs to be able to see the `None`-delimited group. 2. A proc-macro can invoke an attribute proc-macro with its re-collected input. If there are any nonterminals present in the input, they will get re-collected to `None`-delimited groups, which will then get captured as part of the attribute macro invocation. Both of these cases are incredibly obscure, so there hopefully won't be any breakage. This change will allow more agressive 'flattenting' of nonterminals in #82608 without losing `None`-delimited groups.
2021-03-25Avoid double-collection for expression nonterminalsAaron Hill-17/+17
2021-03-23Rollup merge of #83384 - mark-i-m:rename-pat2018, r=joshtriplettYuki Okushi-3/+3
rename :pat2018 -> :pat2015 as requested by T-lang on zulip: https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/or.20patterns/near/231133873 No functional changes here... just renaming. r? `@nikomatsakis`
2021-03-22rename :pat2018 -> :pat215mark-3/+3
2021-03-19stabilize or_patternsmark-65/+29
2021-03-18Auto merge of #76447 - pickfire:async-pub, r=estebankbors-9/+39
Detect async visibility wrong order, `async pub` Partially address #76437.
2021-03-17Auto merge of #83188 - petrochenkov:field, r=lcnrbors-22/+24
ast/hir: Rename field-related structures I always forget what `ast::Field` and `ast::StructField` mean despite working with AST for long time, so this PR changes the naming to less confusing and more consistent. - `StructField` -> `FieldDef` ("field definition") - `Field` -> `ExprField` ("expression field", not "field expression") - `FieldPat` -> `PatField` ("pattern field", not "field pattern") Various visiting and other methods working with the fields are renamed correspondingly too. The second commit reduces the size of `ExprKind` by boxing fields of `ExprKind::Struct` in preparation for https://github.com/rust-lang/rust/pull/80080.
2021-03-17Add pub as optional check_front_matterIvan Tham-8/+17
async-pub check created a regression for default
2021-03-17Detect pub fn attr wrong order like `async pub`Ivan Tham-3/+24
Redirects `const? async? unsafe? pub` to `pub const? async? unsafe?`. Fix #76437
2021-03-17Emit more pretty diagnostics for qualified pathsYuki Okushi-14/+21
2021-03-17Fix bad diagnostics for anon params with qualified pathsYuki Okushi-10/+20
2021-03-17Fix bad diagnostics for anon params with refYuki Okushi-31/+54
2021-03-16ast: Reduce size of `ExprKind` by boxing fields of `ExprKind::Struct`Vadim Petrochenkov-1/+5
2021-03-16ast/hir: Rename field-related structuresVadim Petrochenkov-21/+19
StructField -> FieldDef ("field definition") Field -> ExprField ("expression field", not "field expression") FieldPat -> PatField ("pattern field", not "field pattern") Also rename visiting and other methods working on them.
2021-03-15Auto merge of #83074 - Aaron1011:new-sort-fix, r=jackh726bors-0/+1
Avoid sorting predicates by `DefId` Fixes issue #82920 Even if an item does not change between compilation sessions, it may end up with a different `DefId`, since inserting/deleting an item affects the `DefId`s of all subsequent items. Therefore, we use a `DefPathHash` in the incremental compilation system, which is stable in the face of changes to unrelated items. In particular, the query system will consider the inputs to a query to be unchanged if any `DefId`s in the inputs have their `DefPathHash`es unchanged. Queries are pure functions, so the query result should be unchanged if the query inputs are unchanged. Unfortunately, it's possible to inadvertantly make a query result incorrectly change across compilations, by relying on the specific value of a `DefId`. Specifically, if the query result is a slice that gets sorted by `DefId`, the precise order will depend on how the `DefId`s got assigned in a particular compilation session. If some definitions end up with different `DefId`s (but the same `DefPathHash`es) in a subsequent compilation session, we will end up re-computing a *different* value for the query, even though the query system expects the result to unchanged due to the unchanged inputs. It turns out that we have been sorting the predicates computed during `astconv` by their `DefId`. These predicates make their way into the `super_predicates_that_define_assoc_type`, which ends up getting used to compute the vtables of trait objects. This, re-ordering these predicates between compilation sessions can lead to undefined behavior at runtime - the query system will re-use code built with a *differently ordered* vtable, resulting in the wrong method being invoked at runtime. This PR avoids sorting by `DefId` in `astconv`, fixing the miscompilation. However, it's possible that other instances of this issue exist - they could also be easily introduced in the future. To fully fix this issue, we should 1. Turn on `-Z incremental-verify-ich` by default. This will cause the compiler to ICE whenver an 'unchanged' query result changes between compilation sessions, instead of causing a miscompilation. 2. Remove the `Ord` impls for `CrateNum` and `DefId`. This will make it difficult to introduce ICEs in the first place.
2021-03-14Bump recursion_limit in a few placesAaron Hill-0/+1
This is needed to get rustdoc to succeed on `dist-x86_64-linux-alt`
2021-03-13Improve the wording for the `can't reassign` errorYuki Okushi-1/+2
2021-03-09Rollup merge of #82048 - mark-i-m:or-pat-type-ascription, r=petrochenkovMara Bos-67/+130
or-patterns: disallow in `let` bindings ~~Blocked on https://github.com/rust-lang/rust/pull/81869~~ Disallows top-level or-patterns before type ascription. We want to reserve this syntactic space for possible future generalized type ascription. r? ``@petrochenkov``
2021-03-06rustc_ast: Replace `AstLike::finalize_tokens` with a getter `tokens_mut`Vadim Petrochenkov-3/+7
2021-03-05use pat<no_top_alt> for patterns in let bindingsmark-67/+130
2021-03-03Detect match arm body without bracesEsteban Küber-1/+112
Fix #82524.
2021-03-02Rollup merge of #82579 - osa1:issue82566, r=estebankYuki Okushi-4/+12
Fix turbofish recovery with multiple generic args This consists of two commits, each can be individually reviewed. - First commit fixes the issue in [this comment](https://github.com/rust-lang/rust/issues/82566#issuecomment-786924466). - Second commit fixes #82566 --- r? ````@estebank````
2021-02-27Rollup merge of #81856 - Smittyvb:utf16-warn, r=matthewjasperDylan DPC-0/+3
Suggest character encoding is incorrect when encountering random null bytes This adds a note whenever null bytes are seen at the start of a token unexpectedly, since those tend to come from UTF-16 encoded files without a [BOM](https://en.wikipedia.org/wiki/Byte_order_mark) (if a UTF-16 BOM appears it won't be valid UTF-8, but if there is no BOM it be both valid UTF-16 and valid but garbled UTF-8). This approach was suggested in https://github.com/rust-lang/rust/issues/73979#issuecomment-653976451. Closes #73979.
2021-02-27Recover from X<Y,Z> when parsing const exprÖmer Sinan Ağacan-2/+10
This adds recovery when in array type syntax user writes [X; Y<Z, ...>] instead of [X; Y::<Z, ...>] Fixes #82566 Note that whenever we parse an expression and know that the next token cannot be `,`, we should be calling check_mistyped_turbofish_with_multiple_type_params for this recovery. Previously we only did this for statement parsing (e.g. `let x = f<a, b>;`). We now also do it when parsing the length field in array type syntax.
2021-02-27Fix turbofish recovery with multiple generic argsÖmer Sinan Ağacan-2/+2
check_mistyped_turbofish_with_multiple_type_params was previously expecting type arguments between angle brackets, which is not right, as we can also see const expressions. We now use generic argument parser instead of type parser. Test with one, two, and three generic arguments added to check consistentcy between 1. check_no_chained_comparison: Called after parsing a nested binop application like `x < A > ...` where angle brackets are interpreted as binary operators and `A` is an expression. 2. check_mistyped_turbofish_with_multiple_type_params: called by `parse_full_stmt` when we expect to see a semicolon after parsing an expression but don't see it. (In `T2<1, 2>::C;`, the expression is `T2 < 1`)
2021-02-27Combine HasAttrs and HasTokens into AstLikeAaron Hill-6/+6
When token-based attribute handling is implemeneted in #80689, we will need to access tokens from `HasAttrs` (to perform cfg-stripping), and we will to access attributes from `HasTokens` (to construct a `PreexpTokenStream`). This PR merges the `HasAttrs` and `HasTokens` traits into a new `AstLike` trait. The previous `HasAttrs` impls from `Vec<Attribute>` and `AttrVec` are removed - they aren't attribute targets, so the impls never really made sense.
2021-02-26Rollup merge of #82456 - klensy:or-else, r=estebankGuillaume Gomez-1/+1
Replaced some unwrap_or and map_or with lazy variants Replaced some `unwrap_or` and `map_or` with `unwrap_or_else` and `map_or_else`.
2021-02-25Rollup merge of #82321 - bugadani:ast3, r=varkorDylan DPC-1/+1
AST: Remove some unnecessary boxes
2021-02-25fix reviewklensy-1/+1
2021-02-24replaced some map_or with map_or_elseklensy-1/+1
2021-02-23Rollup merge of #82296 - spastorino:pubrules, r=nikomatsakisDylan DPC-9/+1
Support `pub` on `macro_rules` This rebases and updates `since` version of #78166 from ``@petrochenkov`` r? ``@nikomatsakis``
2021-02-23Rollup merge of #81235 - reese:rw-tuple-diagnostics, r=estebankDylan DPC-2/+2
Improve suggestion for tuple struct pattern matching errors. Closes #80174 This change allows numbers to be parsed as field names when pattern matching on structs, which allows us to provide better error messages when tuple structs are matched using a struct pattern. r? ``@estebank``
2021-02-21parser: remove unneccessary wrapping of return value in parse_extern()Matthias Krüger-7/+3
2021-02-21remove unneccessary wrapping of return value in mk_await_expr()Matthias Krüger-3/+3
2021-02-21rustc_parse: remove unneccessary wrapping of return value in fn mk_range() ↵Matthias Krüger-5/+5
which would always return Ok(..)
2021-02-20Remove some P-sDániel Buga-1/+1
2021-02-19Support `pub` on `macro_rules`Vadim Petrochenkov-9/+1
2021-02-19Rollup merge of #82238 - petrochenkov:nocratemod, r=Aaron1011Dylan DPC-24/+11
ast: Keep expansion status for out-of-line module items I.e. whether a module `mod foo;` is already loaded from a file or not. This is a pre-requisite to correctly treating inner attributes on such modules (https://github.com/rust-lang/rust/issues/81661). With this change AST structures for `mod` items diverge even more for AST structure for the crate root, which previously used `ast::Mod`. Therefore this PR removes `ast::Mod` from `ast::Crate` in the first commit, these two things are sufficiently different from each other, at least at syntactic level. Customization points for visiting a "`mod` item or crate root" were also removed from AST visitors (`fn visit_mod`). `ast::Mod` itself was refactored away in the second commit in favor of `ItemKind::Mod(Unsafe, ModKind)`.
2021-02-18Rollup merge of #82236 - matthiaskrgr:useless_conv, r=jyn514Dylan DPC-4/+4
avoid converting types into themselves (clippy::useless_conversion)
2021-02-18ast: Keep expansion status for out-of-line module itemsVadim Petrochenkov-5/+7
Also remove `ast::Mod` which is mostly redundant now
2021-02-18ast: Stop using `Mod` in `Crate`Vadim Petrochenkov-23/+8
Crate root is sufficiently different from `mod` items, at least at syntactic level. Also remove customization point for "`mod` item or crate root" from AST visitors.
2021-02-17avoid converting types into themselves (clippy::useless_conversion)Matthias Krüger-4/+4
2021-02-15Simplify pattern grammar by allowing nested leading vertmark-89/+111
Along the way, we also implement a handful of diagnostics improvements and fixes, particularly with respect to the special handling of `||` in place of `|` and when there are leading verts in function params, which don't allow top-level or-patterns anyway.
2021-02-13Address review commentsAaron Hill-179/+201
2021-02-13Require passing an `AttrWrapper` to `collect_tokens_trailing_token`Aaron Hill-409/+608
This is a pure refactoring split out from #80689. It represents the most invasive part of that PR, requiring changes in every caller of `parse_outer_attributes` In order to eagerly expand `#[cfg]` attributes while preserving the original `TokenStream`, we need to know the range of tokens that corresponds to every attribute target. This is accomplished by making `parse_outer_attributes` return an opaque `AttrWrapper` struct. An `AttrWrapper` must be converted to a plain `AttrVec` by passing it to `collect_tokens_trailing_token`. This makes it difficult to accidentally construct an AST node with attributes without calling `collect_tokens_trailing_token`, since AST nodes store an `AttrVec`, not an `AttrWrapper`. As a result, we now call `collect_tokens_trailing_token` for attribute targets which only support inert attributes, such as generic arguments and struct fields. Currently, the constructed `LazyTokenStream` is simply discarded. Future PRs will record the token range corresponding to the attribute target, allowing those tokens to be removed from an enclosing `collect_tokens_trailing_token` call if necessary.
2021-02-08parser: Fix panic in 'const impl' recoveryÖmer Sinan Ağacan-2/+12
The panic happens when in recovery parsing a full `impl` (`parse_item_impl`) fails and we drop the `DiagnosticBuilder` for the recovery suggestion and return the `parse_item_impl` error. We now raise the original error "expected identifier found `impl`" when parsing the `impl` fails. Note that the regression test is slightly simplified version of the original repro in #81806, to make the error output smaller and more resilient to unrelated changes in parser error messages. Fixes #81806
2021-02-07expand/resolve: Turn `#[derive]` into a regular macro attributeVadim Petrochenkov-4/+2
2021-02-07Clarify error message wordingSmitty-1/+1
2021-02-06Add note about encoding when null bytes foundSmitty-0/+3
2021-02-05Rollup merge of #81307 - estebank:invalid-byte-str-span, r=petrochenkovMara Bos-80/+136
Handle `Span`s for byte and raw strings and add more detail CC #81208.