about summary refs log tree commit diff
path: root/compiler/rustc_parse/src
AgeCommit message (Collapse)AuthorLines
2021-10-07some clippy::perf fixesMatthias Krüger-1/+1
2021-10-04Use `TokenKind::similar_tokens()`Fabian Wolff-1/+4
2021-10-03Try to recover from a `=>` -> `=` or `->` typo in a match armFabian Wolff-1/+15
2021-10-01Rollup merge of #89029 - notriddle:notriddle/issue-89013, r=estebankManish Goregaokar-5/+32
feat(rustc_parse): recover from pre-RFC-2000 const generics syntax Fixes #89013
2021-09-28Improve error messages for bad type constraintsMichael Howell-11/+20
Co-authored-by: Esteban Kuber <esteban@kuber.com.ar>
2021-09-25Check for macros in built-in attributes that don't support them.Eric Huss-1/+13
2021-09-25Move malformed attribute code to a function and fix inner attribute suggestion.Eric Huss-59/+60
Moving to a dedicated function in preparation for other validation. The suggestion given didn't consider if it was an inner attribute.
2021-09-24Rollup merge of #89221 - aDotInTheVoid:macro-error-1, r=estebankJubilee-0/+14
Give better error for `macro_rules! name!` r? ``@estebank`` ``@rustbot`` modify labels: +A-diagnostics +A-parser
2021-09-24Give better error for `macro_rules! name!`Nixon Enraght-Moony-0/+14
2021-09-24Auto merge of #88835 - FabianWolff:issue-88770, r=petrochenkovbors-2/+2
Fix error recovery in format macro parsing Fixes #88770. Basically, the assumption in the following comment is incorrect: https://github.com/rust-lang/rust/blob/b69fe57261086e70aea9d5b58819a1794bf7c121/compiler/rustc_builtin_macros/src/format.rs#L167-L172 This is only true in the first iteration of the loop, when [`p.clear_expected_tokens()`](https://github.com/rust-lang/rust/blob/b69fe57261086e70aea9d5b58819a1794bf7c121/compiler/rustc_builtin_macros/src/format.rs#L164) is called. In subsequent iterations, `p.expected_tokens` won't be empty, so `p.expect()` won't actually call `unexpected_try_recover()`: https://github.com/rust-lang/rust/blob/b69fe57261086e70aea9d5b58819a1794bf7c121/compiler/rustc_parse/src/parser/mod.rs#L487-L498 Instead, it will call `expect_one_of()`, which _can_ recover and return `Ok()`. This PR handles this case to fix the ICE in #88770.
2021-09-23Rollup merge of #89023 - Wardenfar:issue-85066, r=nagisaJubilee-0/+14
Resolve issue : Somewhat confusing error with extended_key_value_attributes Fixes #85066
2021-09-22Rollup merge of #89046 - oli-obk:fix_oflo, r=estebankthe8472-0/+4
"Fix" an overflow in byte position math r? `@estebank` help! I fixed the ICE only to brick the diagnostic. I mean, it was wrong previously (using an already expanded macro span), but it is really bad now XD
2021-09-21Rollup merge of #88795 - FabianWolff:issue-88684, r=wesleywiserthe8472-14/+47
Print a note if a character literal contains a variation selector Fixes #88684.
2021-09-20Add some more tracingOli Scherer-0/+4
2021-09-19Suggest replacing braces for brackets on array-esque invalid block exprHirochika Matsumoto-4/+54
Newcomers may write `{1, 2, 3}` for making arrays, and the current error message is not informative enough to quickly convince them what is needed to fix the error. This PR implements a diagnostic for this case, and its output looks like this: ```text error: this code is interpreted as a block expression, not an array --> src/lib.rs:1:22 | 1 | const FOO: [u8; 3] = { | ______________________^ 2 | | 1, 2, 3 3 | | }; | |_^ | = note: to define an array, one would use square brackets instead of curly braces help: try using [] instead of {} | 1 | const FOO: [u8; 3] = [ 2 | 1, 2, 3 3 | ]; | ``` Fix #87672
2021-09-19Resolve issue 85066Theo-0/+14
Fix : use struct_dummy Fix different os messages
2021-09-17Rollup merge of #87566 - JohnTitor:find-eqeq-on-assoc-type-bounds, r=estebankGuillaume Gomez-1/+13
Recover invalid assoc type bounds using `==` Fix #87493 r? `@estebank`
2021-09-17Apply review commentsYuki Okushi-2/+2
2021-09-17Recover invalid assoc type bounds using `==`Yuki Okushi-1/+13
2021-09-17Use `multipart_suggestion`Yuki Okushi-20/+14
2021-09-17Emit clearer diagnostics for parens around `for` loop headsYuki Okushi-2/+3
2021-09-16feat(rustc_parse): recover from pre-RFC-2000 const generics syntaxMichael Howell-1/+19
Fixes #89013
2021-09-16Rollup merge of #88729 - estebank:struct-literal-using-parens, r=oli-obkManish Goregaokar-10/+91
Recover from `Foo(a: 1, b: 2)` Detect likely `struct` literal using parentheses as delimiters and emit targeted suggestion instead of type ascription parse error. Fix #61326.
2021-09-15Rollup merge of #88775 - pnkfelix:revert-anon-union-parsing, r=davidtwcoManish Goregaokar-35/+16
Revert anon union parsing Revert PR #84571 and #85515, which implemented anonymous union parsing in a manner that broke the context-sensitivity for the `union` keyword and thus broke stable Rust code. Fix #88583.
2021-09-15Rollup merge of #88690 - m-ou-se:macro-braces-dot-question-expr-parse, r=nagisaManish Goregaokar-11/+14
Accept `m!{ .. }.method()` and `m!{ .. }?` statements. This PR fixes something that I keep running into when using `quote!{}.into()` in a proc macro to convert the `proc_macro2::TokenStream` to a `proc_macro::TokenStream`: Before: ``` error: expected expression, found `.` --> src/lib.rs:6:6 | 4 | quote! { 5 | ... 6 | }.into() | ^ expected expression ``` After: ``` ``` (No output, compiles fine.) --- Context: For expressions like `{ 1 }` and `if true { 1 } else { 2 }`, we accept them as full statements without a trailing `;`, which means the following is not accepted: ```rust { 1 } - 1 // error ``` since that is parsed as two statements: `{ 1 }` and `-1`. Syntactically correct, but the type of `{ 1 }` should be `()` as there is no `;`. However, for specifically `.` and `?` after the `}`, we do [continue parsing it as an expression](https://github.com/rust-lang/rust/blob/13db8440bbbe42870bc828d4ec3e965b38670277/compiler/rustc_parse/src/parser/expr.rs#L864-L876): ```rust { "abc" }.len(); // ok ``` For braced macro invocations, we do not do this: ```rust vec![1, 2, 3].len(); // ok vec!{1, 2, 3}.len(); // error ``` (It parses `vec!{1, 2, 3}` as a full statement, and then complains about `.len()` not being a valid expression.) This PR changes this to also look for a `.` and `?` after a braced macro invocation. We can be sure the macro is an expression and not a full statement in those cases, since no statement can start with a `.` or `?`.
2021-09-14review comment: move recovery code to its own functionEsteban Kuber-2/+19
2021-09-14Auto merge of #88914 - GuillaumeGomez:rollup-h5svc6w, r=GuillaumeGomezbors-1/+14
Rollup of 7 pull requests Successful merges: - #88033 (Add links for primitives in "jump to definition" feature) - #88722 (Make `UnsafeCell::get_mut` const) - #88851 (Fix duplicate bounds for const_trait_impl) - #88859 (interpreter PointerArithmetic: use new Size helper methods) - #88885 (Fix jump def background) - #88894 (Improve error message for missing trait in trait impl) - #88896 (Reduce possibility of flaky tests) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-09-13Auto merge of #87915 - estebank:fancy-spans, r=oli-obkbors-39/+46
Use smaller spans for some structured suggestions Use more accurate suggestion spans for * argument parse error * fully qualified path * missing code block type * numeric casts
2021-09-12Improve error message for missing trait in trait implFabian Wolff-1/+14
2021-09-11Auto merge of #84373 - cjgillot:resolve-span, r=michaelwoerister,petrochenkovbors-1/+1
Encode spans relative to the enclosing item The aim of this PR is to avoid recomputing queries when code is moved without modification. MCP at https://github.com/rust-lang/compiler-team/issues/443 This is achieved by : 1. storing the HIR owner LocalDefId information inside the span; 2. encoding and decoding spans relative to the enclosing item in the incremental on-disk cache; 3. marking a dependency to the `source_span(LocalDefId)` query when we translate a span from the short (`Span`) representation to its explicit (`SpanData`) representation. Since all client code uses `Span`, step 3 ensures that all manipulations of span byte positions actually create the dependency edge between the caller and the `source_span(LocalDefId)`. This query return the actual absolute span of the parent item. As a consequence, any source code motion that changes the absolute byte position of a node will either: - modify the distance to the parent's beginning, so change the relative span's hash; - dirty `source_span`, and trigger the incremental recomputation of all code that depends on the span's absolute byte position. With this scheme, I believe the dependency tracking to be accurate. For the moment, the spans are marked during lowering. I'd rather do this during def-collection, but the AST MutVisitor is not practical enough just yet. The only difference is that we attach macro-expanded spans to their expansion point instead of the macro itself.
2021-09-11Rollup merge of #88668 - hvdijk:x32, r=joshtriplettJubilee-1/+1
Change more x64 size checks to not apply to x32. Commit 95e096d6 changed a bunch of size checks already, but more have been added, so this fixes the new ones the same way: the various size checks that are conditional on target_arch = "x86_64" were not intended to apply to x86_64-unknown-linux-gnux32, so add target_pointer_width = "64" to the conditions.
2021-09-10Fix error recovery in format macro parsingFabian Wolff-2/+2
2021-09-10Keep a parent LocalDefId in SpanData.Camille GILLOT-1/+1
2021-09-10Improve diagnostics if a character literal contains combining marksFabian Wolff-14/+47
2021-09-09Emit proper errors on missing closure bracesSasha Pourcelot-9/+124
This commit focuses on emitting clean errors for the following syntax error: ``` Some(42).map(|a| dbg!(a); a ); ``` Previous implementation tried to recover after parsing the closure body (the `dbg` expression) by replacing the next `;` with a `,`, which made the next expression belong to the next function argument. As such, the following errors were emitted (among others): - the semicolon token was not expected, - a is not in scope, - Option::map is supposed to take one argument, not two. This commit allows us to gracefully handle this situation by adding giving the parser the ability to remember when it has just parsed a closure body inside a function call. When this happens, we can treat the unexpected `;` specifically and try to parse as much statements as possible in order to eat the whole block. When we can't parse statements anymore, we generate a clean error indicating that the braces are missing, and return an ExprKind::Err.
2021-09-09Re-add 71a7f8f1884b2c83eeb4a545eef16df1f2ea6476 post-revert.Felix S. Klock II-1/+4
2021-09-09Revert "Implement Anonymous{Struct, Union} in the AST"Felix S. Klock II-35/+13
This reverts commit 059b68dd677808e14e560802d235ad40beeba71e. Note that this was manually adjusted to retain some of the refactoring introduced by commit 059b68dd677808e14e560802d235ad40beeba71e, so that it could likewise retain the correction introduced in commit 5b4bc05fa57be19bb5962f4b7c0f165e194e3151
2021-09-08Bump stage0 compiler to 1.56Mark Rousskov-2/+0
2021-09-08Rollup merge of #88553 - theo-lw:issue-88276, r=estebankJack Huey-0/+20
Improve diagnostics for unary plus operators (#88276) This pull request improves the diagnostics emitted on parsing a unary plus operator. See #88276. Before: ``` error: expected expression, found `+` --> src/main.rs:2:13 | 2 | let x = +1; | ^ expected expression ``` After: ``` error: leading `+` is not supported --> main.rs:2:13 | 2 | let x = +1; | ^ | | | unexpected `+` | help: try removing the `+` ```
2021-09-07Recover from `Foo(a: 1, b: 2)`Esteban Kuber-10/+74
Detect likely `struct` literal using parentheses as delimiters and emit targeted suggestion instead of type ascription parse error. Fix #61326.
2021-09-06Accept `m!{ .. }.method()` and `m!{ .. }?` statements.Mara Bos-11/+14
2021-09-05Change more x64 size checks to not apply to x32.Harald van Dijk-1/+1
Commit 95e096d6 changed a bunch of size checks already, but more have been added, so this fixes the new ones the same way: the various size checks that are conditional on target_arch = "x86_64" were not intended to apply to x86_64-unknown-linux-gnux32, so add target_pointer_width = "64" to the conditions.
2021-09-05Rollup merge of #88257 - estebank:invalid-attr-error, r=oli-obkMara Bos-21/+119
Provide more context on incorrect inner attribute Suggest changing an inner attribute into an outer attribute if followed by an item.
2021-09-04Use verbose suggestions and only match if the + is seen before a numeric literalTheodore Luo Wang-4/+3
2021-09-04Auto merge of #88598 - estebank:type-ascription-can-die-in-a-fire, r=wesleywiserbors-4/+16
Detect bare blocks with type ascription that were meant to be a `struct` literal Address part of #34255. Potential improvement: silence the other knock down errors in `issue-34255-1.rs`.
2021-09-03Auto merge of #88597 - cjgillot:lower-global, r=petrochenkovbors-2/+1
Move global analyses from lowering to resolution Split off https://github.com/rust-lang/rust/pull/87234 r? `@petrochenkov`
2021-09-03Detect bare blocks with type ascription that were meant to be a `struct` literalEsteban Kuber-4/+16
Address part of #34255. Potential improvement: silence the other knock down errors in `issue-34255-1.rs`.
2021-09-03Auto merge of #88386 - estebank:unmatched-delims, r=jackh726bors-3/+18
Point at unclosed delimiters as part of the primary MultiSpan Both the place where the parser encounters a needed closed delimiter and the unclosed opening delimiter are important, so they should get the same level of highlighting in the output. _Context: https://twitter.com/mwk4/status/1430631546432675840_
2021-09-03Auto merge of #88363 - michaelwoerister:remapped-diagnostics, r=estebankbors-1/+1
Path remapping: Make behavior of diagnostics output dependent on presence of --remap-path-prefix. This PR fixes a regression (#87745) with `--remap-path-prefix` where the flag stopped causing diagnostic messages to be remapped as well. The regression was introduced in https://github.com/rust-lang/rust/pull/83813 where we erroneously assumed that remapping of diagnostic messages was not desired anymore (because #70642 partially undid that functionality with nobody objecting). The issue is fixed by making `--remap-path-prefix` remap diagnostic messages again, including for paths that have been remapped in upstream crates (e.g. the standard library). This means that "sysroot-localization" (implemented in #70642) is also disabled if `rustc` is invoked with `--remap-path-prefix`. The assumption is that once someone starts explicitly remapping paths they also don't want paths to their local Rust installation in their build output. In the future we might want to give more fine-grained control over this behavior via compiler flags (see https://github.com/rust-lang/rfcs/pull/3127 for a related RFC). For now this PR is intended as a regression fix. This PR is an alternative to https://github.com/rust-lang/rust/pull/88191, which makes diagnostic messages be remapped unconditionally. That approach, however, would effectively revert #70642. Fixes https://github.com/rust-lang/rust/issues/87745. cc `@cbeuw` r? `@ghost`
2021-09-02Provide more context on incorrect inner attributeEsteban Kuber-21/+119
Suggest changing an inner attribute into an outer attribute if followed by an item.