Commit Graph

669 Commits

Author SHA1 Message Date
Dylan DPC
22d554657d
Rollup merge of #94985 - dtolnay:constattr, r=pnkfelix
Parse inner attributes on inline const block

According to https://github.com/rust-lang/rust/pull/84414#issuecomment-826150936, inner attributes are intended to be supported *"in all containers for statements (or some subset of statements)"*.

This PR adds inner attribute parsing and pretty-printing for inline const blocks (https://github.com/rust-lang/rust/issues/76001), which contain statements just like an unsafe block or a loop body.

```rust
let _ = const {
    #![allow(...)]

    let x = ();
    x
};
```
2022-04-16 19:42:00 +02:00
Dylan DPC
946d76ec0e
Rollup merge of #95859 - rainy-me:unterminated-nested-block-comment, r=petrochenkov
Improve diagnostics for unterminated nested block comment

close #95283

(This is my first time try to messing around with rust compiler and might get a lot of things wrong... 🙇 )
2022-04-16 07:12:44 +02:00
rainy-me
1b7008dc77 refactor: change to use peekable 2022-04-14 21:18:27 +09:00
Matthias Krüger
7c2d57e0fa couple of clippy::complexity fixes 2022-04-13 22:51:34 +02:00
rainy-me
4a0f8d5175 improve diagnostics for unterminated nested block comment 2022-04-14 03:22:02 +09:00
Takayuki Maeda
29c41280a1 use to_string instead of format! 2022-04-12 07:51:23 +09:00
Michael Goulet
b65265b5e1 better error for binder on associated type bound 2022-04-10 16:41:15 -07:00
bors
fa72316031 Auto merge of #95715 - nnethercote:shrink-Nonterminal, r=davidtwco
Shrink `Nonterminal`

Small consistency and performance improvements.

r? `@petrochenkov`
2022-04-07 12:52:32 +00:00
Nicholas Nethercote
d9592c2d9f Shrink Nonterminal.
By heap allocating the argument within `NtPath`, `NtVis`, and `NtStmt`.
This slightly reduces cumulative and peak allocation amounts, most
notably on `deep-vector`.
2022-04-07 12:51:50 +10:00
León Orell Valerian Liehr
5ab0548500 Stop flagging certain inner attrs as outer ones 2022-04-06 19:54:05 +02:00
David Wood
7f91697b50 errors: implement fallback diagnostic translation
This commit updates the signatures of all diagnostic functions to accept
types that can be converted into a `DiagnosticMessage`. This enables
existing diagnostic calls to continue to work as before and Fluent
identifiers to be provided. The `SessionDiagnostic` derive just
generates normal diagnostic calls, so these APIs had to be modified to
accept Fluent identifiers.

In addition, loading of the "fallback" Fluent bundle, which contains the
built-in English messages, has been implemented.

Each diagnostic now has "arguments" which correspond to variables in the
Fluent messages (necessary to render a Fluent message) but no API for
adding arguments has been added yet. Therefore, diagnostics (that do not
require interpolation) can be converted to use Fluent identifiers and
will be output as before.
2022-04-05 07:01:02 +01:00
David Wood
c45f29595d span: move MultiSpan
`MultiSpan` contains labels, which are more complicated with the
introduction of diagnostic translation and will use types from
`rustc_errors` - however, `rustc_errors` depends on `rustc_span` so
`rustc_span` cannot use types like `DiagnosticMessage` without
dependency cycles. Introduce a new `rustc_error_messages` crate that can
contain `DiagnosticMessage` and `MultiSpan`.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05 07:01:00 +01:00
David Wood
8c684563a5 errors: introduce DiagnosticMessage
Introduce a `DiagnosticMessage` type that will enable diagnostic
messages to be simple strings or Fluent identifiers.
`DiagnosticMessage` is now used in the implementation of the standard
`DiagnosticBuilder` APIs.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05 06:53:39 +01:00
bors
133859d680 Auto merge of #88672 - camelid:inc-parser-sugg, r=davidtwco
Suggest `i += 1` when we see `i++` or `++i`

Closes #83502 (for `i++` and `++i`; `--i` should be covered by #82987, and `i--`
is tricky to handle).

This is a continuation of #83536.

r? `@estebank`
2022-04-03 05:24:20 +00:00
bors
c1550e3f8c Auto merge of #95590 - GuillaumeGomez:multi-line-attr-handling-doctest, r=notriddle
Fix multiline attributes handling in doctests

Fixes #55713.

I needed to have access to the `unclosed_delims` field in order to check that the attribute was completely parsed and didn't have missing parts, so I created a getter for it.

r? `@notriddle`
2022-04-02 23:39:25 +00:00
Guillaume Gomez
c37cd911a4 Fix doctest multi-line mod attributes handling 2022-04-02 20:53:19 +02:00
Matthias Krüger
8f493fd46a
Rollup merge of #95293 - compiler-errors:braces, r=davidtwco
suggest wrapping single-expr blocks in square brackets

Suggests a fix in cases like:

```diff
- const A: [i32; 1] = { 1 };

+ const A: [i32; 1] = [ 1 ];
                      ^   ^
```

Also edit the message for the same suggestion in the parser (e.g. `{ 1, 2 }`).

Fixes #95289
2022-04-01 06:59:42 +02:00
Dylan DPC
1b7d6dbd30
Rollup merge of #95497 - nyurik:compiler-spell-comments, r=compiler-errors
Spellchecking compiler comments

This PR cleans up the rest of the spelling mistakes in the compiler comments. This PR does not change any literal or code spelling issues.
2022-03-31 04:57:28 +02:00
Dylan DPC
86388f6171
Rollup merge of #95251 - GrishaVar:hashes-u16-to-u8, r=dtolnay
Reduce max hash in raw strings from u16 to u8

[Relevant discussion](https://rust-lang.zulipchat.com/#narrow/stream/237824-t-lang.2Fdoc/topic/Max.20raw.20string.20delimiters)
2022-03-31 00:26:31 +02:00
Yuri Astrakhan
a6dd658254 Addressed comments by @compiler-errors and @bjorn3 2022-03-30 17:04:46 -04:00
Yuri Astrakhan
5160f8f843 Spellchecking compiler comments
This PR cleans up the rest of the spelling mistakes in the compiler comments. This PR does not change any literal or code spelling issues.
2022-03-30 15:14:15 -04:00
Grisha Vartanyan
759d1e6af8 Update error message & remove outdated test comment 2022-03-30 18:20:30 +02:00
Dylan DPC
03b3993ae8
Rollup merge of #95461 - nyurik:spelling, r=lcnr
Spellchecking some comments

This PR attempts to clean up some minor spelling mistakes in comments
2022-03-30 09:10:07 +02:00
Yuri Astrakhan
7e8201ae0a Spellchecking some comments
This PR attempts to clean up some minor spelling mistakes in comments
2022-03-30 01:39:38 -04:00
Dylan DPC
e10d5039bc
Rollup merge of #95318 - rust-lang:notriddle/issue-95208, r=wesleywiser
diagnostics: correct generic bounds with doubled colon

Fixes #95208
2022-03-28 20:41:50 +02:00
Dylan DPC
ae037a86f9
Rollup merge of #95301 - nnethercote:rm-NtTT, r=petrochenkov
Remove `Nonterminal::NtTT`.

It's only needed for macro expansion, not as a general element in the
AST. This commit removes it, adds `NtOrTt` for the parser and macro
expansion cases, and renames the variants in `NamedMatch` to better
match the new type.

r? `@petrochenkov`
2022-03-28 16:08:07 +02:00
Michael Goulet
928388bad2 Make fatal DiagnosticBuilder yield never 2022-03-27 22:25:32 -07:00
Nicholas Nethercote
364b908d57 Remove Nonterminal::NtTT.
It's only needed for macro expansion, not as a general element in the
AST. This commit removes it, adds `NtOrTt` for the parser and macro
expansion cases, and renames the variants in `NamedMatch` to better
match the new type.
2022-03-28 10:03:02 +11:00
Noah Lev
4943688e9d Fix from rebase
I changed the test functions to be `pub` rather than called from a
`main` function too, for easier future modification of tests.
2022-03-27 13:54:34 -07:00
bors
ab0c2e18dc Auto merge of #94495 - estebank:missing-closing-gt, r=jackh726
Provide suggestion for missing `>` in a type parameter list

When encountering an inproperly terminated type parameter list, provide
a suggestion to close it after the last non-constraint type parameter
that was successfully parsed.

Fix #94058.
2022-03-27 18:55:58 +00:00
Esteban Kuber
157c67b7a8 Handle , to ; substitution in arg params 2022-03-27 06:05:18 +00:00
Esteban Kuber
6874bd27f5 Provide suggestion for missing > in a type parameter list
When encountering an inproperly terminated type parameter list, provide
a suggestion to close it after the last non-constraint type parameter
that was successfully parsed.

Fix #94058.
2022-03-27 02:50:04 +00:00
Aaron Hill
8035796b9a
Stablize const_extern_fn for "Rust" and "C"
All other ABIs are left unstable for now.

cc #64926
2022-03-26 18:23:54 -04:00
bors
c74925438c Auto merge of #95149 - cjgillot:once-diag, r=estebank
Remove `Session::one_time_diagnostic`

This is untracked mutable state, which modified the behaviour of queries.
It was used for 2 things: some full-blown errors, but mostly for lint declaration notes ("the lint level is defined here" notes).

It is replaced by the diagnostic deduplication infra which already exists in the diagnostic emitter.
A new diagnostic level `OnceNote` is introduced specifically for lint notes, to deduplicate subdiagnostics.

As a drive-by, diagnostic emission takes a `&mut` to allow dropping the `SubDiagnostic`s.
2022-03-26 00:54:54 +00:00
Michael Howell
2a7837262f diagnostics: correct generic bounds with doubled colon
Fixes #95208
2022-03-25 13:57:05 -07:00
Michael Goulet
91ac9cf595 suggest wrapping single-expr blocks in square brackets 2022-03-24 21:40:20 -07:00
Noah Lev
86220d6e51 Fix rustfix panic on test
`run-rustfix` applies all suggestions regardless of their Applicability.
There's a flag, `rustfix-only-machine-applicable`, that does what it
says, but then the produced `.fixed` file would have invalid code from
the suggestions that weren't applied. So, I moved the cases of postfix
increment, in which case multiple suggestions are given, to the
`-notfixed` test, which does not run rustfix.

I also changed the Applicability to Unspecified since MaybeIncorrect
requires that the code be valid, even if it's incorrect.
2022-03-23 22:31:57 -07:00
Noah Lev
725cde42d5 Use multipart_suggestions
This records that the suggestions are mutually-exclusive (i.e., only one
should be applied).
2022-03-23 22:31:57 -07:00
Noah Lev
ef74796178 Change temporary variable name if it would conflict 2022-03-23 22:31:57 -07:00
Noah Lev
95960b7d54 Make standalone an enum 2022-03-23 22:31:57 -07:00
Noah Lev
4212835d99 Add heuristic to avoid treating x + +2 as increment 2022-03-23 22:31:57 -07:00
Noah Lev
29a5c363c7 Improve function names 2022-03-23 22:31:57 -07:00
Noah Lev
073010d425 Improve handling of tmp variable name conflicts 2022-03-23 22:31:57 -07:00
Noah Lev
62b8ea67b7 Emit both subexp and standalone sugg for postfix
This solves the TODO.
2022-03-23 22:31:57 -07:00
Noah Lev
7287f929b9 Emit structured suggestions for field accesses too 2022-03-23 22:31:57 -07:00
Noah Lev
67a9adbb54 Refactor, handle fields better, add field tests 2022-03-23 22:31:57 -07:00
Noah Lev
80e57e223e Reduce rightward drift 2022-03-23 22:31:57 -07:00
Noah Lev
d915606d50 Remove error recovery todos 2022-03-23 22:31:57 -07:00
Noah Lev
c9cc43aa66 Move increment checks to improve errors 2022-03-23 22:31:57 -07:00
Camelid
5d9cd4b851 Suggest i += 1 when we see i++ or ++i 2022-03-23 22:31:57 -07:00
Dylan DPC
0254928213
Rollup merge of #95212 - TaKO8Ki:replace-this-clone-with-this-create-snapshot-for-diagnostic, r=Dylan-DPC
Replace `this.clone()` with `this.create_snapshot_for_diagnostic()`

Use [`create_snapshot_for_diagnostic`](cd11905716/compiler/rustc_parse/src/parser/diagnostics.rs (L214-L223)) I implemented in https://github.com/rust-lang/rust/pull/94731 instead of `this.clone()` to avoid duplicate errors about unclosed delims being emitted when the `Parser` is dropped.
2022-03-23 03:05:32 +01:00
bors
5f37001055 Auto merge of #95215 - Dylan-DPC:rollup-l9f9t7l, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #95188 ([`macro-metavar-expr`] Fix generated tokens hygiene)
 - #95196 (rename LocalState::Uninitialized to Unallocated)
 - #95197 (Suggest constraining param for unary ops when missing trait impl)
 - #95200 (Cancel a not emitted error after parsing const generic args)
 - #95207 (update Termination trait docs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-03-22 19:06:04 +00:00
Takayuki Maeda
b86a1d1c07 replace this.clone() with this.create_snapshot_for_diagnostic() 2022-03-23 01:26:34 +09:00
bors
64137f0b15 Auto merge of #94693 - nnethercote:parser-inlining, r=petrochenkov
Inline some parser functions

Some crates that do a lot of complex declarative macro expansion spend a lot of time parsing (and reparsing) tokens. These commits inline some functions for some minor speed wins.

r? `@ghost`
2022-03-22 16:24:50 +00:00
Takayuki Maeda
62ded071d5 cancel a not emitted error after parsing const generic args 2022-03-22 16:06:56 +09:00
Nicholas Nethercote
f8f1d3f00b Split TokenCursor::{next,next_desugared} into inlined and non-inlined halves. 2022-03-22 11:05:54 +11:00
Nicholas Nethercote
4e700a023c Split Parser::bump_with into inlined and non-inlined halves.
The call site within `Parser::bump` is hot.

Also add an inline annotation to `Parser::next_tok`. It was already
being inlined by the compiler; this just makes sure that continues.
2022-03-22 11:01:53 +11:00
bors
051d1176b7 Auto merge of #95104 - compiler-errors:remove-ascription, r=davidtwco
suggest removing type ascription in bad parsing position

Not sure how to test this with the non-nightly suggestion. Didn't add a new UI test because it already manifests in an existing UI test.

Fixes #95014
2022-03-21 02:29:55 +00:00
Matthias Krüger
63da51db93
Rollup merge of #95135 - TaKO8Ki:fix-not-emitted-unmatched-angle-bracket-error, r=Dylan-DPC
Fix a not emitted unmatched angle bracket error

closes #95128
2022-03-20 20:42:45 +01:00
Camille GILLOT
056951d628 Take &mut Diagnostic in emit_diagnostic.
Taking a Diagnostic by move would break the usual pattern
`diag.label(..).emit()`.
2022-03-20 20:36:08 +01:00
Takayuki Maeda
5c8aaedef6 fix a not emitted unmatched angle bracket error 2022-03-20 22:39:15 +09:00
Michael Goulet
3516a16eeb suggest removing type ascription in bad position 2022-03-18 21:22:26 -07:00
Takayuki Maeda
201a86046c use self.create_snapshot_for_diagnostic instead of self.clone() 2022-03-18 16:56:43 +09:00
Dylan DPC
270a41c33e
Rollup merge of #94960 - codehorseman:master, r=oli-obk
Fix many spelling mistakes

Signed-off-by: codehorseman <cricis@yeah.net>
2022-03-17 22:55:05 +01:00
Dylan DPC
5eb3433ed5
Rollup merge of #94731 - TaKO8Ki:const-generic-expr-recovery, r=davidtwco,oli-obk
Suggest adding `{ .. }` around a const function call with arguments

closes #91020
2022-03-17 22:55:04 +01:00
Dylan DPC
7e1415ea80
Rollup merge of #93222 - mark-i-m:errorreported, r=oli-obk
Make ErrorReported impossible to construct outside `rustc_errors`

There are a few places were we have to construct it, though, and a few
places that are more invasive to change. To do this, we create a
constructor with a long obvious name.

cc #69426 `@varkor` `@eddyb` `@estebank`

I actually didn't see that I was assigned to this issue until now...
2022-03-17 22:55:00 +01:00
Dylan DPC
c8133f6f5e
Rollup merge of #91133 - terrarier2111:unsafe-diagnostic, r=jackh726
Improve `unsafe` diagnostic

This fixes: https://github.com/rust-lang/rust/issues/90880
I didn't use the exact proposed messages though.
2022-03-17 22:54:59 +01:00
mark
bb8d4307eb rustc_error: make ErrorReported impossible to construct
There are a few places were we have to construct it, though, and a few
places that are more invasive to change. To do this, we create a
constructor with a long obvious name.
2022-03-16 10:35:24 -05:00
codehorseman
01dbfb3eb2 resolve the conflict in compiler/rustc_session/src/parse.rs
Signed-off-by: codehorseman <cricis@yeah.net>
2022-03-16 20:12:30 +08:00
David Tolnay
f427698c03
Parse inner attributes on inline const block 2022-03-15 17:56:59 -07:00
Takayuki Maeda
896b113ec3 use format_args_capture in some parts of rustc_parse 2022-03-15 19:17:29 +09:00
bors
95561b336c Auto merge of #94584 - pnkfelix:inject-use-suggestion-sites, r=ekuber
More robust fallback for `use` suggestion

Our old way to suggest where to add `use`s would first look for pre-existing `use`s in the relevant crate/module, and if there are *no* uses, it would fallback on trying to use another item as the basis for the suggestion.

But this was fragile, as illustrated in issue #87613

This PR instead identifies span of the first token after any inner attributes, and uses *that* as the fallback for the `use` suggestion.

Fix #87613
2022-03-15 03:56:33 +00:00
bors
f103b2969b Auto merge of #94865 - notriddle:notriddle/single-colon-path-not-const-generics, r=cjgillot
diagnostics: single colon within `<>` probably, not type ascription

Fixes #94812
2022-03-12 19:10:33 +00:00
Michael Howell
26e299a4a7 Use consistent prose for ::
Co-authored-by: Camille Gillot <gillot.camille@gmail.com>
2022-03-12 08:20:36 -07:00
Michael Howell
7e323370b3 diagnostics: single colon within <> probably, not type ascription
Fixes #94812
2022-03-11 15:35:18 -07:00
Dylan DPC
298c9a0e14
Rollup merge of #94839 - TaKO8Ki:suggest-using-double-colon-for-struct-field-type, r=cjgillot
Suggest using double colon when a struct field type include single colon

#92685
2022-03-11 20:29:47 +01:00
Takayuki Maeda
813f00dd4f fix a suggestion message 2022-03-11 21:26:06 +09:00
Takayuki Maeda
bdc3177868 suggest using double colon when using single colon in struct field type path 2022-03-11 16:15:57 +09:00
Takayuki Maeda
9a6532276e replace self.clone() with self.create_snapshot_for_diagnostic() 2022-03-10 22:11:00 +09:00
Takayuki Maeda
2db8236857 add doc comments 2022-03-10 19:34:42 +09:00
Takayuki Maeda
3ded25204b implement SnapshotParser struct 2022-03-09 23:13:04 +09:00
Takayuki Maeda
192acb4b98 take over unclosed_delims 2022-03-09 16:04:14 +09:00
Takayuki Maeda
3514741358 remove an unnecessary comment 2022-03-09 14:10:34 +09:00
Takayuki Maeda
a34015c0d0 implement and use diagnostic_snapshot 2022-03-09 13:48:40 +09:00
Takayuki Maeda
527b1f3c2f initialize unclosed_delims field 2022-03-09 12:59:46 +09:00
Takayuki Maeda
529fd2da89 suggest adding { .. } around a const function with arguments 2022-03-08 17:07:35 +09:00
Michael Howell
fbd4cfa0f8 diagnostics: only talk about Cargo.toml if running under Cargo
Fixes #94646
2022-03-07 10:54:17 -07:00
bors
ad0d1d71d3 Auto merge of #90076 - jackh726:wherethewhere, r=nikomatsakis
Change location of where clause on GATs

Closes #89122

~Blocked on lang FCP~

r? `@nikomatsakis`
2022-03-06 07:22:09 +00:00
Jack Huey
c20b4f5584 Change syntax for TyAlias where clauses 2022-03-05 13:13:45 -05:00
Ralf Jung
e887e6647c
Rollup merge of #94633 - TaKO8Ki:suggest-removing-semicolon-after-derive-attribute, r=cjgillot
Suggest removing a semicolon after derive attributes

closes #93942
2022-03-05 12:53:16 -05:00
Takayuki Maeda
47d91bc9e6 suggest removing a semicolon after derive attributes
use current token span
2022-03-06 01:28:35 +09:00
Esteban Kuber
004f2ed219 Do not recover from Ty? in macro parsing
Follow up to #92746. Address #94510.
2022-03-04 02:03:55 +00:00
Felix S. Klock II
d37da1e332 Adjusted diagnostic output so that if there is no use in a item sequence,
then we just suggest the first legal position where you could inject a use.

To do this, I added `inject_use_span` field to `ModSpans`, and populate it in
parser (it is the span of the first token found after inner attributes, if any).
Then I rewrote the use-suggestion code to utilize it, and threw out some stuff
that is now unnecessary with this in place. (I think the result is easier to
understand.)

Then I added a test of issue 87613.
2022-03-03 18:58:37 -05:00
Felix S. Klock II
b82795244e Associate multiple with a crate too. 2022-03-03 18:45:25 -05:00
Felix S. Klock II
e9035f7bef refactor: prepare to associate multiple spans with a module. 2022-03-03 14:38:50 -05:00
mark
e489a94dee rename ErrorReported -> ErrorGuaranteed 2022-03-02 09:45:25 -06:00
Matthias Krüger
5be38d2bb3
Rollup merge of #94445 - c410-f3r:more-let-chains, r=cjgillot
4 - Make more use of `let_chains`

Continuation of #94376.

cc #53667
2022-02-28 20:05:17 +01:00
Esteban Kuber
f42b4f595e Tweak diagnostics
* Recover from invalid `'label: ` before block.
* Make suggestion to enclose statements in a block multipart.
* Point at `match`, `while`, `loop` and `unsafe` keywords when failing
  to parse their expression.
* Do not suggest `{ ; }`.
* Do not suggest `|` when very unlikely to be what was wanted (in `let`
  statements).
2022-02-28 18:22:45 +00:00
Caio
e3e902bb06 4 - Make more use of let_chains
Continuation of #94376.

cc #53667
2022-02-28 07:49:56 -03:00
Michael Goulet
6b52ac240a Suggest {} around more bad const generic exprs 2022-02-25 17:16:58 -08:00