Commit Graph

714 Commits

Author SHA1 Message Date
Takayuki Maeda
2135331a33 remove the rest of unnecessary to_string 2022-06-17 18:48:09 +09:00
Chayim Refael Friedman
0ef4098a54 Do not suggest adding semicolon/changing delimiters for macros in item position that originates in macros 2022-06-16 02:19:31 +00:00
Michael Goulet
d1ba2d25d4 Improve parsing errors and suggestions for bad if statements 2022-06-13 20:53:48 -07:00
Yuki Okushi
e3a3c00be8
Rollup merge of #95211 - terrarier2111:improve-parser, r=compiler-errors
Improve parser diagnostics

This pr fixes https://github.com/rust-lang/rust/issues/93867 and contains a couple of diagnostics related changes to the parser.
Here is a short list with some of the changes:
- don't suggest the same thing that is the current token
- suggest removing the current token if the following token is one of the suggestions (maybe incorrect)
- tell the user to put a type or lifetime after where if there is none (as a warning)
- reduce the amount of tokens suggested (via the new eat_noexpect and check_noexpect methods)

If any of these changes are undesirable, i can remove them, thanks!
2022-06-14 07:47:22 +09:00
Takayuki Maeda
fd1290a631 remove unnecessary to_string and String::new for tool_only_span_suggestion 2022-06-13 16:01:16 +09:00
Takayuki Maeda
77d6176e69 remove unnecessary to_string and String::new 2022-06-13 15:48:40 +09:00
threadexception
21fdd549f6 Improves parser diagnostics, fixes #93867 2022-06-12 17:48:52 +02:00
Takayuki Maeda
84a13a28b7 use create_snapshot_for_diagnostic instead of clone 2022-06-12 17:27:36 +09:00
Michael Goulet
f12a1c23bc
Rollup merge of #97857 - ChayimFriedman2:box-identifier-help, r=compiler-errors
Suggest escaping `box` as identifier

Fixes #97810.
2022-06-08 13:32:21 -07:00
Chayim Refael Friedman
c1b1ec7e07 Suggest escaping box as identifier 2022-06-08 06:17:25 +00:00
Dylan DPC
a90c5a3c69
Rollup merge of #97823 - compiler-errors:missing-comma-match-arm, r=estebank
Recover missing comma after match arm

If we're missing a comma after a match arm expression, try parsing another pattern and a following `=>`. If we find both of those, then recover by suggesting to insert a `,`.

Fixes #80112
2022-06-08 07:37:32 +02:00
Michael Goulet
b7ed860108 recover import instead of use in item 2022-06-07 19:14:03 -07:00
Michael Goulet
b13eb61a2c Recover missing comma after match arm 2022-06-07 02:19:51 -07:00
Waffle Maybe
4f85a73e51 Add spaces before and after expr in add {} suggestion
Co-authored-by: Michael Goulet <michael@errs.io>
2022-06-06 01:40:52 +04:00
Maybe Waffle
f06f051745 Suggest removing label in 'label: non_block_expr 2022-06-05 23:34:11 +04:00
Maybe Waffle
c6e5bb32fb Do not suggest adding labeled block if there are no labeled breaks 2022-06-05 23:12:51 +04:00
Maybe Waffle
f21c0a274e Suggest adding {} for 'label: non_block_expr 2022-06-05 16:45:29 +04:00
Dylan DPC
19dc28c23e
Rollup merge of #97587 - pvdrz:maybe-recover-from-bad-qpath-stage-2, r=davidtwco
Migrate more diagnostics to use the `#[derive(SessionDiagnostic)]`

r? ``@davidtwco``
2022-06-02 11:13:24 +02:00
Yuki Okushi
d126de111b
Rollup merge of #97166 - nnethercote:move-conditions-out, r=estebank
Move conditions out of recover/report functions.

`Parser` has six recover/report functions that are passed a boolean, and
nothing is done if the boolean has a particular value.

This PR moves the tests outside the functions. This has the following effects.
- The number of lines of code goes down.
- Some `use` items become shorter.
- Avoids the strangeness whereby 11 out of 12 calls to
  `maybe_recover_from_bad_qpath` pass `true` as the second argument.
- Makes it clear at the call site that only one of
  `maybe_recover_from_bad_type_plus` and `maybe_report_ambiguous_plus` will be
  run.

r? `@estebank`
2022-06-02 06:44:27 +09:00
Christian Poveda
0fa70a8e2a
rename sp to span 2022-06-01 07:14:33 -05:00
Christian Poveda
e1d63d1d7c
migrate check_for_for_in_in_typo diagnostic 2022-05-31 16:28:05 -05:00
Christian Poveda
9ce04e3783
merge diagnostics about incorrect uses of .await 2022-05-31 15:07:44 -05:00
Christian Poveda
a06ba45487
migrate error_on_incorrect_await diagnostic 2022-05-31 14:32:07 -05:00
Christian Poveda
2a0496cbc8
use suggestion_short for incorrect semicolon diagnostic 2022-05-31 12:56:26 -05:00
Christian Poveda
93a427e3ca
migrate recover_from_await_method_call diagnostic 2022-05-31 12:33:35 -05:00
Christian Poveda
29ed9a56e3
migrate maybe_consume_incorrect_semicolon diagnostic 2022-05-31 11:45:44 -05:00
Christian Poveda
bd4d1cd7a2
migrate maybe_recover_from_bad_qpath_stage_2 diagnostic 2022-05-31 11:22:26 -05:00
bors
47365c0d65 Auto merge of #97566 - compiler-errors:rollup-qfxw4j8, r=compiler-errors
Rollup of 6 pull requests

Successful merges:

 - #89685 (refactor: VecDeques Iter fields to private)
 - #97172 (Optimize the diagnostic generation for `extern unsafe`)
 - #97395 (Miri call ABI check: ensure type size+align stay the same)
 - #97431 (don't do `Sized` and other return type checks on RPIT's real type)
 - #97555 (Source code page: line number click adds `NaN`)
 - #97558 (Fix typos in comment)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-05-31 01:17:00 +00:00
Michael Goulet
22da719762
Rollup merge of #97172 - SparrowLii:unsafe_extern, r=compiler-errors
Optimize the diagnostic generation for `extern unsafe`

This PR does the following about diagnostic generation when parsing foreign mod:
1. Fixes the FIXME about avoiding depending on the error message text.
2. Continue parsing when `unsafe` is followed by `{` (just like `unsafe extern {...}`).
3. Add test case.
2022-05-30 15:57:27 -07:00
David Wood
f669b78ffc errors: simplify referring to fluent attributes
To render the message of a Fluent attribute, the identifier of the
Fluent message must be known. `DiagnosticMessage::FluentIdentifier`
contains both the message's identifier and optionally the identifier of
an attribute. Generated constants for each attribute would therefore
need to be named uniquely (amongst all error messages) or be able to
refer to only the attribute identifier which will be combined with a
message identifier later. In this commit, the latter strategy is
implemented as part of the `Diagnostic` type's functions for adding
subdiagnostics of various kinds.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-05-30 13:38:19 +01:00
SparrowLii
0be2ca96fa Optimize the diagnostic generation for extern unsafe 2022-05-30 15:56:43 +08:00
Michael Goulet
d61d30d9a2 Minor improvement on else-no-if diagnostic 2022-05-24 15:22:13 -07:00
Dylan DPC
0531521dbb
Rollup merge of #97298 - compiler-errors:if-else-stmt-braces, r=davidtwco
Parse expression after `else` as a condition if followed by `{`

Fixes #49361.

Two things:
1. This wording needs help. I can never find a natural/intuitive phrasing when I write diagnostics 😅
2. Do we even want to show the "wrap in braces" case? I would assume most of the time the "add an `if`" case is the right one.
2022-05-24 15:58:24 +02:00
bors
b2eba058e6 Auto merge of #97121 - pvdrz:do-subdiagnostics-later, r=davidtwco
Avoid double binding of subdiagnostics inside `#[derive(SessionDiagnostic)]`

r? `@davidtwco`
2022-05-24 10:25:13 +00:00
Michael Goulet
9be37b2d3f Parse expression after else as a condition if followed by { 2022-05-23 21:09:35 -07:00
Dylan DPC
b73f1c77a7
Rollup merge of #97254 - jhpratt:remove-crate-vis, r=cjgillot
Remove feature: `crate` visibility modifier

FCP completed in #53120.
2022-05-23 07:43:50 +02:00
Vadim Petrochenkov
8e8fb4f49e rustc_parse: Move AST -> TokenStream conversion logic to rustc_ast 2022-05-22 12:01:07 +03:00
Jacob Pratt
7b987e34c0
Merge crate and restricted visibilities 2022-05-21 17:02:55 -04:00
Jacob Pratt
8cece636b2
Remove feature: crate visibility modifier 2022-05-21 14:22:06 -04:00
Jacob Pratt
49c82f31a8
Remove crate visibility usage in compiler 2022-05-20 20:04:54 -04:00
Camille GILLOT
db8a9274a9 Introduce BareFnTy::decl_span and fix generics span. 2022-05-20 12:26:37 +02:00
Nicholas Nethercote
7b6c5c76a5 Move condition out of maybe_recover_unexpected_comma. 2022-05-19 16:53:23 +10:00
Nicholas Nethercote
d4347ed678 Move condition out of maybe_recover_colon_colon_in_pat_typo. 2022-05-19 16:53:23 +10:00
Nicholas Nethercote
7a37e0c2ff Move condition out of maybe_report_ambiguous_plus and maybe_recover_from_bad_type_plus. 2022-05-19 16:53:06 +10:00
Nicholas Nethercote
a148a32fdc Move condition out of maybe_recover_from_question_mark. 2022-05-19 16:13:48 +10:00
Nicholas Nethercote
1b422451ae Move condition out of maybe_recover_from_bad_qpath. 2022-05-19 16:13:41 +10:00
Christian Poveda
462c1c846b
generate code for subdiagnostic fields in the second match 2022-05-17 13:10:15 -05:00
Christian Poveda
7cafefec4a
keep bounds where they were 2022-05-16 22:23:32 -05:00
Christian Poveda
7e8517df61
migrate maybe_recover_from_bad_type_plus diagnostic 2022-05-16 17:16:27 -05:00
Vadim Petrochenkov
f2b7fa4847 ast: Introduce some traits to get AST node properties generically
And use them to avoid constructing some artificial `Nonterminal` tokens during expansion
2022-05-11 12:43:27 +03:00