Commit Graph

2438 Commits

Author SHA1 Message Date
Jakub Beránek
d68432a1a9
Rollup merge of #142341 - xizheyin:142311, r=fee1-dead
Don't suggest converting `///` to `//` when expecting `,`

Fixes rust-lang/rust#142311
2025-06-16 19:54:33 +02:00
xizheyin
c63665cd73 Dont suggest converting /// to regular comment when it appears after missing , in list
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-06-16 23:07:11 +08:00
Deadbeef
96fd9fc2dd use if let guards where possible 2025-06-15 15:46:20 +08:00
Jonathan Brouwer
b131b6f630
Rework how the disallowed qualifier lints are generated
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-06-13 18:13:34 +02:00
Matthias Krüger
75c186bf43
Rollup merge of #142261 - folkertdev:unstable-attr-correct-edition, r=compiler-errors
use correct edition when warning for unsafe attributes

fixes https://github.com/rust-lang/rust/issues/142182

If an attribute is re-emitted by a macro, the incorrect edition was used to emit warnings for unsafe attributes.

This logic was introduced in https://github.com/rust-lang/rust/pull/139718

cc `@compiler-errors` `@ehuss`
2025-06-12 03:14:52 +02:00
Lukas Wirth
edc405d383 Add expectation for { when parsing lone coroutine qualifiers 2025-06-11 17:11:58 +02:00
Folkert de Vries
2c8257493d
use correct edition when warning for unsafe attributes
If an attribute is re-emitted by a macro, the incorrect edition was used to emit warnings for unsafe attributes
2025-06-09 21:55:22 +02:00
bjorn3
9223704f4b Remove all unused feature gates from the compiler 2025-06-08 14:50:42 +00:00
Guillaume Gomez
93ca0af08c
Rollup merge of #141603 - nnethercote:reduce-P, r=fee1-dead
Reduce `ast::ptr::P` to a typedef of `Box`

As per the MCP at https://github.com/rust-lang/compiler-team/issues/878.

r? `@fee1-dead`
2025-06-06 23:53:16 +02:00
Josh Stone
af2a85bd75 Ensure stack in Parser::parse_ty
This solve a stack overflow found on Fedora s390x when building
`tests/ui/associated-consts/issue-93775.rs`.
2025-06-04 15:21:30 -07:00
Matthias Krüger
0736a03a78
Rollup merge of #141570 - chenyukang:yukang-fix-eq_unspanned, r=workingjubilee
Fix incorrect eq_unspanned in TokenStream

Fixes rust-lang/rust#141522

r? ``@workingjubilee``

should we remove this function?
since it's used in several places, i'd prefer to keep it.
2025-06-04 16:24:07 +02:00
Matthias Krüger
96531418f8
Rollup merge of #141945 - nnethercote:rm-Path-is_ident, r=compiler-errors
Remove `Path::is_ident`.

It checks that a path has a single segment that matches the given symbol, and that there are zero generic arguments. It has a single use.

We also have `impl PartialEq<Symbol> for Path` which does exactly the same thing *except* it doesn't check for zero generic arguments, which seems like an oversight. It has numerous uses.

This commit removes `Path::is_ident`, adds a test for zero generic arguments to `PartialEq<Symbol> for Path`, and changes the single use of `is_ident` to instead use `==`.

r? `@wesleywiser`
2025-06-03 21:53:38 +02:00
Oli Scherer
5fbdfc3e10
Add iter macro
This adds an `iter!` macro that can be used to create movable
generators.

This also adds a yield_expr feature so the `yield` keyword can be used
within iter! macro bodies. This was needed because several unstable
features each need `yield` expressions, so this allows us to stabilize
them separately from any individual feature.

Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
Co-authored-by: Jieyou Xu <jieyouxu@outlook.com>
Co-authored-by: Travis Cross <tc@traviscross.com>
2025-06-03 10:52:32 -07:00
Nicholas Nethercote
04391045d0 Remove Path::is_ident.
It checks that a path has a single segment that matches the given
symbol, and that there are zero generic arguments. It has a single use.

We also have `impl PartialEq<Symbol> for Path` which does exactly the
same thing *except* it doesn't check for zero generic arguments, which
seems like an oversight. It has numerous uses.

This commit removes `Path::is_ident`, adds a test for zero generic
arguments to `PartialEq<Symbol> for Path`, and changes the single use of
`is_ident` to instead use `==`.
2025-06-03 15:21:33 +10:00
Jubilee
5e139db47b
Rollup merge of #141077 - chenyukang:yukang-fix-140991-comma, r=wesleywiser
Fix the issue of typo of comma in arm parsing

Fixes #140991

I also checked is it a '/', since it's near from ',' from keyboard.
2025-05-30 13:52:25 -07:00
Matthias Krüger
5fc3f26748
Rollup merge of #141004 - matthewjasper:unicode-before-expansion, r=davidtwco
Report text_direction_codepoint_in_literal when parsing

The lint is now reported in code that gets removed/modified/duplicated by macro expansion, and spans are more accurate so we don't get ICEs from trying to split a span in the middle of a character.

This removes support for lint level attributes for `text_direction_codepoint_in_literal` except at the crate level, I don't think that there's an easy way around this when the lint can be reported on code that's removed by `cfg` or that is only in the input of a macro.

Fixes #140281
2025-05-30 07:01:28 +02:00
Jacob Pratt
0ac0285c3f
Rollup merge of #141675 - nnethercote:ItemKind-field-order, r=fee1-dead
Reorder `ast::ItemKind::{Struct,Enum,Union}` fields.

So they match the order of the parts in the source code, e.g.:
```
struct Foo<T, U> { t: T, u: U }
       <-><----> <------------>
       /   |       \
   ident generics  variant_data
```

r? `@fee1-dead`
2025-05-29 04:49:43 +02:00
Trevor Gross
d6b1108cda
Rollup merge of #141670 - chenyukang:yukang-fix-ice-from-contracts, r=nnethercote
Fix ICE in tokenstream with contracts from parser recovery

Fixes rust-lang/rust#140683

After two times of parsing error, the `recover_stmt_` constructs an error ast, then when we expand macors, the invalid tokenstream triggered ICE because of mismatched delims.

Expected `{` and get other tokens is an obvious error message, too much effort on recovery may introduce noise.

r? ```@nnethercote```
2025-05-28 10:28:11 -04:00
Nicholas Nethercote
4c4a40f6df Reorder ast::ItemKind::{Struct,Enum,Union} fields.
So they match the order of the parts in the source code, e.g.:
```
struct Foo<T, U> { t: T, u: U }
       <-><----> <------------>
       /   |       \
   ident generics  variant_data
```
2025-05-28 15:48:45 +10:00
yukang
adcd0bf5c3 Fix ICE in tokenstream with contracts from parser recovery 2025-05-28 09:35:10 +08:00
Matthew Jasper
65bdb31a97 Report text_direction_codepoint_in_literal when parsing
- The lint is now reported in code that gets removed/modified/duplicated
  by macro expansion.
- Spans are more accurate
- Fixes #140281
2025-05-27 15:57:41 +00:00
Folkert de Vries
c7c0194d98
move asm parsing code into rustc_parse 2025-05-27 09:44:10 +02:00
Nicholas Nethercote
991c91fdaa Reduce P<T> to a typedef of Box<T>.
Keep the `P` constructor function for now, to minimize immediate churn.

All the `into_inner` calls are removed, which is nice.
2025-05-27 13:29:24 +10:00
Nicholas Nethercote
0f285e346f Remove the one use of P<[T]>.
A `Vec` is fine, the additional word (vector vs. boxed slice) doesn't
matter here.
2025-05-27 02:54:18 +10:00
yukang
d3347bb32b remove eq_unspanned from TokenStream 2025-05-26 17:02:51 +08:00
yukang
5f8954bc41 Fix the issue of typo of comma in arm parsing 2025-05-16 12:40:04 +02:00
Matthias Krüger
e53b9f8fdd
Rollup merge of #141003 - clubby789:ternary-improve, r=compiler-errors
Improve ternary operator recovery

This
- Improves the span of the error to not point at the next token
- Where possible, we use the span of the condition to further improve the span of the error to include the cond, and suggest a maybe-incorrect fix

Currently this works on free expressions, not let statements; some more refactoring would be needed to pass the span down, which I'm not sure is worth doing.

### Old
![image](https://github.com/user-attachments/assets/5688cefc-e4ef-4135-a5ba-340ce05ae6f3)

### New
![image](https://github.com/user-attachments/assets/154f5380-e0c8-42c7-9bf8-0adb3d0433fa)
2025-05-16 07:19:41 +02:00
Jamie
1267333ef1 Improve ternary operator recovery 2025-05-14 13:32:59 +01:00
Pietro Albini
2ce08ca5d6
update cfg(bootstrap) 2025-05-12 15:33:37 +02:00
Kornel
fc20650c6a
Error message for top-level or-patterns suggesting a solution 2025-05-09 22:16:34 +09:00
Nicholas Nethercote
0984db553d Remove Ident::empty.
All uses have been removed. And it's nonsensical: an identifier by
definition has at least one char.

The commits adds an is-non-empty assertion to `Ident::new` to enforce
this, and converts some `Ident` constructions to use `Ident::new`.
Adding the assertion requires making `Ident::new` and
`Ident::with_dummy_span` non-const, which is no great loss.

The commit amends a couple of places that do path splitting to ensure no
empty identifiers are created.
2025-05-09 13:57:49 +10:00
Guillaume Gomez
32325e1dec
Rollup merge of #140671 - xizheyin:issue-140169, r=petrochenkov
Parser: Recover error from named params while parse_path

Fixes #140169

I added test to the first commit and the second added the code and changes to test.

r? `@petrochenkov`
2025-05-07 18:19:06 +02:00
xizheyin
b922da3586 Use parse_param_general when parsing (T, U)->R in parse_path_segment
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>

Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>
2025-05-07 22:56:14 +08:00
Stuart Cook
627873a078
Rollup merge of #140035 - fee1-dead-contrib:push-oszwkkvmpkks, r=jieyouxu,wesleywiser
Implement RFC 3503: frontmatters

Tracking issue: #136889

Supercedes #137193. This implements [RFC 3503](https://github.com/rust-lang/rfcs/blob/master/text/3503-frontmatter.md).

This might break rust-analyzer. Will look into how to fix that.

Suggestions welcome for how to improve diagnostics.
2025-05-06 16:28:39 +10:00
Deadbeef
662182637e Implement RFC 3503: frontmatters
Supercedes #137193
2025-05-05 23:10:08 +08:00
Jieyou Xu
eb3a8e5b81
Make attribute safety validation logic more obvious 2025-05-04 21:44:50 +08:00
Urgau
f4e1ec111c Report the unsafe_attr_outside_unsafe lint at the closest node 2025-05-03 16:10:25 +02:00
Matthias Krüger
a477172ced
Rollup merge of #140494 - ehuss:document-restrictions, r=traviscross,SparrowLii
Parser: Document restrictions

I had trouble easily understanding what these various flags do. This is my attempt to try to explain what these do.
2025-04-30 22:36:44 +02:00
Vadim Petrochenkov
6668d13de2 ast: Remove token visiting from AST visitor
It's no longer necessary after the removal of nonterminal tokens in #124141.
2025-04-30 10:36:03 +03:00
Eric Huss
2b92f9fb98 Parser: Document restrictions
I had trouble easily understanding what these various flags do. This is
my attempt to try to explain what these do.
2025-04-29 18:05:45 -07:00
Nicholas Nethercote
880e6f716d Use ThinVec to shrink LazyAttrTokenStreamInner. 2025-04-30 07:12:09 +10:00
Nicholas Nethercote
298c56f4ba Simplify LazyAttrTokenStream.
This commit does the following.
- Changes it from `Lrc<Box<dyn ToAttrTokenStream>>` to
  `Lrc<LazyAttrTokenStreamInner>`.
- Reworks `LazyAttrTokenStreamImpl` as `LazyAttrTokenStreamInner`, which
  is a two-variant enum.
- Removes the `ToAttrTokenStream` trait and the two impls of it.

The recursion limit must be increased in some crates otherwise rustdoc
aborts.
2025-04-30 07:10:56 +10:00
Nicholas Nethercote
28236ab703 Move various token stream things from rustc_parse to rustc_ast.
Specifically: `TokenCursor`, `TokenTreeCursor`,
`LazyAttrTokenStreamImpl`, `FlatToken`, `make_attr_token_stream`,
`ParserRange`, `NodeRange`. `ParserReplacement`, and `NodeReplacement`.
These are all related to token streams, rather than actual parsing.

This will facilitate the simplifications in the next commit.
2025-04-29 12:14:27 +10:00
Matthias Krüger
6f6fa0f23a
Rollup merge of #140272 - Kivooeo:new-fix-four, r=est31
Improve error message for `||` (or) in let chains

**Description**

This PR improves the error message when using `||` in an if let chain expression, addressing #140263.

**Changes**

1. Creates a dedicated error message specifically for `||` usage in let chains
2. Points the primary span directly at the `||` operator
3. Removes confusing secondary notes about "let statements" and unsupported contexts
5. Adds UI tests verifying the new error message and valid cases

**Before**
```rust
error: expected expression, found let statement
 --> src/main.rs:2:8
  |
2 |     if let true = true || false {}
  |        ^^^^^^^^^^^^^^^
  |
  = note: only supported directly in conditions of if and while expressions
note: || operators are not supported in let chain expressions
 --> src/main.rs:2:24
  |
2 |     if let true = true || false {}
  |
```

**After**
```rust
error: `||` operators are not supported in let chain conditions
 --> src/main.rs:2:24
  |
2 |     if let true = true || false {}
  |                        ^^
```

**Implementation details**
1. Added new `OrInLetChain` diagnostic in errors.rs

2. Modified `CondChecker` in expr.rs to prioritize the `||` error

3. Updated fluent message definitions to use clearer wording

**Related issue**
Fixes #140263

cc ```@ehuss``` (issue author)
2025-04-26 07:13:08 +02:00
Kivooeo
f072d30741 resolved conflict 2025-04-25 17:02:59 +05:00
Matthias Krüger
564e5ccb5c
Rollup merge of #140202 - est31:let_chains_feature_compiler, r=lcnr
Make #![feature(let_chains)] bootstrap conditional in compiler/

Let chains have been stabilized recently in #132833, so we can remove the gating from our uses in the compiler (as the compiler uses edition 2024).
2025-04-25 07:50:25 +02:00
Matthias Krüger
f45d2bd8ee
Rollup merge of #140228 - fmease:revert-overzealous-colon-recovery, r=jieyouxu
Revert overzealous parse recovery for single colons in paths

Basically manually reverts #136808, cc ``@chenyukang`` ``@estebank.``

Reopens #129273.
Fixes [after beta backport] #140227.
2025-04-24 11:40:47 +02:00
León Orell Valerian Liehr
16da97be2f
Revert overzealous parse recovery for single colons 2025-04-24 02:57:10 +02:00
bors
553600e0f5 Auto merge of #140180 - ChrisDenton:rollup-5pvs08u, r=ChrisDenton
Rollup of 7 pull requests

Successful merges:

 - #140142 (Some more graphviz tweaks)
 - #140146 (Update `compiler_builtins` to 0.1.156)
 - #140147 (Clean: rename `open_braces` to `open_delimiters` in lexer and move `make_unclosed_delims_error` into `diagnostics.rs`.)
 - #140160 (Use `is_lang_item` and `as_lang_item` instead of handrolling their logic)
 - #140163 (Validate extension in `PathBuf::add_extension`)
 - #140173 (Ping Mara when touching format_args!() internals.)
 - #140175 (`rc""` more clear error message)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-23 15:12:33 +00:00
est31
7493e1cdf6 Make #![feature(let_chains)] bootstrap conditional in compiler/ 2025-04-23 16:40:30 +02:00