bors
e64f1110c0
Auto merge of #103345 - Nilstrieb:diag-flat, r=compiler-errors
...
Flatten diagnostic slug modules
This makes it easier to grep for the slugs in the code.
See https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Localization.20infra.20interferes.20with.20grepping.20for.20error for more discussion about it.
This was mostly done with a few regexes and a bunch of manual work. This also exposes a pretty annoying inconsistency for the extra labels. Some of the extra labels are defined as additional properties in the fluent message (which makes them not prefixed with the crate name) and some of them are new fluent messages themselves (which makes them prefixed with the crate name). I don't know whether we want to clean this up at some point but it's useful to know.
r? `@davidtwco`
2022-10-23 09:06:39 +00:00
Nilstrieb
c65ebae221
Migrate all diagnostics
2022-10-23 10:09:44 +02:00
Matthias Krüger
b656f5e9a6
Rollup merge of #103354 - clubby789:escape-string-literals, r=compiler-errors
...
Escape string literals when fixing overlong char literal
Fixes #103323
````@rustbot```` label +A-diagnostics +A-suggestion-diagnostics
2022-10-23 08:14:31 +02:00
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
clubby789
ed40d46159
Properly escape quotes when suggesting switching between char/string literals
2022-10-22 02:37:15 +01:00
Dylan DPC
0a0e9f73af
Rollup merge of #102922 - kper:bugfix/102902-filtering-json, r=oli-obk
...
Filtering spans when emitting json
According to the issue #102902 , we shouldn't emit spans which have an empty span and no suggested replacement.
2022-10-21 17:29:58 +05:30
yukang
2414357374
fix assertion failed for break_last_token and trailing token
2022-10-20 20:16:27 +08:00
Kevin Per
28d0312b7d
Implement assertions and fixes to not emit empty spans without suggestions
2022-10-20 08:25:31 +00:00
yukang
0af255a5aa
Fix the bug of next_point in span
2022-10-18 02:59:38 +08:00
Rageking8
7122abaddf
more dupe word typos
2022-10-14 12:57:56 +08:00
Dylan DPC
a9a5529eac
Rollup merge of #102927 - compiler-errors:let, r=davidtwco
...
Fix `let` keyword removal suggestion in structs
(1.) Fixes a bug where, given this code:
```rust
struct Foo {
let x: i32,
}
```
We were parsing the field name as `let` instead of `x`, which causes issues later on in the type-checking phase.
(2.) Also, suggestions for `let: i32` as a field regressed, displaying this extra `help:` which is removed by this PR
```
help: remove the let, the `let` keyword is not allowed in struct field definitions
|
2 - let: i32,
2 + : i32,
```
(3.) Makes the suggestion text a bit more succinct, since we don't need to re-explain that `let` is not allowed in this position (since it's in a note that follows). This causes the suggestion to render inline as well.
cc `@gimbles,` this addresses a few nits I mentioned in your PR.
2022-10-12 22:13:26 +05:30
Nilstrieb
7bfef19844
Use tidy-alphabetical
in the compiler
2022-10-12 17:49:10 +05:30
Michael Goulet
f9d3c83526
Fix let removal suggestion in struct
2022-10-11 17:35:50 +00:00
bors
518263d889
Auto merge of #102896 - matthiaskrgr:rollup-jg5xawz, r=matthiaskrgr
...
Rollup of 6 pull requests
Successful merges:
- #101360 (Point out incompatible closure bounds)
- #101789 (`let`'s not needed in struct field definitions)
- #102846 (update to syn-1.0.102)
- #102871 (rustdoc: clean up overly complex `.trait-impl` CSS selectors)
- #102876 (suggest candidates for unresolved import)
- #102888 (Improve rustdoc-gui search-color test)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
2022-10-11 00:36:26 +00:00
Matthias Krüger
01a2246000
Rollup merge of #101789 - gimbles:let, r=estebank
...
`let`'s not needed in struct field definitions
Fixes #101683
2022-10-10 20:47:32 +02:00
Guillaume Gomez
adc24d1b5e
Fix compiler docs
2022-10-10 18:28:29 +02:00
gimbles
6071b4b8a6
let
is not allowed in struct field definitions
...
Co-authored-by: jyn514 <jyn514@gmail.com>
Co-authored-by: Esteban Kuber <estebank@users.noreply.github.com>
2022-10-10 16:53:13 +05:30
Yuki Okushi
303ebd5b04
Rollup merge of #102345 - chenyukang:fix-102182-impl-trait, r=estebank
...
Recover from impl Trait in type param bound
Fixes #102182
r? ``@estebank``
2022-10-10 10:23:04 +09:00
Urgau
5ae73634dc
Stabilize half_open_range_patterns
2022-10-08 11:00:13 +02:00
yukang
7b2f04a2b3
fix #102182 , recover from impl Trait in type param bound
2022-10-08 06:47:26 +08:00
bors
0152393048
Auto merge of #99324 - reez12g:issue-99144, r=jyn514
...
Enable doctests in compiler/ crates
Helps with https://github.com/rust-lang/rust/issues/99144
2022-10-06 03:01:57 +00:00
Nicholas Nethercote
4e5ddf1adf
Invert is_top_level
to avoid negation.
2022-10-03 11:42:29 +11:00
Nicholas Nethercote
a822d08bd1
Remove TokenStreamBuilder
.
...
It's now only used in one function. Also, the "should we glue the
tokens?" check is only necessary when pushing a `TokenTree::Token`, not
when pushing a `TokenTree::Delimited`.
As part of this, we now do the "should we glue the tokens?" check
immediately, which avoids having look back at the previous token. It
also puts all the logic dealing with token gluing in a single place.
2022-10-03 11:42:29 +11:00
Nicholas Nethercote
8d0754d602
Inline and remove parse_token_tree_non_delim_non_eof
.
...
It has a single call site.
2022-10-03 11:42:29 +11:00
Nicholas Nethercote
ce7676829e
Merge parse_token_trees_until_close_delim
and parse_all_token_trees
.
...
Because they're very similar, and this will allow some follow-up
changes.
2022-10-03 11:42:29 +11:00
Nicholas Nethercote
9de9cf19d7
Add comments to TokenCursor::desugar
.
...
It took me some time to work out what this code was doing.
2022-10-03 11:42:29 +11:00
Matthias Krüger
cc009bc536
Rollup merge of #102500 - compiler-errors:parse-sess-cleanup, r=cjgillot
...
Remove `expr_parentheses_needed` from `ParseSess`
Not sure why this method needed to exist on `ParseSess`, but we can achieve the same behavior by just inlining it everywhere.
2022-10-01 16:45:05 +02:00
Maybe Waffle
d86f9cd464
Replace some bool
params with an enum
2022-10-01 10:13:02 +00:00
Maybe Waffle
38b0865248
Recover wrong cased keywords starting functions
2022-10-01 10:08:53 +00:00
Maybe Waffle
3694429d09
recover wrong-cased use
s (Use
, USE
, etc)
2022-10-01 10:07:47 +00:00
Matthias Krüger
eaf1c7a0da
Rollup merge of #102493 - nnethercote:improve-size-assertions-some-more, r=lqd
...
Group together more size assertions.
Also add a few more assertions for some relevant token-related types.
And fix an erroneous comment in `rustc_errors`.
r? `@lqd`
2022-09-30 23:38:27 +02:00
Nicholas Nethercote
5ab68a82d5
Group together more size assertions.
...
Also add a few more assertions for some relevant token-related types.
And fix an erroneous comment in `rustc_errors`.
2022-10-01 07:30:23 +10:00
Matthias Krüger
6906e64c30
Rollup merge of #102350 - TaKO8Ki:incomplete-fn-in-struct-definition, r=fee1-dead
...
Improve errors for incomplete functions in struct definitions
Given the following code:
```rust
fn main() {}
struct Foo {
fn
}
```
[playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=29139f870511f6918324be5ddc26c345 )
The current output is:
```
Compiling playground v0.0.1 (/playground)
error: functions are not allowed in struct definitions
--> src/main.rs:4:5
|
4 | fn
| ^^
|
= help: unlike in C++, Java, and C#, functions are declared in `impl` blocks
= help: see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information
error: could not compile `playground` due to previous error
```
In this case, rustc should suggest escaping `fn` to use it as an identifier.
2022-09-30 10:22:37 +02:00
Michael Goulet
85a726e754
Remove expr_parentheses_needed from ParseSess
2022-09-30 01:39:20 +00:00
reez12g
9a4c5abe45
Remove from compiler/ crates
2022-09-29 16:49:04 +09:00
Rageking8
2ee2ffa9a7
improve E0585 help
2022-09-29 00:34:31 +08:00
bors
09ae7846a2
Auto merge of #101619 - Xiretza:rustc_parse-session-diagnostics, r=davidtwco
...
Migrate more of rustc_parse to SessionDiagnostic
Still far from complete, but I thought I'd add a checkpoint here because rebasing was starting to get annoying.
2022-09-28 11:11:42 +00:00
bors
6201eabde8
Auto merge of #102302 - nnethercote:more-lexer-improvements, r=matklad
...
More lexer improvements
A follow-up to #99884 .
r? `@matklad`
2022-09-28 08:14:04 +00:00
Nicholas Nethercote
d0a26acb2a
Address review comments.
2022-09-28 11:15:23 +10:00
Matthias Krüger
8b635cba1d
Rollup merge of #102284 - compiler-errors:missing-type-in-raw-ptr, r=davidtwco
...
Structured suggestion for missing `mut`/`const` in raw pointer
Fixes #102261
2022-09-27 21:42:23 +02: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
caefac034e
Document use of Symbol::to_string()
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
760c4352d6
Migrate "struct literal body without path" error to diagnostic struct
2022-09-27 20:29:19 +02:00
Xiretza
ba10f2c0f2
Migrate "expected semicolon" diagnostics to diagnostic structs
2022-09-27 20:29:19 +02:00
Xiretza
7507ee29fc
Migrate "expected identifier" diagnostics to diagnostic structs
2022-09-27 20:29:19 +02:00
Xiretza
21b5194a3a
Rework "inner attribute not permitted" errors
2022-09-27 20:29:19 +02:00
Xiretza
4d0519a4e7
Remove error condition in parse_attribute
...
This function is only ever called when the `#` has already been
consumed, no need to produce an error message here.
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
Takayuki Maeda
d7b6bd8f13
improve errors for incomplete functions in struct definitions
2022-09-28 01:03:18 +09:00
Michael Goulet
594134d873
Structured suggestion for missing mut/const in pointer
2022-09-27 02:47:07 +00:00
Nicholas Nethercote
7f7e2165b1
Rename some variables.
...
These make the delimiter processing clearer.
2022-09-27 12:04:03 +10:00
Takayuki Maeda
4f44dee501
add a label to struct/enum/union ident name
2022-09-27 10:28:50 +09:00
Takayuki Maeda
e123a61297
create a new local var
2022-09-27 10:22:46 +09:00
Nicholas Nethercote
880ebb657a
Minor improvements.
...
Add some comments, and mark one path as unreachable.
2022-09-27 09:53:04 +10:00
Matthias Krüger
6f5e8c2ed4
Rollup merge of #102286 - compiler-errors:recover-semi-in-block-item, r=davidtwco
...
Recover some items that expect braces and don't take semicolons
Fixes #102262
2022-09-26 19:19:21 +02:00
Pietro Albini
3975d55d98
remove cfg(bootstrap)
2022-09-26 10:14:45 +02:00
bors
72f4923979
Auto merge of #102297 - fee1-dead-contrib:rollup-2np0cre, r=fee1-dead
...
Rollup of 5 pull requests
Successful merges:
- #102143 (Recover from struct nested in struct)
- #102178 (bootstrap: the backtrace feature is stable, no need to allow it any more)
- #102197 (Stabilize const `BTree{Map,Set}::new`)
- #102267 (Don't set RUSTC in the bootstrap build script)
- #102270 (Remove benches from `rustc_middle`)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
2022-09-26 05:27:43 +00:00
Nicholas Nethercote
fb4dba0a17
Inline and remove cook_lexer_token
.
...
This is a small performance win, alas.
2022-09-26 13:50:13 +10:00
Nicholas Nethercote
da84f0f4c3
Add rustc_lexer::TokenKind::Eof
.
...
For alignment with `rust_ast::TokenKind::Eof`. Plus it's a bit faster,
due to less `Option` manipulation in `StringReader::next_token`.
2022-09-26 13:48:08 +10:00
Nicholas Nethercote
ceb25d125f
Use less DRY in cook_lexer_token
.
...
This is a case where a small amount of repetition results in code that
is faster and easier to read.
2022-09-26 13:41:58 +10:00
Nicholas Nethercote
aa6bfaf04b
Make rustc_lexer::cursor::Cursor
public.
...
`Cursor` is currently hidden, and the main tokenization path uses
`rustc_lexer::first_token` which involves constructing a new `Cursor`
for every single token, which is weird. Also, `first_token` also can't
handle empty input, so callers have to check for that first.
This commit makes `Cursor` public, so `StringReader` can contain a
`Cursor`, which results in a simpler structure. The commit also changes
`StringReader::advance_token` so it returns an `Option<Token>`,
simplifying the the empty input case.
2022-09-26 13:36:35 +10:00
Nicholas Nethercote
33516ac09a
[ui] Rearrange StringReader
/TokenTreesReader
creation.
...
`TokenTreesReader` wraps a `StringReader`, but the `into_token_trees`
function obscures this. This commit moves to a more straightforward
control flow.
2022-09-26 13:35:46 +10:00
Nicholas Nethercote
33ba2776c9
Remove ast::Token::take
.
...
Instead of replacing `TokenTreesReader::token` in two steps, we can just
do it in one, which is both simpler and faster.
2022-09-26 13:35:43 +10:00
Nicholas Nethercote
5b2075e03d
Remove TokenTreesReader::bump
.
...
It's an unnecessary layer that obfuscates when I am looking for
optimizations.
2022-09-26 13:34:04 +10:00
Nicholas Nethercote
d7928a92e5
Clarify spacing computation.
...
The spacing computation is done in two parts. In the first part
`next_token` and `bump` use `Spacing::Alone` to mean "preceded by
whitespace" and `Spacing::Joint` to mean the opposite. In the second
part `parse_token_tree_other` then adjusts the `spacing` value to mean
the usual thing (i.e. "is the following token joinable punctuation?").
This shift in meaning is very confusing and it took me some time to
understand what was going on.
This commit changes the first part to use a bool, and adds some
comments, which makes things much clearer.
2022-09-26 13:21:26 +10:00
Nicholas Nethercote
9640d1c023
Move #!
checking.
...
Currently does the "is this a `#!` at the start of the file?" check for
every single token(!)
This commit moves it so it only happens once.
2022-09-26 13:19:14 +10:00
Michael Goulet
4d0d688a3c
Recover some items that expect braces and don't take semicolons
2022-09-25 22:34:25 +00:00
Nicholas Nethercote
14281e6147
Remove unnecessary spacing
assignment.
...
It has no useful effect.
2022-09-26 08:28:45 +10:00
Nicholas Nethercote
66e9b1149c
Rearrange TokenTreesReader::parse_token_tree
.
...
`parse_token_tree` is basically a match with four arms: `Eof`,
`OpenDelim`, `CloseDelim`, and "other". It has two call sites, and at
each call site one of the arms is unreachable. It's also not inlined.
This commit removes `parse_token_tree` by splitting it into four
functions and inlining them. This avoids some repeated conditional
tests and also some non-inlined function calls on the hot path.
2022-09-26 08:28:45 +10:00
Rageking8
a1062b9bdc
recover from struct nested in struct
2022-09-22 23:41:38 +08:00
Xiretza
ae56d2a118
Add missing code="" attributes to suggestion subdiagnostics
2022-09-22 17:25:50 +02:00
Jhonny Bill Mena
e52e2344dc
FIX - adopt new Diagnostic naming in newly migrated modules
...
FIX - ambiguous Diagnostic link in docs
UPDATE - rename diagnostic_items to IntoDiagnostic and AddToDiagnostic
[Gardening] FIX - formatting via `x fmt`
FIX - rebase conflicts. NOTE: Confirm wheather or not we want to handle TargetDataLayoutErrorsWrapper this way
DELETE - unneeded allow attributes in Handler method
FIX - broken test
FIX - Rebase conflict
UPDATE - rename residual _SessionDiagnostic and fix LintDiag link
2022-09-21 11:43:22 -04:00
Jhonny Bill Mena
5f91719f75
UPDATE - rename SessionSubdiagnostic macro to Subdiagnostic
...
Also renames:
- sym::AddSubdiagnostic to sym:: Subdiagnostic
- rustc_diagnostic_item = "AddSubdiagnostic" to rustc_diagnostic_item = "Subdiagnostic"
2022-09-21 11:39:53 -04:00
Jhonny Bill Mena
a3396b2070
UPDATE - rename DiagnosticHandler macro to Diagnostic
2022-09-21 11:39:53 -04: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
bors
b79b7d8b4e
Auto merge of #101846 - chenyukang:fix-101793, r=davidtwco
...
Fix the wording of help msg for bitwise not
Fixes #101793
2022-09-21 12:32:54 +00:00
Michael Howell
14b27cfd11
Rollup merge of #100250 - cjgillot:recover-token-stream, r=Aaron1011
...
Manually cleanup token stream when macro expansion aborts.
In case of syntax error in macro expansion, the expansion code can decide to stop processing anything. In that case, the token stream is malformed. This makes downstream users, like derive macros, ICE.
In this case, this PR manually cleans up the token stream by closing all currently open delimiters.
Fixes https://github.com/rust-lang/rust/issues/96818 .
Fixes https://github.com/rust-lang/rust/issues/80447 .
Fixes https://github.com/rust-lang/rust/issues/81920 .
Fixes https://github.com/rust-lang/rust/issues/91023 .
2022-09-20 10:12:56 -07:00
Dylan DPC
3ad81e0dd8
Rollup merge of #93628 - est31:stabilize_let_else, r=joshtriplett
...
Stabilize `let else`
🎉 **Stabilizes the `let else` feature, added by [RFC 3137](https://github.com/rust-lang/rfcs/pull/3137 ).** 🎉
Reference PR: https://github.com/rust-lang/reference/pull/1156
closes #87335 (`let else` tracking issue)
FCP: https://github.com/rust-lang/rust/pull/93628#issuecomment-1029383585
----------
## Stabilization report
### Summary
The feature allows refutable patterns in `let` statements if the expression is
followed by a diverging `else`:
```Rust
fn get_count_item(s: &str) -> (u64, &str) {
let mut it = s.split(' ');
let (Some(count_str), Some(item)) = (it.next(), it.next()) else {
panic!("Can't segment count item pair: '{s}'");
};
let Ok(count) = u64::from_str(count_str) else {
panic!("Can't parse integer: '{count_str}'");
};
(count, item)
}
assert_eq!(get_count_item("3 chairs"), (3, "chairs"));
```
### Differences from the RFC / Desugaring
Outside of desugaring I'm not aware of any differences between the implementation and the RFC. The chosen desugaring has been changed from the RFC's [original](https://rust-lang.github.io/rfcs/3137-let-else.html#reference-level-explanations ). You can read a detailed discussion of the implementation history of it in `@cormacrelf` 's [summary](https://github.com/rust-lang/rust/pull/93628#issuecomment-1041143670 ) in this thread, as well as the [followup](https://github.com/rust-lang/rust/pull/93628#issuecomment-1046598419 ). Since that followup, further changes have happened to the desugaring, in #98574 , #99518 , #99954 . The later changes were mostly about the drop order: On match, temporaries drop in the same order as they would for a `let` declaration. On mismatch, temporaries drop before the `else` block.
### Test cases
In chronological order as they were merged.
Added by df9a2e0687
(#87688 ):
* [`ui/pattern/usefulness/top-level-alternation.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/pattern/usefulness/top-level-alternation.rs ) to ensure the unreachable pattern lint visits patterns inside `let else`.
Added by 5b95df4bdc
(#87688 ):
* [`ui/let-else/let-else-bool-binop-init.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-bool-binop-init.rs ) to ensure that no lazy boolean expressions (using `&&` or `||`) are allowed in the expression, as the RFC mandates.
* [`ui/let-else/let-else-brace-before-else.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-brace-before-else.rs ) to ensure that no `}` directly preceding the `else` is allowed in the expression, as the RFC mandates.
* [`ui/let-else/let-else-check.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-check.rs ) to ensure that `#[allow(...)]` attributes added to the entire `let` statement apply for the `else` block.
* [`ui/let-else/let-else-irrefutable.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-irrefutable.rs ) to ensure that the `irrefutable_let_patterns` lint fires.
* [`ui/let-else/let-else-missing-semicolon.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-missing-semicolon.rs ) to ensure the presence of semicolons at the end of the `let` statement.
* [`ui/let-else/let-else-non-diverging.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-non-diverging.rs ) to ensure the `else` block diverges.
* [`ui/let-else/let-else-run-pass.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-run-pass.rs ) to ensure the feature works in some simple test case settings.
* [`ui/let-else/let-else-scope.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-scope.rs ) to ensure the bindings created by the outer `let` expression are not available in the `else` block of it.
Added by bf7c32a447
(#89965 ):
* [`ui/let-else/issue-89960.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/issue-89960.rs ) as a regression test for the ICE-on-error bug #89960 . Later in 102b9125e1
this got removed in favour of more comprehensive tests.
Added by 856541963c
(#89974 ):
* [`ui/let-else/let-else-if.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-if.rs ) to test for the improved error message that points out that `let else if` is not possible.
Added by 9b45713b6c
:
* [`ui/let-else/let-else-allow-unused.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-allow-unused.rs ) as a regression test for #89807 , to ensure that `#[allow(...)]` attributes added to the entire `let` statement apply for bindings created by the `let else` pattern.
Added by 61bcd8d307
(#89841 ):
* [`ui/let-else/let-else-non-copy.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-non-copy.rs ) to ensure that a copy is performed out of non-copy wrapper types. This mirrors `if let` behaviour. The test case bases on rustc internal changes originally meant for #89933 but then removed from the PR due to the error prior to the improvements of #89841 .
* [`ui/let-else/let-else-source-expr-nomove-pass.rs `](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-source-expr-nomove-pass.rs ) to ensure that while there is a move of the binding in the successful case, the `else` case can still access the non-matching value. This mirrors `if let` behaviour.
Added by 102b9125e1
(#89841 ):
* [`ui/let-else/let-else-ref-bindings.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-ref-bindings.rs ) and [`ui/let-else/let-else-ref-bindings-pass.rs `](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-ref-bindings-pass.rs ) to check `ref` and `ref mut` keywords in the pattern work correctly and error when needed.
Added by 2715c5f984
(#89841 ):
* Match ergonomic tests adapted from the `rfc2005` test suite.
Added by fec8a507a2
(#89841 ):
* [`ui/let-else/let-else-deref-coercion-annotated.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-deref-coercion-annotated.rs ) and [`ui/let-else/let-else-deref-coercion.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-deref-coercion.rs ) to check deref coercions.
#### Added since this stabilization report was originally written (2022-02-09)
Added by 76ea566677
(#94211 ):
* [`ui/let-else/let-else-destructuring.rs`](https://github.com/rust-lang/rust/blob/1.63.0/src/test/ui/let-else/let-else-destructuring.rs ) to give a nice error message if an user tries to do an assignment with a (possibly refutable) pattern and an `else` block, like asked for in #93995 .
Added by e7730dcb7e
(#94208 ):
* [`ui/let-else/let-else-allow-in-expr.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-allow-in-expr.rs ) to test whether `#[allow(unused_variables)]` works in the expr, as well as its non presence, as well as putting it on the entire `let else` *affects* the expr, too. This was adding a missing test as pointed out by the stabilization report.
* Expansion of `ui/let-else/let-else-allow-unused.rs` and `ui/let-else/let-else-check.rs` to ensure that non-presence of `#[allow(unused)]` does issue the unused lint. This was adding a missing test case as pointed out by the stabilization report.
Added by 5bd71063b3
(#94208 ):
* [`ui/let-else/let-else-slicing-error.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-slicing-error.rs ), a regression test for #92069 , which got fixed without addition of a regression test. This resolves a missing test as pointed out by the stabilization report.
Added by 5374688e1d
(#98574 ):
* [`src/test/ui/async-await/async-await-let-else.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/async-await/async-await-let-else.rs ) to test the interaction of async/await with `let else`
Added by 6c529ded86
(#98574 ):
* [`src/test/ui/let-else/let-else-temporary-lifetime.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/let-else-temporary-lifetime.rs ) as a (partial) regression test for #98672
Added by 9b56640106
(#99518 ):
* [`src/test/ui/let-else/let-else-temp-borrowck.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/let-else-temporary-lifetime.rs ) as a regression test for #93951
* Extension of `src/test/ui/let-else/let-else-temporary-lifetime.rs` to include a partial regression test for #98672 (especially regarding `else` drop order)
Added by baf9a7cb57
(#99518 ):
* Extension of `src/test/ui/let-else/let-else-temporary-lifetime.rs` to include a partial regression test for #93951 , similar to `let-else-temp-borrowck.rs`
Added by 60be2de8b7
(#99518 ):
* Extension of `src/test/ui/let-else/let-else-temporary-lifetime.rs` to include a program that can now be compiled thanks to borrow checker implications of #99518
Added by 47a7a91c96
(#100132 ):
* [`src/test/ui/let-else/issue-100103.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/issue-100103.rs ), as a regression test for #100103 , to ensure that there is no ICE when doing `Err(...)?` inside else blocks.
Added by e3c5bd617d
(#100443 ):
* [`src/test/ui/let-else/let-else-then-diverge.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/let-else-then-diverge.rs ), to verify that there is no unreachable code error with the current desugaring.
Added by 981852677c
(#100443 ):
* [`src/test/ui/let-else/issue-94176.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/issue-94176.rs ), to make sure that a correct span is emitted for a missing trailing expression error. Regression test for #94176 .
Added by e182d12a84
(#100434 ):
* [src/test/ui/unpretty/pretty-let-else.rs](https://github.com/rust-lang/rust/blob/master/src/test/ui/unpretty/pretty-let-else.rs ), as a regression test to ensure pretty printing works for `let else` (this bug surfaced in many different ways)
Added by e26285603c
(#99954 ):
* [`src/test/ui/let-else/let-else-temporary-lifetime.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/let-else-temporary-lifetime.rs ) extended to contain & borrows as well, as this was identified as an earlier issue with the desugaring: https://github.com/rust-lang/rust/issues/98672#issuecomment-1200196921
Added by 2d8460ef43
(#99291 ):
* [`src/test/ui/let-else/let-else-drop-order.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/let-else-drop-order.rs ) a matrix based test for various drop order behaviour of `let else`. Especially, it verifies equality of `let` and `let else` drop orders, [resolving](https://github.com/rust-lang/rust/pull/93628#issuecomment-1238498468 ) a [stabilization blocker](https://github.com/rust-lang/rust/pull/93628#issuecomment-1055738523 ).
Added by 1b87ce0d40
(#101410 ):
* Edit to `src/test/ui/let-else/let-else-temporary-lifetime.rs` to add the `-Zvalidate-mir` flag, as a regression test for #99228
Added by af591ebe4d
(#101410 ):
* [`src/test/ui/let-else/issue-99975.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/issue-99975.rs ) as a regression test for the ICE #99975 .
Added by this PR:
* `ui/let-else/let-else.rs`, a simple run-pass check, similar to `ui/let-else/let-else-run-pass.rs`.
### Things not currently tested
* ~~The `#[allow(...)]` tests check whether allow works, but they don't check whether the non-presence of allow causes a lint to fire.~~ → *test added by e7730dcb7eb29a10ee73f269f4dc6e9d606db0da*
* ~~There is no `#[allow(...)]` test for the expression, as there are tests for the pattern and the else block.~~ → *test added by e7730dcb7eb29a10ee73f269f4dc6e9d606db0da*
* ~~`let-else-brace-before-else.rs` forbids the `let ... = {} else {}` pattern and there is a rustfix to obtain `let ... = ({}) else {}`. I'm not sure whether the `.fixed` files are checked by the tooling that they compile. But if there is no such check, it would be neat to make sure that `let ... = ({}) else {}` compiles.~~ → *test added by e7730dcb7eb29a10ee73f269f4dc6e9d606db0da*
* ~~#92069 got closed as fixed, but no regression test was added. Not sure it's worth to add one.~~ → *test added by 5bd71063b3810d977aa376d1e6dd7cec359330cc*
* ~~consistency between `let else` and `if let` regarding lifetimes and drop order: https://github.com/rust-lang/rust/pull/93628#issuecomment-1055738523~~ → *test added by 2d8460ef43d902f34ba2133fe38f66ee8d2fdafc*
Edit: they are all tested now.
### Possible future work / Refutable destructuring assignments
[RFC 2909](https://rust-lang.github.io/rfcs/2909-destructuring-assignment.html ) specifies destructuring assignment, allowing statements like `FooBar { a, b, c } = foo();`.
As it was stabilized, destructuring assignment only allows *irrefutable* patterns, which before the advent of `let else` were the only patterns that `let` supported.
So the combination of `let else` and destructuring assignments gives reason to think about extensions of the destructuring assignments feature that allow refutable patterns, discussed in #93995 .
A naive mapping of `let else` to destructuring assignments in the form of `Some(v) = foo() else { ... };` might not be the ideal way. `let else` needs a diverging `else` clause as it introduces new bindings, while assignments have a default behaviour to fall back to if the pattern does not match, in the form of not performing the assignment. Thus, there is no good case to require divergence, or even an `else` clause at all, beyond the need for having *some* introducer syntax so that it is clear to readers that the assignment is not a given (enums and structs look similar). There are better candidates for introducer syntax however than an empty `else {}` clause, like `maybe` which could be added as a keyword on an edition boundary:
```Rust
let mut v = 0;
maybe Some(v) = foo(&v);
maybe Some(v) = foo(&v) else { bar() };
```
Further design discussion is left to an RFC, or the linked issue.
2022-09-17 15:31:06 +05:30
Guillaume Gomez
9a72ded562
Rollup merge of #101859 - Rageking8:slight-vertical-formatting, r=compiler-errors
...
Slight vertical formatting
2022-09-16 13:07:18 +02:00
yukang
484b612909
use subdiagnostic for logical negation, bitwise not
2022-09-16 14:41:42 +08:00
est31
173eb6f407
Only enable the let_else feature on bootstrap
...
On later stages, the feature is already stable.
Result of running:
rg -l "feature.let_else" compiler/ src/librustdoc/ library/ | xargs sed -s -i "s#\\[feature.let_else#\\[cfg_attr\\(bootstrap, feature\\(let_else\\)#"
2022-09-15 21:06:45 +02:00
yukang
4bf7d2ca91
tweak suggestion
2022-09-16 01:09:26 +08:00
Rageking8
6d7beafc87
slight vertical formatting
2022-09-15 23:51:43 +08:00
yukang
f43562b95b
more tweak on diagnostic messages
2022-09-15 22:39:16 +08:00
yukang
98e20c097c
fix #101797 : Suggest associated const for incorrect use of let in traits
2022-09-15 16:15:38 +08:00
bors
750bd1a7ff
Auto merge of #101313 - SparrowLii:mk_attr_id, r=cjgillot
...
make `mk_attr_id` part of `ParseSess`
Updates #48685
The current `mk_attr_id` uses the `AtomicU32` type, which is not very efficient and adds a lot of lock contention in a parallel environment.
This PR refers to the task list in #48685 , uses `mk_attr_id` as a method of the `AttrIdGenerator` struct, and adds a new field `attr_id_generator` to `ParseSess`.
`AttrIdGenerator` uses the `WorkerLocal`, which has two advantages: 1. `Cell` is more efficient than `AtomicU32`, and does not increase any lock contention. 2. We put the index of the work thread in the first few bits of the generated `AttrId`, so that the `AttrId` generated in different threads can be easily guaranteed to be unique.
cc `@cjgillot`
2022-09-14 20:52:18 +00:00
bors
6153d3cbe6
Auto merge of #101212 - eholk:dyn-star, r=compiler-errors
...
Initial implementation of dyn*
This PR adds extremely basic and incomplete support for [dyn*](https://smallcultfollowing.com/babysteps//blog/2022/03/29/dyn-can-we-make-dyn-sized/ ). The goal is to get something in tree behind a flag to make collaboration easier, and also to make sure the implementation so far is not unreasonable. This PR does quite a few things:
* Introduce `dyn_star` feature flag
* Adds parsing for `dyn* Trait` types
* Defines `dyn* Trait` as a sized type
* Adds support for explicit casts, like `42usize as dyn* Debug`
* Including const evaluation of such casts
* Adds codegen for drop glue so things are cleaned up properly when a `dyn* Trait` object goes out of scope
* Adds codegen for method calls, at least for methods that take `&self`
Quite a bit is still missing, but this gives us a starting point. Note that this is never intended to become stable surface syntax for Rust, but rather `dyn*` is planned to be used as an implementation detail for async functions in dyn traits.
Joint work with `@nikomatsakis` and `@compiler-errors.`
r? `@bjorn3`
2022-09-14 18:10:51 +00:00
SparrowLii
1a3ecbdb6a
make mk_attr_id
part of ParseSess
2022-09-14 08:49:10 +08:00
Eric Holk
cf04547b0b
Address code review comments
2022-09-13 14:50:12 -07:00
Camille GILLOT
cb5ea8d0b6
Emit an error instead of reconstructing token stream.
2022-09-13 19:47:50 +02:00
Camille GILLOT
8823634db8
Manually cleanup token stream when macro expansion aborts.
2022-09-13 19:46:01 +02:00
Eric Holk
eff35e59c6
Introduce dyn_star feature flag
...
The primary purpose of this commit is to introduce the
dyn_star flag so we can begin experimenting with implementation.
In order to have something to do in the feature gate test, we also add
parser support for `dyn* Trait` objects. These are currently treated
just like `dyn Trait` objects, but this will change in the future.
Note that for now `dyn* Trait` is experimental syntax to enable
implementing some of the machinery needed for async fn in dyn traits
without fully supporting the feature.
2022-09-12 16:55:55 -07:00
Nicholas Nethercote
d2df07c425
Rename {Create,Lazy}TokenStream
as {To,Lazy}AttrTokenStream
.
...
`To` is better than `Create` for indicating that this is a non-consuming
conversion, rather than creating something out of nothing.
And the addition of `Attr` is because the current names makes them sound
like they relate to `TokenStream`, but really they relate to
`AttrTokenStream`.
2022-09-09 17:25:38 +10:00