summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/diagnostics.rs
AgeCommit message (Collapse)AuthorLines
2021-11-25Auto merge of #85346 - estebank:issue-84946, r=nagisa,varkorbors-6/+73
Account for incorrect `impl Foo<const N: ty> {}` syntax Fix #84946
2021-11-24Tweak span and add more testsEsteban Kuber-5/+2
2021-11-24Account for incorrect `impl Foo<const N: ty> {}` syntaxEsteban Küber-6/+76
Fix #84946
2021-11-22fix(doctest): detect extern crate items in statement doctestsMichael Howell-1/+1
This partially reverts #91026, because rustdoc needs to detect the extern statements, even when they appear inside implicit `main()`. It does not entirely revert it, so the old bug is still fixed, by duplicating some of the logic from `parse_mod` instead of trying to use it directly. Fixes #91134
2021-10-17Some "parenthesis" and "parentheses" fixesr00ster91-2/+2
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-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-19/+13
2021-09-17Emit clearer diagnostics for parens around `for` loop headsYuki Okushi-2/+3
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-10Fix error recovery in format macro parsingFabian Wolff-2/+2
2021-09-04Auto merge of #88598 - estebank:type-ascription-can-die-in-a-fire, r=wesleywiserbors-3/+8
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-03Detect bare blocks with type ascription that were meant to be a `struct` literalEsteban Kuber-3/+8
Address part of #34255. Potential improvement: silence the other knock down errors in `issue-34255-1.rs`.
2021-08-27Point at unclosed delimiters as part of the primary MultiSpanEsteban Kuber-1/+11
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.
2021-08-12Use smaller spans for some structured suggestionsEsteban Kuber-39/+46
Use more accurate suggestion spans for * argument parse error * fully qualified path * missing code block type * numeric casts * E0212
2021-07-30Use multispan suggestions more oftenEsteban Küber-1/+1
* Use more accurate span for `async move` suggestion * Use more accurate span for deref suggestion * Use `multipart_suggestion` more often
2021-07-24fix code to suggest `;` on parse errorElliot Bobrow-57/+57
2021-06-10Add support for using qualified paths with structs in expression and patternRyan Levick-1/+1
position.
2021-05-08Rename `Parser::span_fatal_err` -> `Parser::span_err`Joshua Nelson-5/+1
The name was misleading, it wasn't actually a fatal error.
2021-04-12don't bump in check_mistyped_turbofish_with_multiple_type_paramsb-naber-15/+17
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-02-27Fix turbofish recovery with multiple generic argsÖmer Sinan Ağacan-1/+1
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-25fix reviewklensy-1/+1
2021-02-24replaced some map_or with map_or_elseklensy-1/+1
2021-02-15Simplify pattern grammar by allowing nested leading vertmark-1/+1
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-01-31Improve handling of spans around macro result parse errorsAaron Hill-2/+2
Fixes #81543 After we expand a macro, we try to parse the resulting tokens as a AST node. This commit makes several improvements to how we handle spans when an error occurs: * Only ovewrite the original `Span` if it's a dummy span. This preserves a more-specific span if one is available. * Use `self.prev_token` instead of `self.token` when emitting an error message after encountering EOF, since an EOF token always has a dummy span * Make `SourceMap::next_point` leave dummy spans unused. A dummy span does not have a logical 'next point', since it's a zero-length span. Re-using the span span preserves its 'dummy-ness' for other checks
2021-01-22improve diagnostics for angle argsb-naber-5/+16
2021-01-14Use Option::map_or instead of `.map(..).unwrap_or(..)`LingMan-1/+1
2020-12-21Implemented a compiler diagnostic for move async mistakeDion Dokter-0/+18
Ran the tidy check Following the diagnostic guide better Diagnostic generation is now relegated to its own function in the diagnostics module. Added tests Fixed the ui test
2020-11-18Permit standalone generic parameters as const generic arguments in macrosvarkor-3/+7
2020-10-30Fix even more clippy warningsJoshua Nelson-5/+1
2020-10-29Rollup merge of #78460 - varkor:turbofish-string-generic, r=lcnrYuki Okushi-4/+5
Adjust turbofish help message for const generics Types are no longer special. (This message arguably only makes sense with `min_const_generics` or more, but we'll be there soon.) r? @lcnr
2020-10-28Adjust turbofish help message for const genericsvarkor-4/+5
2020-10-28Rollup merge of #78379 - estebank:fn-signature-parse, r=varkorDylan DPC-8/+0
Tweak invalid `fn` header and body parsing * Rely on regular "expected"/"found" parser error for `fn`, fix #77115 * Recover empty `fn` bodies when encountering `}` * Recover trailing `>` in return types * Recover from non-type in array type `[<BAD TOKEN>; LEN]`
2020-10-27Auto merge of #77502 - varkor:const-generics-suggest-enclosing-braces, ↵bors-4/+143
r=petrochenkov Suggest that expressions that look like const generic arguments should be enclosed in brackets I pulled out the changes for const expressions from https://github.com/rust-lang/rust/pull/71592 (without the trait object diagnostic changes) and made some small changes; the implementation is `@estebank's.` We're also going to want to make some changes separately to account for trait objects (they result in poor diagnostics, as is evident from one of the test cases here), such as an adaption of https://github.com/rust-lang/rust/pull/72273. Fixes https://github.com/rust-lang/rust/issues/70753. r? `@petrochenkov`
2020-10-26Suggest expressions that look like const generic arguments should be ↵varkor-4/+143
enclosed in brackets Co-Authored-By: Esteban Kuber <github@kuber.com.ar>
2020-10-25Rely on regular "expected"/"found" parser error for `fn`Esteban Küber-8/+0
2020-10-23Silence unnecessary `await foo?` knock-down errorEsteban Küber-1/+7
2020-10-07Detect blocks that could be struct expr bodiesEsteban Küber-2/+85
This approach lives exclusively in the parser, so struct expr bodies that are syntactically correct on their own but are otherwise incorrect will still emit confusing errors, like in the following case: ```rust fn foo() -> Foo { bar: Vec::new() } ``` ``` error[E0425]: cannot find value `bar` in this scope --> src/file.rs:5:5 | 5 | bar: Vec::new() | ^^^ expecting a type here because of type ascription error[E0214]: parenthesized type parameters may only be used with a `Fn` trait --> src/file.rs:5:15 | 5 | bar: Vec::new() | ^^^^^ only `Fn` traits may use parentheses error[E0107]: wrong number of type arguments: expected 1, found 0 --> src/file.rs:5:10 | 5 | bar: Vec::new() | ^^^^^^^^^^ expected 1 type argument ``` If that field had a trailing comma, that would be a parse error and it would trigger the new, more targetted, error: ``` error: struct literal body without path --> file.rs:4:17 | 4 | fn foo() -> Foo { | _________________^ 5 | | bar: Vec::new(), 6 | | } | |_^ | help: you might have forgotten to add the struct literal inside the block | 4 | fn foo() -> Foo { Path { 5 | bar: Vec::new(), 6 | } } | ``` Partially address last part of #34255.
2020-09-15Auto merge of #76171 - estebank:turbofish-the-revenge, r=davidtwcobors-0/+46
Detect turbofish with multiple type params missing leading `::` Fix #76072.
2020-09-14Detect turbofish with multiple type params missing leading `::`Esteban Küber-0/+46
Fix #76072.
2020-09-10Attach `TokenStream` to `ast::Path`Aaron Hill-1/+1
2020-09-10Attach `TokenStream` to `ast::Ty`Aaron Hill-2/+7
A `Ty` does not have outer attributes, so we only capture tokens when parsing a `macro_rules!` matcher
2020-08-30mv compiler to compiler/mark-0/+1643