Commit Graph

582 Commits

Author SHA1 Message Date
CoCo-Japan-pan d3bb7198e7 Add stringify! tests 2026-05-24 17:34:01 +09:00
Jonathan Brouwer 1db77ea560 Rollup merge of #155023 - TaKO8Ki:move-expr-1, r=nikomatsakis
Introduce move expressions (`move($expr)`)

This is an experimental first version of move expressions.

This first version implements it just in plain closures. A support for coroutine closures will be added in follow up pull requests.

RFC: will be added later
Tracking issue: https://github.com/rust-lang/rust/issues/155050
Project goal:
- https://github.com/rust-lang/rust-project-goals/issues/107
- https://rust-lang.github.io/rust-project-goals/2026/ergonomic-rc.html

r? @nikomatsakis
2026-05-11 23:03:03 +02:00
Jonathan Brouwer 6133b7e062 Rollup merge of #155734 - qaijuang:cfg-select-doc-comment, r=JonathanBrouwer
Reject outer attributes on `cfg_select` branches

Fixes rust-lang/rust#155701.
2026-05-08 11:35:31 +02:00
Qai Juang d42a92b18d Reject outer attributes on cfg_select branches
* Lint doc comments in cfg_select branches
* test with multi-line doc comment

Co-authored-by: Copilot <copilot@github.com>
* Reject outer attributes on `cfg_select` branches
* address nits and gotchas

Co-authored-by: Copilot <copilot@github.com>
* one more test

Co-authored-by: Copilot <copilot@github.com>
* avoid snapshotting and classify recovered doc comments directly
2026-05-08 09:14:09 +00:00
Takayuki Maeda 98348de63a add move(expr) syntax 2026-05-07 22:22:56 +09:00
cyrgani ee350203e8 Revert "remove MethodReceiverExpr special-casing"
This reverts commit 5ad560f7ec and adds a regression test.
2026-05-05 10:56:28 +00:00
Jonathan Brouwer fa16f8102e Rollup merge of #155693 - cclfmht:fix/issue-155508, r=ShoyuVanilla
Suggest enclosing format string with `""` under special cases

This commit adds suggestions on enclosing format string with `""` when it falls into the following 3 cases: `{}`, `{:?}`, `{:#?}` as mentioned in rust-lang/rust#155508.

Currently, this commit only recognizes the above 3 cases. I wonder if we should generalize this to more cases, for example, appying this suggestion to `Block`s with only 0 or 1 `Stmt`, such as `{:#x}`, `{:^10}`, `{abc}`.
2026-04-26 19:06:27 +02:00
Jonathan Brouwer 382ec81061 Rollup merge of #155757 - mejrs:ident_help, r=Kivooeo
macro_metavar_expr_concat: explain why idents are invalid

Recently I've been playing around with `macro_metavar_expr_concat` and in the process wasted more time than I'd have liked on debugging my dodgy idents. This should make that experience much nicer going forward.
2026-04-26 19:06:26 +02:00
cclfmht 2c16f9edf5 Suggest enclosing format string with "" under special cases
* Suggest enclosing format string under special cases

This commit add suggestions about enclosing format string when it falls
into the following cases: `{}`, `{:?}`, `{:#?}`.
* Add HELP annotations in the UI test
2026-04-26 10:50:05 +00:00
mejrs b6c6dd1fa0 macro_metavar_expr_concat: explain why idents are invalid 2026-04-25 19:56:05 +02:00
Jacob Pratt d3eddcff9e Rollup merge of #155643 - qaijuang:fix-macro-missing-fragment-dollar-suggestion, r=eholk
Improve suggestion for $-prefixed fragment specifiers

Fixes rust-lang/rust#155505
2026-04-25 01:21:50 -04:00
Qai Juang 2b46d9204a Improve suggestion for $-prefixed fragment specifiers 2026-04-24 14:59:01 -04:00
Trevor Gross 6c683adbdf Rollup merge of #153482 - DanielEScherzer:test-references-macros, r=ehuss
tests/ui/macros: add annotations for reference rules
2026-04-23 20:32:48 -04:00
Guillaume Gomez abce9f98d7 Rollup merge of #155442 - CoCo-Japan-pan:impl-restriction-reorder, r=Urgau,fmease,jhpratt
Change keyword order for `impl` restrictions

Based on rust-lang/rust#155222, this PR reorders keywords in trait definitions to group restrictions with visibility. It changes the order from `pub(...) const unsafe auto impl(...) trait Foo {...}`  to `pub(...) impl(...) const unsafe auto trait Foo {...}`.

Tracking issue for restrictions: rust-lang/rust#105077

r? @Urgau
cc @jhpratt
2026-04-23 14:42:47 +02:00
Daniel Scherzer 05485026ad tests/ui/macros: add annotations for reference rules 2026-04-21 15:46:04 -07:00
Jonathan Brouwer 13b537002b Rollup merge of #155475 - cijiugechu:missing-tokens, r=jieyouxu
Make reparsed guard metavars collect tokens

This should avoid missing tokens.

Closes rust-lang/rust#155333
2026-04-20 18:57:03 +02:00
cijiugechu f6294883f8 Make reparsed guard metavars collect tokens 2026-04-20 13:36:27 +08:00
CoCo-Japan-pan 0e6efe57d7 Update UI tests 2026-04-19 16:38:04 +09:00
bors 18b439f84e Auto merge of #154605 - estebank:attr-suggest, r=jieyouxu
Make `span_suggestions` always verbose



`span_suggestions` is to provide mutually exclusive suggestions. When it was introduced, we made its behavior be that if a single suggestion is given to it, we present the suggestion inline, otherwise in patch format. Changing this to make all of its uses be verbose, as that is closer in intent of output.
2026-04-16 11:23:18 +00:00
Esteban Küber b849e10d38 Make span_suggestions always verbose
`span_suggestions` is to provide mutually exclusive suggestions. When it was introduced, we made its behavior be that if a single suggestion is given to it, we present the suggestion inline, otherwise in patch format. Changing this to make all of its uses be verbose, as that is closer in intent of output.
2026-04-15 01:38:14 +00:00
cyrgani e972232f27 reduce unnecessary allocations a bit 2026-04-14 11:16:32 +00:00
Jonathan Brouwer 49b5708d51 Rollup merge of #155182 - fmease:guard-exp-begins-guard, r=petrochenkov
Make the expansion of guard metavars begin guard non-terminals

While investigating something unrelated, I noticed a bug in the impl of unstable feature `macro_guard_matcher` (tracking issue: rust-lang/rust#153104). Namely, the following doesn't compile:

```rs
#![feature(macro_guard_matcher)]

macro_rules! a { ($guard:guard) => { b!($guard); }; }
macro_rules! b { ($guard:guard) => {}; }
a!(if true);
```

```
error: no rules expected `guard` metavariable
 --> src/lib.rs:3:41
  |
3 | macro_rules! a { ($guard:guard) => { b!($guard); }; }
  |                                         ^^^^^^ no rules expected this token in macro call
4 | macro_rules! b { ($guard:guard) => {}; }
  | -------------- when calling this macro
5 | a!(if true);
  | ----------- in this macro invocation
  |
note: while trying to match meta-variable `$guard:guard`
 --> src/lib.rs:4:19
  |
4 | macro_rules! b { ($guard:guard) => {}; }
  |                   ^^^^^^^^^^^^
  = note: this error originates in the macro `a` (in Nightly builds, run with -Z macro-backtrace for more info)
```

---

While I'm still skeptical of `guard` fragment specifiers in general (although I can't quite pinpoint why), I figured I should fix this issue.
2026-04-13 14:02:33 +02:00
León Orell Valerian Liehr fc2c72cb67 Make the expansion of guard metavars begin guard non-terminals 2026-04-12 03:18:56 +02:00
Folkert de Vries 6bcd172f5a add cfg(target_object_format = "...") 2026-04-11 14:12:39 +02:00
Jonathan Brouwer 0b7a11ff96 Rollup merge of #154615 - aryannrd:moving-issues, r=Kivooeo
Moving issues
2026-04-02 22:13:56 +02:00
León Orell Valerian Liehr 92fbfae16b Emit pre-expansion feature gate warning for item modifier default 2026-04-01 17:01:59 +02:00
yukang 6518de37d4 Skip suggestions pointing to extern macro def for assert_eq 2026-03-30 22:58:03 +08:00
Aryan Dubey c0e8750bea Added issue link and description to macro-const-stringify.rs 2026-03-29 21:22:14 -04:00
Aryan Dubey 16c3d975e0 Moved and renamed issue-38160 to macros/macro-const-stringify.rs 2026-03-29 21:19:32 -04:00
bors 1174f78409 Auto merge of #154014 - Unique-Usman:ua/decmacrounrepeatable2, r=estebank
rustc_expand: improve diagnostics for non-repeatable metavars



There was an initally opened pr which solve this issue here https://github.com/rust-lang/rust/pull/152679. It got merged but, there was a perf regression. And this new pr is opened to address the problem. The first did the computation of binding and matched_rule and then passed them as owned value down to `diagnostics::emit_frag_parse_err(` but, now this pr address the issue by passing `lhs` and `rules` as borrowed value to from_tts and the move the logic to `diagnostics::emit_frag_parse_err(`.

Fix https://github.com/rust-lang/rust/issues/47452.
2026-03-25 23:14:18 +00:00
Jonathan Brouwer a376772bc1 Rollup merge of #154112 - cyrgani:macros-folder, r=Kivooeo
some `tests/ui/macros` cleanup

Move most tests that do not run any code from `//@ run-pass` to `//@ check-pass` and merge the (outdated) `die-macro-*` tests into one file.
2026-03-25 19:52:57 +01:00
Jonathan Brouwer 6e3c17424d Rollup merge of #153702 - SpriteOvO:guard-matcher, r=davidtwco
Add macro matcher for `guard` fragment specifier

Tracking issue #153104

This PR implements a new `guard` macro matcher to match `if-let` guards (specifically [`MatchArmGuard`](https://github.com/rust-lang/reference/blob/50a1075e879be75aeec436252c84eef0fad489f4/src/expressions/match-expr.md#match-guards)). In the upcoming PR, we can use this new matcher in the `matches!` and `assert_matches!` macros to support their use with `if-let` guards. (see #152313)

The original `Expr` used to represent a guard has been wrapped in a new `Guard` type, allowing us to carry the span information of the leading `if` keyword. However, it might be even better to include the `if` keyword in the `Guard` type as well? I've left a FIXME comment in the code.
2026-03-25 19:52:50 +01:00
Usman Akinyemi ed4a1f8b80 rustc_expand: improve diagnostics for non-repeatable metavars
Co-authored-by: Esteban Küber <esteban@kuber.com.ar>
Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
2026-03-24 08:12:13 +05:30
Jonathan Brouwer b9f8e25f6e Rollup merge of #146961 - Jules-Bertholet:expr-cfg, r=JonathanBrouwer
Allow passing `expr` metavariable as `cfg` predicate

This PR allows expanding `expr` metavariables inside the configuration predicates of `cfg` and `cfg_attr` invocations.
For example, the following code will now compile:

```rust
macro_rules! mac {
    ($e:expr) => {
        #[cfg_attr($e, inline)]
        #[cfg($e)]
        fn func() {}

        #[cfg(not($e))]
        fn func() {
            panic!()
        }
    }
}

mac!(any(unix, feature = "foo"));
```

There is currently no `macro_rules` fragment specifier that can represent all valid `cfg` predicates. `meta` comes closest, but excludes `true` and `false`. By fixing that, this change makes it easier to write declarative macros that parse `cfg` or `cfg_attr` invocations, for example https://github.com/rust-lang/rust/pull/146281/.

@rustbot label T-lang needs-fcp A-attributes A-cfg A-macros
2026-03-21 00:42:47 +01:00
Jules Bertholet ab36d506d2 Address review comments 2026-03-20 18:48:38 -04:00
cyrgani 9ce6863063 merge die-macro tests into panic-macro-basic.rs 2026-03-19 14:40:33 +00:00
cyrgani adacd90f29 move many ui/macros tests from run- to check-pass 2026-03-19 14:37:13 +00:00
Stuart Cook 3cfde0efba Rollup merge of #154020 - aryannrd:move-issue-23891, r=JohnTitor
Moved tests/ui/issues/issue-23891.rs to tests/ui/macros/
2026-03-18 21:26:33 +11:00
Aryan Dubey fb885759e0 Added test description and a link to github page for the relevant issue to the test 2026-03-17 18:24:54 -04:00
Aryan Dubey a9838dd1ea Moved issue-23981 to tests/ui/macros 2026-03-17 18:16:09 -04:00
Jonathan Brouwer 270bca8608 Rollup merge of #153994 - cyrgani:no-invalid-test-dir, r=Kivooeo
move `tests/ui/invalid` tests to new folders

Just some renaming of tests to remove another vague directory.

r? @Kivooeo
2026-03-17 21:20:03 +01:00
cyrgani 72732f2013 move tests/ui/invalid tests to new folders 2026-03-17 10:07:52 +00:00
cyrgani 93584fd50f dissolve tests/ui/cross 2026-03-16 10:21:35 +00:00
cyrgani 6dcb85d55d remove several redundant tests 2026-03-15 20:39:11 +00:00
Jules Bertholet 7f83c784bd Allow passing expr metavariable as a cfg predicate 2026-03-15 13:44:14 -04:00
Asuna 9729bb2558 Add macro matcher for guard fragment specifier 2026-03-12 02:18:34 +00:00
Jonathan Brouwer 2d9fde77a8 Rollup merge of #153594 - reddevilmidzy:ui-refactor, r=JohnTitor,Kivooeo
Move some ui tests

> [!NOTE]
> I split the commits to make the review easier and to keep the git history easier to trace.

Renamed issue-xxx tests

`tests/ui/dyn-drop` -> `tests/ui/dyn-keyword`
`tests/ui/missing-trait-bounds` -> `tests/ui/trait-bound/missing-trait-bounds`
`tests/ui/recursion_limit` -> `tests/ui/recursion/recursion_limit`
`tests/ui/version` -> `tests/ui/compile-flags`

Reorganize `tests/ui/empty`
2026-03-09 11:49:26 +01:00
Redddy e63664773c Move some ui tests
* Move dyn-drop to dyn-keyword
* Reorganize `tests/ui/empty` into specific dirs

remove tests/ui/empty/empty-linkname.rs duplicate of tests/ui/error-codes/E0454.rs
* Move `missing-trait-bounds` to `trait-bound/missing-trait-bounds`
* bless traits/missing-trait-bounds tests
* Move `recursion_limit` to `recursion/recursion_limit`
* Move `version` to `compile-flags`
2026-03-09 09:11:06 +00:00
Guillaume Gomez 25c7798004 Create new Diagnostic type for panic calls without literals 2026-03-05 12:12:31 +01:00
Jonathan Brouwer 1c44dbd580 Rollup merge of #152164 - mu001999-contrib:lint/unused_features, r=JonathanBrouwer
Lint unused features

*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/152164)*

Fixes rust-lang/rust#44232
Fixes rust-lang/rust#151752

---

This PR records used features through query side effect, then reports unsued features finally.
2026-03-04 19:30:36 +01:00