Commit Graph

2128 Commits

Author SHA1 Message Date
Nicholas Nethercote
03159d4bff Remove ErrorGuaranteed retval from error_unexpected_after_dot.
It was added in #130349, but it's not used meaningfully, and causes
difficulties for Nonterminal removal in #124141.
2024-11-21 08:22:17 +11:00
Nicholas Nethercote
cee88f7a3f Prepare for invisible delimiters.
Current places where `Interpolated` is used are going to change to
instead use invisible delimiters. This prepares for that.
- It adds invisible delimiter cases to the `can_begin_*`/`may_be_*`
  methods and the `failed_to_match_macro` that are equivalent to the
  existing `Interpolated` cases.
- It adds panics/asserts in some places where invisible delimiters
  should never occur.
- In `Parser::parse_struct_fields` it excludes an ident + invisible
  delimiter from special consideration in an error message, because
  that's quite different to an ident + paren/brace/bracket.
2024-11-21 08:22:11 +11:00
Nicholas Nethercote
cfafa9380b Add metavariables to TokenDescription.
Pasted metavariables are wrapped in invisible delimiters, which
pretty-print as empty strings, and changing that can break some proc
macros. But error messages saying "expected identifer, found ``" are
bad. So this commit adds support for metavariables in `TokenDescription`
so they print as "metavariable" in error messages, instead of "``".

It's not used meaningfully yet, but will be needed to get rid of
interpolated tokens.
2024-11-21 08:16:55 +11:00
Nicholas Nethercote
afe238f66f Introduce InvisibleOrigin on invisible delimiters.
It's not used meaningfully yet, but will be needed to get rid of
interpolated tokens.
2024-11-21 08:16:54 +11:00
bors
875df370be Auto merge of #133219 - matthiaskrgr:rollup-hnuq0zf, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #123947 (Add vec_deque::Iter::as_slices and friends)
 - #125405 (Add std:🧵:add_spawn_hook.)
 - #133175 (ci: use free runner in dist-i686-msvc)
 - #133183 (Mention std::fs::remove_dir_all in std::fs::remove_dir)
 - #133188 (Add `visit` methods to ast nodes that already have `walk`s on ast visitors)
 - #133201 (Remove `TokenKind::InvalidPrefix`)
 - #133207 (Default-enable `llvm_tools_enabled` when no `config.toml` is present)
 - #133213 (Correct the tier listing of `wasm32-wasip2`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-11-19 23:04:44 +00:00
bors
ee612c45f0 Auto merge of #132761 - nnethercote:resolve-tweaks, r=petrochenkov
Resolve tweaks

A couple of small perf improvements, and some minor refactorings, all in `rustc_resolve`.

r? `@petrochenkov`
2024-11-19 19:54:35 +00:00
Nicholas Nethercote
e9a0c3c98c Remove TokenKind::InvalidPrefix.
It was added in #123752 to handle some cases involving emoji, but it
isn't necessary because it's always treated the same as
`TokenKind::InvalidIdent`. This commit removes it, which makes things a
little simpler.
2024-11-19 18:06:22 +11:00
Kornel
7765f23ea1
Diagnostics for let mut in item context 2024-11-17 22:30:11 +00:00
许杰友 Jieyou Xu (Joe)
0b157e88d7
Rollup merge of #133060 - tyrone-wu:removelet-span-suggestion, r=jieyouxu
Trim whitespace in RemoveLet primary span

Separate `RemoveLet` span into primary span for `let` and removal suggestion span for `let `, so that primary span does not include whitespace.

Fixes: #133031
2024-11-17 23:56:09 +08:00
Esteban Küber
6913194b8e review comment: move logic to new method 2024-11-16 20:03:31 +00:00
Esteban Küber
c09c73b996 Reword suggestion message 2024-11-16 20:03:31 +00:00
Esteban Küber
629a69f3e2 Better account for else if macro conditions mising an if
If a macro statement has been parsed after `else`, suggest a missing `if`:

```
error: expected `{`, found `falsy`
  --> $DIR/else-no-if.rs:47:12
   |
LL |     } else falsy! {} {
   |       ---- ^^^^^
   |       |
   |       expected an `if` or a block after this `else`
   |
help: add an `if` if this is the condition of a chained `else if` statement
   |
LL |     } else if falsy! {} {
   |            ++
```
2024-11-16 20:03:31 +00:00
Esteban Küber
04fe839177 Increase accuracy of if condition misparse suggestion
Look at the expression that was parsed when trying to recover from a bad `if` condition to determine what was likely intended by the user beyond "maybe this was meant to be an `else` body".

```
error: expected `{`, found `map`
  --> $DIR/missing-dot-on-if-condition-expression-fixable.rs:4:30
   |
LL |     for _ in [1, 2, 3].iter()map(|x| x) {}
   |                              ^^^ expected `{`
   |
help: you might have meant to write a method call
   |
LL |     for _ in [1, 2, 3].iter().map(|x| x) {}
   |                              +
```
2024-11-16 20:03:31 +00:00
Tyrone Wu
dd557c988f
Trim whitespace in RemoveLet primary span
Separate `RemoveLet` span into primary span for `let` and removal
suggestion span for `let `, so that primary span does not include
whitespace.

Fixes: #133031

Signed-off-by: Tyrone Wu <wudevelops@gmail.com>
2024-11-15 17:43:29 +00:00
clubby789
1136bbf066 Trim extra space when suggesting removing bad let 2024-11-13 13:19:13 +00:00
Nicholas Nethercote
99d02fb40f Optimize check_keyword_case.
`to_lowercase` allocates, but `eq_ignore_ascii_case` doesn't. This path
is hot enough that this makes a small but noticeable difference in
benchmarking.
2024-11-13 08:43:47 +11:00
bors
42b2496320 Auto merge of #126597 - estebank:unicode-output, r=fmease
Add Unicode block-drawing compiler output support

Add nightly-only theming support to rustc output using Unicode box
drawing characters instead of ASCII-art to draw the terminal UI.

In order to enable, the flags `-Zunstable-options=yes --error-format=human-unicode` must be passed in.

After:

```
error: foo
  ╭▸ test.rs:3:3
  │
3 │       X0 Y0 Z0
  │   ┌───╿──│──┘
  │  ┌│───│──┘
  │ ┏││━━━┙
  │ ┃││
4 │ ┃││   X1 Y1 Z1
5 │ ┃││   X2 Y2 Z2
  │ ┃│└────╿──│──┘ `Z` label
  │ ┃└─────│──┤
  │ ┗━━━━━━┥  `Y` is a good letter too
  │        `X` is a good letter
  ╰╴
note: bar
  ╭▸ test.rs:4:3
  │
4 │ ┏   X1 Y1 Z1
5 │ ┃   X2 Y2 Z2
6 │ ┃   X3 Y3 Z3
  │ ┗━━━━━━━━━━┛
  ├ note: bar
  ╰ note: baz
note: qux
  ╭▸ test.rs:4:3
  │
4 │   X1 Y1 Z1
  ╰╴  ━━━━━━━━
```

Before:

```
error: foo
 --> test.rs:3:3
  |
3 |       X0 Y0 Z0
  |    ___^__-__-
  |   |___|__|
  |  ||___|
  | |||
4 | |||   X1 Y1 Z1
5 | |||   X2 Y2 Z2
  | |||____^__-__- `Z` label
  | ||_____|__|
  | |______|  `Y` is a good letter too
  |        `X` is a good letter
  |
note: bar
 --> test.rs:4:3
  |
4 | /   X1 Y1 Z1
5 | |   X2 Y2 Z2
6 | |   X3 Y3 Z3
  | |__________^
  = note: bar
  = note: baz
note: qux
 --> test.rs:4:3
  |
4 |   X1 Y1 Z1
  |   ^^^^^^^^
```

After:

![rustc output with unicode box drawing characters](https://github.com/rust-lang/rust/assets/1606434/d210b79a-6579-4407-9706-ba8edc6e9f25)

Before:
![current rustc output with ASCII art](https://github.com/rust-lang/rust/assets/1606434/5aecccf8-a6ee-4469-8b39-72fb0d979a9f)
2024-11-11 00:00:58 +00:00
Esteban Küber
1d78004575
Add Unicode block-drawing compiler output support
Add nightly-only theming support to rustc output using Unicode box
drawing characters instead of ASCII-art to draw the terminal UI:

After:

```
error: foo
  ╭▸ test.rs:3:3
  │
3 │       X0 Y0 Z0
  │   ┌───╿──│──┘
  │  ┌│───│──┘
  │ ┏││━━━┙
  │ ┃││
4 │ ┃││   X1 Y1 Z1
5 │ ┃││   X2 Y2 Z2
  │ ┃│└────╿──│──┘ `Z` label
  │ ┃└─────│──┤
  │ ┗━━━━━━┥  `Y` is a good letter too
  │        `X` is a good letter
  ╰╴
note: bar
  ╭▸ test.rs:4:3
  │
4 │ ┏   X1 Y1 Z1
5 │ ┃   X2 Y2 Z2
6 │ ┃   X3 Y3 Z3
  │ ┗━━━━━━━━━━┛
  ├ note: bar
  ╰ note: baz
note: qux
  ╭▸ test.rs:4:3
  │
4 │   X1 Y1 Z1
  ╰╴  ━━━━━━━━
```

Before:

```
error: foo
 --> test.rs:3:3
  |
3 |       X0 Y0 Z0
  |    ___^__-__-
  |   |___|__|
  |  ||___|
  | |||
4 | |||   X1 Y1 Z1
5 | |||   X2 Y2 Z2
  | |||____^__-__- `Z` label
  | ||_____|__|
  | |______|  `Y` is a good letter too
  |        `X` is a good letter
  |
note: bar
 --> test.rs:4:3
  |
4 | /   X1 Y1 Z1
5 | |   X2 Y2 Z2
6 | |   X3 Y3 Z3
  | |__________^
  = note: bar
  = note: baz
note: qux
 --> test.rs:4:3
  |
4 |   X1 Y1 Z1
  |   ^^^^^^^^
```
2024-11-10 23:57:18 +01:00
Matthias Krüger
910ac7eabf
Rollup merge of #132363 - compiler-errors:raw-lt-id-valid, r=wesleywiser
Enforce that raw lifetimes must be valid raw identifiers

Make sure that the identifier part of a raw lifetime is a valid raw identifier. This precludes `'r#_` and all module segment paths for now.

I don't believe this is compelling to support. This was raised by `@ehuss` in https://github.com/rust-lang/reference/pull/1603#discussion_r1822726753 (well, specifically the `'r#_` case), but I don't see why we shouldn't just make it consistent with raw identifiers.
2024-11-09 19:16:43 +01:00
Nicholas Nethercote
981dc02eaf Revert "Avoid nested replacement ranges" from #129346.
It caused a test regression in the `cfg_eval.rs` crate. (The bugfix
in #129346 was in a different commit; this commit was just a code
simplification.)
2024-11-04 15:57:35 +11:00
Mara Bos
cb26fa07bb Improve the missing_abi lint. 2024-10-31 10:55:45 +01:00
Michael Goulet
9785c7cf94 Enforce that raw lifetime identifiers must be valid raw identifiers 2024-10-30 14:45:22 +00:00
Matthias Krüger
2480e3bbc5
Rollup merge of #132332 - nnethercote:use-token_descr-more, r=estebank
Use `token_descr` more in error messages

This is the first two commits from #124141, put into their own PR to get things rolling. Commit messages have the details.

r? ``@estebank``
cc ``@petrochenkov``
2024-10-30 06:40:36 +01:00
klensy
746b675c5a fix clippy::clone_on_ref_ptr for compiler 2024-10-28 18:05:08 +03:00
Nicholas Nethercote
a201fab208 Tweak expand_incomplete_parse warning.
By using `token_descr`, as is done for many other errors, we can get
slightly better descriptions in error messages, e.g.
"macro expansion ignores token `let` and any following" becomes
"macro expansion ignores keyword `let` and any tokens following".

This will be more important once invisible delimiters start being
mentioned in error messages -- without this commit, that leads to error
messages such as "error at ``" because invisible delimiters are
pretty printed as an empty string.
2024-10-28 14:12:45 +11:00
Josh Triplett
ecdc2441b6 "innermost", "outermost", "leftmost", and "rightmost" don't need hyphens
These are all standard dictionary words and don't require hyphenation.
2024-10-23 02:45:24 -07:00
bors
f79fae3069 Auto merge of #131723 - matthiaskrgr:rollup-krcslig, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #122670 (Fix bug where `option_env!` would return `None` when env var is present but not valid Unicode)
 - #131095 (Use environment variables instead of command line arguments for merged doctests)
 - #131339 (Expand set_ptr_value / with_metadata_of docs)
 - #131652 (Move polarity into `PolyTraitRef` rather than storing it on the side)
 - #131675 (Update lint message for ABI not supported)
 - #131681 (Fix up-to-date checking for run-make tests)
 - #131702 (Suppress import errors for traits that couldve applied for method lookup error)
 - #131703 (Resolved python deprecation warning in publish_toolstate.py)
 - #131710 (Remove `'apostrophes'` from `rustc_parse_format`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-10-15 11:50:31 +00:00
Matthias Krüger
fb691b470a
Rollup merge of #130635 - eholk:pin-reborrow-sugar, r=compiler-errors
Add `&pin (mut|const) T` type position sugar

This adds parser support for `&pin mut T` and `&pin const T` references. These are desugared to `Pin<&mut T>` and `Pin<&T>` in the AST lowering phases.

This PR currently includes #130526 since that one is in the commit queue. Only the most recent commits (bd450027eb4a94b814a7dd9c0fa29102e6361149 and following) are new.

Tracking:

- #130494

r? `@compiler-errors`
2024-10-15 05:12:34 +02:00
Michael Goulet
95dba280b9 Move trait bound modifiers into ast::PolyTraitRef 2024-10-14 09:20:38 -04:00
printfn
46b41b4fc8 Update unicode-width to 0.2.0 2024-10-12 21:57:50 +00:00
Trevor Gross
63a91db022
Rollup merge of #130870 - surechen:fix_130791, r=compiler-errors
Add suggestion for removing invalid path sep `::` in fn def

Add suggestion for removing invalid path separator `::` in function definition.

for example: `fn invalid_path_separator::<T>() {}`

fixes #130791
2024-10-12 11:08:42 -05:00
bors
f4966590d8 Auto merge of #131045 - compiler-errors:remove-unnamed_fields, r=wesleywiser
Retire the `unnamed_fields` feature for now

`#![feature(unnamed_fields)]` was implemented in part in #115131 and #115367, however work on that feature has (afaict) stalled and in the mean time there have been some concerns raised (e.g.[^1][^2]) about whether `unnamed_fields` is worthwhile to have in the language, especially in its current desugaring. Because it represents a compiler implementation burden including a new kind of anonymous ADT and additional complication to field selection, and is quite prone to bugs today, I'm choosing to remove the feature.

However, since I'm not one to really write a bunch of words, I'm specifically *not* going to de-RFC this feature. This PR essentially *rolls back* the state of this feature to "RFC accepted but not yet implemented"; however if anyone wants to formally unapprove the RFC from the t-lang side, then please be my guest. I'm just not totally willing to summarize the various language-facing reasons for why this feature is or is not worthwhile, since I'm coming from the compiler side mostly.

Fixes #117942
Fixes #121161
Fixes #121263
Fixes #121299
Fixes #121722
Fixes #121799
Fixes #126969
Fixes #131041

Tracking:
* https://github.com/rust-lang/rust/issues/49804

[^1]: https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Unnamed.20struct.2Funion.20fields
[^2]: https://github.com/rust-lang/rust/issues/49804#issuecomment-1972619108
2024-10-11 13:11:13 +00:00
Peter Jaszkowiak
321a5db7d4 Reserve guarded string literals (RFC 3593) 2024-10-08 18:21:16 -06:00
Eric Holk
b490bf56b7
Fix clippy and rustfmt compilation 2024-10-07 11:15:15 -07:00
Eric Holk
ae698f8199
Add sugar for &pin (const|mut) types 2024-10-07 11:15:04 -07:00
bors
0b16baa570 Auto merge of #131235 - codemountains:rename-nestedmetaitem-to-metaitemlnner, r=nnethercote
Rename `NestedMetaItem` to `MetaItemInner`

Fixes #131087

r? `@nnethercote`
2024-10-07 08:59:55 +00:00
codemountains
6dfc4a0473 Rename NestedMetaItem to MetaItemInner 2024-10-06 23:28:30 +09:00
Esteban Küber
7f5548fa8b On function and method calls in patterns, link to the book
```
error: expected a pattern, found an expression
 --> f889.rs:3:13
  |
3 |     let (x, y.drop()) = (1, 2); //~ ERROR
  |             ^^^^^^^^ not a pattern
  |
  = note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>

error[E0532]: expected a pattern, found a function call
 --> f889.rs:2:13
  |
2 |     let (x, drop(y)) = (1, 2); //~ ERROR
  |             ^^^^ not a tuple struct or tuple variant
  |
  = note: function calls are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
```

Fix #97200.
2024-10-06 01:44:59 +00:00
Guillaume Gomez
2ceeeb159d
Rollup merge of #131034 - Urgau:cfg-true-false, r=nnethercote
Implement RFC3695 Allow boolean literals as cfg predicates

This PR implements https://github.com/rust-lang/rfcs/pull/3695: allow boolean literals as cfg predicates, i.e. `cfg(true)` and `cfg(false)`.

r? `@nnethercote` *(or anyone with parser knowledge)*
cc `@clubby789`
2024-10-04 15:42:53 +02:00
Jubilee
b7c33e2f20
Rollup merge of #130725 - GrigorenkoPV:@-in-struct-patterns, r=Nadrieril
Parser: better error messages for `@` in struct patterns
2024-10-02 21:26:58 -07:00
Michael Goulet
40465d2449 Remove anon struct and union types 2024-10-01 13:55:46 -04:00
Michael Goulet
e3a0da1863 Remove unnamed field feature 2024-10-01 13:55:46 -04:00
Urgau
57b9b1f974 Use ast::NestedMetaItem when evaluating cfg predicate 2024-10-01 10:01:09 +02:00
surechen
d0165956fe Add suggestion for removing invalid path separator :: in function definition.
for example: `fn invalid_path_separator::<T>() {}`

fixes: #130791
2024-09-27 15:41:04 +08:00
Jubilee
515bdcda01
Rollup merge of #130551 - nnethercote:fix-break-last-token, r=petrochenkov
Fix `break_last_token`.

It currently doesn't handle the three-char tokens `>>=` and `<<=` correctly. These can be broken twice, resulting in three individual tokens. This is a latent bug that currently doesn't cause any problems, but does cause problems for #124141, because that PR increases the usage of lazy token streams.

r? `@petrochenkov`
2024-09-23 07:54:44 -07:00
Nicholas Nethercote
73cc575177 Fix break_last_token.
It currently doesn't handle the three-char tokens `>>=` and `<<=`
correctly. These can be broken twice, resulting in three individual
tokens. This is a latent bug that currently doesn't cause any problems,
but does cause problems for #124141, because that PR increases the usage
of lazy token streams.
2024-09-23 09:14:30 +10:00
Pavel Grigorenko
9cd668beed Parser: better error messages for @ in struct patterns 2024-09-23 02:12:53 +03:00
Michael Goulet
c682aa162b Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
Pavel Grigorenko
82482dc357 Parser: recover from ::: to :: in delegations 2024-09-21 20:29:22 +03:00
Pavel Grigorenko
e90e2593ea Parser: recover from ::: to :: 2024-09-21 20:07:52 +03:00