Michael Goulet
28d82ddfc2
Fix typo
2022-11-05 19:33:12 -07:00
yukang
4b77e730b5
fake a base to suppress later extra error message
2022-11-04 19:32:32 +08:00
yukang
1e25882944
fix #102806 , suggest use .. to fill in the rest of the fields of Struct
2022-11-04 10:35:36 +08:00
Nilstrieb
29e50e8d35
Gate some recovery behind a flag
...
Mainly in `expr.rs`
2022-10-28 22:07:36 +02:00
Nilstrieb
ed14202864
Add flag to forbid recovery in the parser
2022-10-25 22:06:53 +02:00
Yuki Okushi
11d11e3415
Rollup merge of #103333 - chenyukang:yukang/fix-103143, r=wesleywiser
...
Fix assertion failed for break_last_token and trailing token
Fixes #103143
2022-10-25 08:01:27 +09:00
Dylan DPC
e029c1fd43
Rollup merge of #101293 - compiler-errors:lt-is-actually-char, r=estebank
...
Recover when unclosed char literal is parsed as a lifetime in some positions
Fixes #101278
2022-10-23 15:20:16 +05:30
Michael Goulet
3d7b1f0d18
Don't erroneously deny semicolons after closure expr within parentheses in a macro
2022-10-22 06:59:49 +00:00
Michael Goulet
0270b50eb0
Recover unclosed char literal being parsed as lifetime
2022-10-22 06:57:12 +00:00
yukang
2414357374
fix assertion failed for break_last_token and trailing token
2022-10-20 20:16:27 +08:00
yukang
0af255a5aa
Fix the bug of next_point in span
2022-10-18 02:59:38 +08:00
Michael Goulet
85a726e754
Remove expr_parentheses_needed from ParseSess
2022-09-30 01:39:20 +00:00
Xiretza
d7c64574e0
Implement IntoDiagnosticArg for rustc_ast::token::Token(Kind)
2022-09-27 20:29:19 +02:00
Xiretza
37fdcb4b36
Don't unnecessarily stringify paths in diagnostics
2022-09-27 20:29:19 +02:00
Xiretza
00f95468c4
Migrate even more diagnostics in rustc_parse to diagnostic structs
2022-09-27 20:29:19 +02:00
Xiretza
e1b1d7b029
Migrate more rustc_parse diagnostics to diagnostic structs
2022-09-27 20:29:18 +02:00
Xiretza
e56d6a68db
Move rustc_parse diagnostic structs to separate module
2022-09-27 20:29:18 +02:00
Xiretza
6ae7a30927
Migrate "invalid literal suffix" diagnostic to diagnostic structs
2022-09-27 20:29:18 +02:00
Xiretza
ab7c7dc7ce
Migrate more diagnostics in rustc_parse to diagnostic structs
2022-09-27 20:29:18 +02:00
Jhonny Bill Mena
19b348fed4
UPDATE - rename DiagnosticHandler trait to IntoDiagnostic
2022-09-21 11:39:52 -04:00
Jhonny Bill Mena
5b8152807c
UPDATE - move SessionDiagnostic from rustc_session to rustc_errors
2022-09-21 11:39:52 -04:00
yukang
484b612909
use subdiagnostic for logical negation, bitwise not
2022-09-16 14:41:42 +08:00
yukang
f43562b95b
more tweak on diagnostic messages
2022-09-15 22:39:16 +08:00
Matthias Krüger
c365ce3ffd
Rollup merge of #101502 - TaKO8Ki:do-not-suggest-semicolon-for-macro-without-exclamation-mark, r=wesleywiser
...
Do not suggest a semicolon for a macro without `!`
Fixes a regression in #101490
2022-09-07 21:48:15 +02:00
Takayuki Maeda
7ac124803f
do not suggest a semicolon for a macro without !
2022-09-07 03:59:47 +09:00
Jhonny Bill Mena
321e60bf34
UPDATE - into_diagnostic to take a Handler instead of a ParseSess
...
Suggested by the team in this Zulip Topic https://rust-lang.zulipchat.com/#narrow/stream/336883-i18n/topic/.23100717.20SessionDiagnostic.20on.20Handler
Handler already has almost all the capabilities of ParseSess when it comes to diagnostic emission, in this migration we only needed to add the ability to access source_map from the emitter in order to get a Snippet and the start_point. Not sure if this is the best way to address this gap
2022-09-05 02:18:45 -04:00
bors
eac6c33bc6
Auto merge of #100869 - nnethercote:replace-ThinVec, r=spastorino
...
Replace `rustc_data_structures::thin_vec::ThinVec` with `thin_vec::ThinVec`
`rustc_data_structures::thin_vec::ThinVec` looks like this:
```
pub struct ThinVec<T>(Option<Box<Vec<T>>>);
```
It's just a zero word if the vector is empty, but requires two
allocations if it is non-empty. So it's only usable in cases where the
vector is empty most of the time.
This commit removes it in favour of `thin_vec::ThinVec`, which is also
word-sized, but stores the length and capacity in the same allocation as
the elements. It's good in a wider variety of situation, e.g. in enum
variants where the vector is usually/always non-empty.
The commit also:
- Sorts some `Cargo.toml` dependency lists, to make additions easier.
- Sorts some `use` item lists, to make additions easier.
- Changes `clean_trait_ref_with_bindings` to take a
`ThinVec<TypeBinding>` rather than a `&[TypeBinding]`, because this
avoid some unnecessary allocations.
r? `@spastorino`
2022-09-01 08:01:06 +00:00
Dezhi Wu
b1430fb7ca
Fix a bunch of typo
...
This PR will fix some typos detected by [typos].
I only picked the ones I was sure were spelling errors to fix, mostly in
the comments.
[typos]: https://github.com/crate-ci/typos
2022-08-31 18:24:55 +08:00
Nilstrieb
d1ef8180f9
Revert let_chains stabilization
...
This reverts commit 3266460749
.
This is the revert against master, the beta revert was already done in #100538 .
2022-08-29 19:34:11 +02:00
Nicholas Nethercote
c768617f6f
Improve parse_dot_or_call_expr_with
.
...
Avoid all the extra work in the very common case where `attrs` is empty.
2022-08-29 15:42:16 +10:00
Yuki Okushi
f4550a6edf
Rollup merge of #99332 - jyn514:stabilize-label-break-value, r=petrochenkov
...
Stabilize `#![feature(label_break_value)]`
See the stabilization report in https://github.com/rust-lang/rust/issues/48594#issuecomment-1186213313 .
2022-08-25 08:50:54 +09:00
Joshua Nelson
31e39446ec
Stabilize #![feature(label_break_value)]
...
# Stabilization proposal
The feature was implemented in https://github.com/rust-lang/rust/pull/50045 by est31 and has been in nightly since 2018-05-16 (over 4 years now).
There are [no open issues][issue-label] other than the tracking issue. There is a strong consensus that `break` is the right keyword and we should not use `return`.
There have been several concerns raised about this feature on the tracking issue (other than the one about tests, which has been fixed, and an interaction with try blocks, which has been fixed).
1. nrc's original comment about cost-benefit analysis: https://github.com/rust-lang/rust/issues/48594#issuecomment-422235234
2. joshtriplett's comments about seeing use cases: https://github.com/rust-lang/rust/issues/48594#issuecomment-422281176
3. withoutboats's comments that Rust does not need more control flow constructs: https://github.com/rust-lang/rust/issues/48594#issuecomment-450050630
Many different examples of code that's simpler using this feature have been provided:
- A lexer by rpjohnst which must repeat code without label-break-value: https://github.com/rust-lang/rust/issues/48594#issuecomment-422502014
- A snippet by SergioBenitez which avoids using a new function and adding several new return points to a function: https://github.com/rust-lang/rust/issues/48594#issuecomment-427628251 . This particular case would also work if `try` blocks were stabilized (at the cost of making the code harder to optimize).
- Several examples by JohnBSmith: https://github.com/rust-lang/rust/issues/48594#issuecomment-434651395
- Several examples by Centril: https://github.com/rust-lang/rust/issues/48594#issuecomment-440154733
- An example by petrochenkov where this is used in the compiler itself to avoid duplicating error checking code: https://github.com/rust-lang/rust/issues/48594#issuecomment-443557569
- Amanieu recently provided another example related to complex conditions, where try blocks would not have helped: https://github.com/rust-lang/rust/issues/48594#issuecomment-1184213006
Additionally, petrochenkov notes that this is strictly more powerful than labelled loops due to macros which accidentally exit a loop instead of being consumed by the macro matchers: https://github.com/rust-lang/rust/issues/48594#issuecomment-450246249
nrc later resolved their concern, mostly because of the aforementioned macro problems.
joshtriplett suggested that macros could be able to generate IR directly
(https://github.com/rust-lang/rust/issues/48594#issuecomment-451685983 ) but there are no open RFCs,
and the design space seems rather speculative.
joshtriplett later resolved his concerns, due to a symmetry between this feature and existing labelled break: https://github.com/rust-lang/rust/issues/48594#issuecomment-632960804
withoutboats has regrettably left the language team.
joshtriplett later posted that the lang team would consider starting an FCP given a stabilization report: https://github.com/rust-lang/rust/issues/48594#issuecomment-1111269353
[issue-label]: https://github.com/rust-lang/rust/issues?q=is%3Aissue+is%3Aopen+label%3AF-label_break_value+
## Report
+ Feature gate:
- d695a497bb/src/test/ui/feature-gates/feature-gate-label_break_value.rs
+ Diagnostics:
- 6b2d3d5f3c/compiler/rustc_parse/src/parser/diagnostics.rs (L2629)
- f65bf0b2bb/compiler/rustc_resolve/src/diagnostics.rs (L749)
- f65bf0b2bb/compiler/rustc_resolve/src/diagnostics.rs (L1001)
- 111df9e6ed/compiler/rustc_passes/src/loops.rs (L254)
- d695a497bb/compiler/rustc_parse/src/parser/expr.rs (L2079)
- d695a497bb/compiler/rustc_parse/src/parser/expr.rs (L1569)
+ Tests:
- https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_continue.rs
- https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_unlabeled_break.rs
- https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_illegal_uses.rs
- https://github.com/rust-lang/rust/blob/master/src/test/ui/lint/unused_labels.rs
- https://github.com/rust-lang/rust/blob/master/src/test/ui/run-pass/for-loop-while/label_break_value.rs
## Interactions with other features
Labels follow the hygiene of local variables.
label-break-value is permitted within `try` blocks:
```rust
let _: Result<(), ()> = try {
'foo: {
Err(())?;
break 'foo;
}
};
```
label-break-value is disallowed within closures, generators, and async blocks:
```rust
'a: {
|| break 'a
//~^ ERROR use of unreachable label `'a`
//~| ERROR `break` inside of a closure
}
```
label-break-value is disallowed on [_BlockExpression_]; it can only occur as a [_LoopExpression_]:
```rust
fn labeled_match() {
match false 'b: { //~ ERROR block label not supported here
_ => {}
}
}
macro_rules! m {
($b:block) => {
'lab: $b; //~ ERROR cannot use a `block` macro fragment here
unsafe $b; //~ ERROR cannot use a `block` macro fragment here
|x: u8| -> () $b; //~ ERROR cannot use a `block` macro fragment here
}
}
fn foo() {
m!({});
}
```
[_BlockExpression_]: https://doc.rust-lang.org/nightly/reference/expressions/block-expr.html
[_LoopExpression_]: https://doc.rust-lang.org/nightly/reference/expressions/loop-expr.html
2022-08-23 21:14:12 -05:00
Dylan DPC
75b7089d1e
Rollup merge of #100713 - Xiretza:parser-expr-session-diagnostics, r=estebank
...
Convert diagnostics in parser/expr to SessionDiagnostic
This migrates all the easy cases in `rustc_parse::parser::expr` to `SessionDiagnostic`s, I've left things such as `multipart_suggestion`s out for now in the hopes of a derive API being developed soon.
2022-08-22 20:34:14 +05:30
Nicholas Nethercote
619b8abaa6
Use AttrVec
in more places.
...
In some places we use `Vec<Attribute>` and some places we use
`ThinVec<Attribute>` (a.k.a. `AttrVec`). This results in various points
where we have to convert between `Vec` and `ThinVec`.
This commit changes the places that use `Vec<Attribute>` to use
`AttrVec`. A lot of this is mechanical and boring, but there are
some interesting parts:
- It adds a few new methods to `ThinVec`.
- It implements `MapInPlace` for `ThinVec`, and introduces a macro to
avoid the repetition of this trait for `Vec`, `SmallVec`, and
`ThinVec`.
Overall, it makes the code a little nicer, and has little effect on
performance. But it is a precursor to removing
`rustc_data_structures::thin_vec::ThinVec` and replacing it with
`thin_vec::ThinVec`, which is implemented more efficiently.
2022-08-22 07:35:33 +10:00
Xiretza
ffcaa0dee2
Migrate diagnostics in parser/expr to SessionDiagnostic
2022-08-21 14:54:05 +02:00
bors
dd01122b5c
Auto merge of #100564 - nnethercote:box-ast-MacCall, r=spastorino
...
Box the `MacCall` in various types.
r? `@spastorino`
2022-08-20 10:26:54 +00:00
Nicholas Nethercote
eafd0dfd05
Box the MacCall
in various types.
2022-08-17 08:10:56 +10:00
Nicholas Nethercote
5d3cc1713a
Rename some things related to literals.
...
- Rename `ast::Lit::token` as `ast::Lit::token_lit`, because its type is
`token::Lit`, which is not a token. (This has been confusing me for a
long time.)
reasonable because we have an `ast::token::Lit` inside an `ast::Lit`.
- Rename `LitKind::{from,to}_lit_token` as
`LitKind::{from,to}_token_lit`, to match the above change and
`token::Lit`.
2022-08-16 13:41:34 +10:00
Matthias Krüger
e14d12cb66
Rollup merge of #100559 - nnethercote:parser-simplifications, r=compiler-errors
...
Parser simplifications
Best reviewed one commit at a time.
r? ``@compiler-errors``
2022-08-15 20:11:38 +02:00
Nicholas Nethercote
2ef0479568
Simplify attribute handling in parse_bottom_expr
.
...
`Parser::parse_bottom_expr` currently constructs an empty `attrs` and
then passes it to a large number of other functions. This makes the code
harder to read than it should be, because it's not clear that many
`attrs` arguments are always empty.
This commit removes `attrs` and the passing, simplifying a lot of
functions. The commit also renames `Parser::mk_expr` (which takes an
`attrs` argument) as `mk_expr_with_attrs`, and introduces a new
`mk_expr` which creates an expression with no attributes, which is the
more common case.
2022-08-15 13:29:28 +10:00
Nicholas Nethercote
1e8497351d
Streamline parse_path_start_expr
.
...
Let-chaining avoids some code duplication.
2022-08-15 09:51:11 +10:00
Michael Goulet
237cbe91a8
Adjust span of closure param
2022-08-12 15:18:40 +00:00
Dylan DPC
b5f5bdce87
Rollup merge of #100351 - compiler-errors:diagnostic-convention, r=fee1-dead
...
Use `&mut Diagnostic` instead of `&mut DiagnosticBuilder` unless needed
This seems to be the established convention (02ff9e0
) when `DiagnosticBuilder` was first added. I am guilty of introducing some of these.
2022-08-11 22:47:03 +05:30
Camille GILLOT
9701845287
Do not consider method call receiver as an argument in AST.
2022-08-10 18:34:54 +02:00
Michael Goulet
a2b6744af0
Use &mut Diagnostic instead of &mut DiagnosticBuilder unless needed
2022-08-10 03:45:42 +00:00
Takayuki Maeda
6d85bb9535
suggest a missing semicolon before an array
2022-08-10 02:29:28 +09:00
Michael Goulet
6be7a87f9c
Use expr parse restrictions for let expr parsing
2022-08-01 01:13:16 +00:00
Michael Goulet
7cdd937bb8
dont call type ascription 'cast'
2022-07-29 07:02:52 +00:00
Eric Huss
2ce2870749
Remove let-chain close brace check.
2022-07-25 11:19:29 -07:00
Caio
3266460749
Stabilize let_chains
2022-07-16 20:17:58 -03:00