Skip to content

Conversation

@Shinonn23
Copy link

@Shinonn23 Shinonn23 commented Dec 5, 2025

This PR fixes the ICE reported in #148138

The root cause is that const blocks aren’t allowed in pattern position, but the AST lowering logic still attempted to create PatExprKind::ConstBlock. That allowed invalid HIR to reach type checking, which then hit a span_bug!.

Following the discussion in the issue, this patch removes the ConstBlock lowering path from lower_expr_within_pat.
Any ExprKind::ConstBlock inside a pattern now lowers to PatKind::Err, consistent with how other invalid pattern expressions are handled.

A new UI test is included to ensure the compiler emits a proper error for const blocks in patterns and to prevent regressions.

Closes #148138

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 5, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 5, 2025

r? @SparrowLii

rustbot has assigned @SparrowLii.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@Shinonn23 Shinonn23 force-pushed the fix-ice-constblock-148138 branch from dd08ea6 to b713916 Compare December 5, 2025 05:38
@dianne
Copy link
Contributor

dianne commented Dec 5, 2025

r? dianne

@rustbot rustbot assigned dianne and unassigned SparrowLii Dec 5, 2025
@Shinonn23 Shinonn23 force-pushed the fix-ice-constblock-148138 branch from b713916 to 8a0d87b Compare December 5, 2025 07:22
@rustbot
Copy link
Collaborator

rustbot commented Dec 5, 2025

rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead.

cc @rust-lang/rust-analyzer

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred in match checking

cc @Nadrieril

@rustbot rustbot added T-clippy Relevant to the Clippy team. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue. labels Dec 5, 2025
@rustbot

This comment has been minimized.

@Shinonn23 Shinonn23 force-pushed the fix-ice-constblock-148138 branch from 8a0d87b to e412043 Compare December 5, 2025 07:25
@rustbot

This comment has been minimized.

@Shinonn23 Shinonn23 force-pushed the fix-ice-constblock-148138 branch from e412043 to 3d5438d Compare December 5, 2025 07:26
Copy link
Member

@Veykril Veykril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not need to touch rust-analyzer source

View changes since this review

@Shinonn23 Shinonn23 force-pushed the fix-ice-constblock-148138 branch 2 times, most recently from 5260fe6 to d217779 Compare December 5, 2025 07:54
@rust-log-analyzer

This comment has been minimized.

@jieyouxu jieyouxu closed this Dec 5, 2025
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 5, 2025
@jieyouxu jieyouxu reopened this Dec 5, 2025
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 5, 2025
@Shinonn23 Shinonn23 force-pushed the fix-ice-constblock-148138 branch 2 times, most recently from 85231c0 to 37c37ed Compare December 5, 2025 11:12
@rust-log-analyzer

This comment has been minimized.

@Shinonn23 Shinonn23 force-pushed the fix-ice-constblock-148138 branch from 37c37ed to 73dfb1d Compare December 7, 2025 08:39
Copy link
Contributor

@dianne dianne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good now, thanks! Just a few more notes.
@rustbot author

View changes since this review

Comment on lines 5 to 7
| ^^^^^^^^^
|
= help: use a named `const`-item or an `if`-guard (`x if x == const { ... }`) instead
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice to keep this help message around. Could you add it to the ArbitraryExpressionInPattern error emitted during AST lowering? There's an optional pattern_from_macro_note note on it already, so you can use that as a reference (except making it a help rather than a note). We could also use the const blocks cannot be used as patterns message in that case too, but I could go either way on that; arbitrary expressions aren't allowed in patterns seems fine enough to me.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 7, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 7, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

… HIR

This fixes the reported ICE by explicitly rejecting `const` blocks
in patterns during AST lowering.

Additionally, performs complete cleanup:
- Removed `PatExprKind::ConstBlock` from HIR.
- Removed `Pat::ConstBlockPat` from Rust Analyzer.
- Cleaned up Clippy and other tools.
@Shinonn23 Shinonn23 force-pushed the fix-ice-constblock-148138 branch from 73dfb1d to 45c1507 Compare December 8, 2025 03:45
@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu-llvm-20-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
diff of stderr:

5    |        ^
6    |
7    = note: the `expr` fragment specifier forces the metavariable's content to be an expression
+    = help: use a named `const`-item or an `if`-guard (`x if x == const { ... }`) instead
8 
9 error: arbitrary expressions aren't allowed in patterns
10   --> $DIR/issue-43250.rs:11:8

13    |        ^
14    |
15    = note: the `expr` fragment specifier forces the metavariable's content to be an expression
+    = help: use a named `const`-item or an `if`-guard (`x if x == const { ... }`) instead
16 
17 error: aborting due to 2 previous errors
18 


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args issues/issue-43250.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/issues/issue-43250.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/issues/issue-43250" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error: arbitrary expressions aren't allowed in patterns
##[error]  --> /checkout/tests/ui/issues/issue-43250.rs:9:8
   |
LL |     m!(y);
   |        ^
   |
   = note: the `expr` fragment specifier forces the metavariable's content to be an expression
   = help: use a named `const`-item or an `if`-guard (`x if x == const { ... }`) instead

error: arbitrary expressions aren't allowed in patterns
##[error]  --> /checkout/tests/ui/issues/issue-43250.rs:11:8
   |
LL |     m!(C);
   |        ^
   |
   = note: the `expr` fragment specifier forces the metavariable's content to be an expression
   = help: use a named `const`-item or an `if`-guard (`x if x == const { ... }`) instead

error: aborting due to 2 previous errors
------------------------------------------

---- [ui] tests/ui/issues/issue-43250.rs stdout end ----
---- [ui] tests/ui/lowering/expr-in-pat-issue-99380.rs stdout ----
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/lowering/expr-in-pat-issue-99380/expr-in-pat-issue-99380.stderr`
diff of stderr:

5    |          ^^^^^^^
6    |
7    = note: the `expr` fragment specifier forces the metavariable's content to be an expression
+    = help: use a named `const`-item or an `if`-guard (`x if x == const { ... }`) instead
8 
9 error: aborting due to 1 previous error
10 


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args lowering/expr-in-pat-issue-99380.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/lowering/expr-in-pat-issue-99380.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/lowering/expr-in-pat-issue-99380" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error: arbitrary expressions aren't allowed in patterns
##[error]  --> /checkout/tests/ui/lowering/expr-in-pat-issue-99380.rs:10:10
   |
LL |     foo!(Some(3)); //~ ERROR arbitrary expressions aren't allowed in patterns
   |          ^^^^^^^
   |
   = note: the `expr` fragment specifier forces the metavariable's content to be an expression
   = help: use a named `const`-item or an `if`-guard (`x if x == const { ... }`) instead

error: aborting due to 1 previous error
------------------------------------------

---- [ui] tests/ui/lowering/expr-in-pat-issue-99380.rs stdout end ----
---- [ui] tests/ui/match/expr_before_ident_pat.rs stdout ----
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/match/expr_before_ident_pat/expr_before_ident_pat.stderr`
diff of stderr:

11    |            ^
12    |
13    = note: the `expr` fragment specifier forces the metavariable's content to be an expression
+    = help: use a named `const`-item or an `if`-guard (`x if x == const { ... }`) instead
14 
15 error: aborting due to 2 previous errors
16 


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args match/expr_before_ident_pat.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/match/expr_before_ident_pat.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/match/expr_before_ident_pat" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error[E0425]: cannot find value `a` in this scope
##[error]  --> /checkout/tests/ui/match/expr_before_ident_pat.rs:10:12
   |
LL |     funny!(a, a);
   |            ^ not found in this scope

error: arbitrary expressions aren't allowed in patterns
##[error]  --> /checkout/tests/ui/match/expr_before_ident_pat.rs:10:12
   |
LL |     funny!(a, a);
   |            ^
   |
   = note: the `expr` fragment specifier forces the metavariable's content to be an expression
   = help: use a named `const`-item or an `if`-guard (`x if x == const { ... }`) instead

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0425`.
------------------------------------------

---- [ui] tests/ui/match/expr_before_ident_pat.rs stdout end ----
---- [ui] tests/ui/pattern/deref-patterns/ice-adjust-mode-unimplemented-for-constblock.rs stdout ----
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/pattern/deref-patterns/ice-adjust-mode-unimplemented-for-constblock/ice-adjust-mode-unimplemented-for-constblock.stderr`
diff of stderr:

23    |
24 LL |     let vec![const { vec![] }]: Vec<usize> = vec![];
25    |              ^^^^^^^^^^^^^^^^
+    |
+    = help: use a named `const`-item or an `if`-guard (`x if x == const { ... }`) instead
26 
27 error[E0164]: expected tuple struct or tuple variant, found associated function `<[_]>::into_vec`
28   --> $DIR/ice-adjust-mode-unimplemented-for-constblock.rs:5:9


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args pattern/deref-patterns/ice-adjust-mode-unimplemented-for-constblock.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/pattern/deref-patterns/ice-adjust-mode-unimplemented-for-constblock.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/pattern/deref-patterns/ice-adjust-mode-unimplemented-for-constblock" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error[E0532]: expected a pattern, found a function call
##[error]  --> /checkout/tests/ui/pattern/deref-patterns/ice-adjust-mode-unimplemented-for-constblock.rs:5:9
   |
LL |     let vec![const { vec![] }]: Vec<usize> = vec![];
   |         ^^^^^^^^^^^^^^^^^^^^^^ not a tuple struct or tuple variant
   |
   = note: function calls are not allowed in patterns: <https://doc.rust-lang.org/book/ch19-00-patterns.html>
   = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0658]: usage of qualified paths in this context is experimental
##[error]  --> /checkout/tests/ui/pattern/deref-patterns/ice-adjust-mode-unimplemented-for-constblock.rs:5:9
   |
LL |     let vec![const { vec![] }]: Vec<usize> = vec![];
   |         ^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: see issue #86935 <https://github.com/rust-lang/rust/issues/86935> for more information
   = help: add `#![feature(more_qualified_paths)]` to the crate attributes to enable
   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
   = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)

error: arbitrary expressions aren't allowed in patterns
##[error]  --> /checkout/tests/ui/pattern/deref-patterns/ice-adjust-mode-unimplemented-for-constblock.rs:5:14
   |
LL |     let vec![const { vec![] }]: Vec<usize> = vec![];
   |              ^^^^^^^^^^^^^^^^
   |
   = help: use a named `const`-item or an `if`-guard (`x if x == const { ... }`) instead

error[E0164]: expected tuple struct or tuple variant, found associated function `<[_]>::into_vec`
##[error]  --> /checkout/tests/ui/pattern/deref-patterns/ice-adjust-mode-unimplemented-for-constblock.rs:5:9
   |
LL |     let vec![const { vec![] }]: Vec<usize> = vec![];
   |         ^^^^^^^^^^^^^^^^^^^^^^ `fn` calls are not allowed in patterns
   |
   = help: for more information, visit https://doc.rust-lang.org/book/ch19-00-patterns.html
   = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 4 previous errors
---
diff of stderr:

8    |                               ----------- in this macro invocation
9    |
10    = note: the `expr` fragment specifier forces the metavariable's content to be an expression
+    = help: use a named `const`-item or an `if`-guard (`x if x == const { ... }`) instead
11    = note: this error originates in the macro `make_vec` (in Nightly builds, run with -Z macro-backtrace for more info)
12 
13 error: arbitrary expressions aren't allowed in patterns

20    |                         ----------- in this macro invocation
21    |
22    = note: the `expr` fragment specifier forces the metavariable's content to be an expression
+    = help: use a named `const`-item or an `if`-guard (`x if x == const { ... }`) instead
23    = note: this error originates in the macro `make_pat` (in Nightly builds, run with -Z macro-backtrace for more info)
24 
25 error: arbitrary expressions aren't allowed in patterns

32    |                         ----------- in this macro invocation
33    |
34    = note: the `expr` fragment specifier forces the metavariable's content to be an expression
+    = help: use a named `const`-item or an `if`-guard (`x if x == const { ... }`) instead
35    = note: this error originates in the macro `make_pat` (in Nightly builds, run with -Z macro-backtrace for more info)
36 
37 error: aborting due to 3 previous errors


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args pattern/issue-92074-macro-ice.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/pattern/issue-92074-macro-ice.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/pattern/issue-92074-macro-ice" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error: arbitrary expressions aren't allowed in patterns
##[error]  --> /checkout/tests/ui/pattern/issue-92074-macro-ice.rs:18:25
   |
LL |     () => { force_expr!(Vec::new()) } //~ ERROR arbitrary expressions aren't allowed
   |                         ^^^^^^^^^^
...
LL |     assert!(matches!(x, En::A(make_vec!())));
   |                               ----------- in this macro invocation
   |
   = note: the `expr` fragment specifier forces the metavariable's content to be an expression
   = help: use a named `const`-item or an `if`-guard (`x if x == const { ... }`) instead
   = note: this error originates in the macro `make_vec` (in Nightly builds, run with -Z macro-backtrace for more info)

error: arbitrary expressions aren't allowed in patterns
##[error]  --> /checkout/tests/ui/pattern/issue-92074-macro-ice.rs:22:24
   |
LL |     () => { force_pat!(get_usize(), get_usize()) }
   |                        ^^^^^^^^^^^
...
LL |     assert!(matches!(5, make_pat!()));
   |                         ----------- in this macro invocation
   |
   = note: the `expr` fragment specifier forces the metavariable's content to be an expression
   = help: use a named `const`-item or an `if`-guard (`x if x == const { ... }`) instead
   = note: this error originates in the macro `make_pat` (in Nightly builds, run with -Z macro-backtrace for more info)

error: arbitrary expressions aren't allowed in patterns
##[error]  --> /checkout/tests/ui/pattern/issue-92074-macro-ice.rs:22:37
   |
LL |     () => { force_pat!(get_usize(), get_usize()) }
   |                                     ^^^^^^^^^^^
...
LL |     assert!(matches!(5, make_pat!()));
   |                         ----------- in this macro invocation
   |
   = note: the `expr` fragment specifier forces the metavariable's content to be an expression
   = help: use a named `const`-item or an `if`-guard (`x if x == const { ... }`) instead
   = note: this error originates in the macro `make_pat` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 3 previous errors
------------------------------------------

---- [ui] tests/ui/pattern/issue-92074-macro-ice.rs stdout end ----
---
3    |
4 LL |     Arith = 1 + 1,
5    |             ^^^^^
+    |
+    = help: use a named `const`-item or an `if`-guard (`x if x == const { ... }`) instead
6 
7 error: arbitrary expressions aren't allowed in patterns
8   --> $DIR/patkind-litrange-no-expr.rs:20:13

10 LL |     Arith = 1 + 1,
11    |             ^^^^^
12    |
+    = help: use a named `const`-item or an `if`-guard (`x if x == const { ... }`) instead
13    = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
14 
15 error: aborting due to 2 previous errors


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args pattern/patkind-litrange-no-expr.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/pattern/patkind-litrange-no-expr.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/pattern/patkind-litrange-no-expr" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error: arbitrary expressions aren't allowed in patterns
##[error]  --> /checkout/tests/ui/pattern/patkind-litrange-no-expr.rs:20:13
   |
LL |     Arith = 1 + 1, //~ ERROR arbitrary expressions aren't allowed in patterns
   |             ^^^^^
   |
   = help: use a named `const`-item or an `if`-guard (`x if x == const { ... }`) instead

error: arbitrary expressions aren't allowed in patterns
##[error]  --> /checkout/tests/ui/pattern/patkind-litrange-no-expr.rs:20:13
   |
LL |     Arith = 1 + 1, //~ ERROR arbitrary expressions aren't allowed in patterns
   |             ^^^^^
   |
   = help: use a named `const`-item or an `if`-guard (`x if x == const { ... }`) instead
   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 2 previous errors
------------------------------------------

---- [ui] tests/ui/pattern/patkind-litrange-no-expr.rs stdout end ----

let guar = self.dcx().emit_err(ArbitraryExpressionInPattern {
span,
pattern_from_macro_note: pattern_from_macro,
arbitrary_expression_in_pattern_help: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the help message is specific to const blocks, it should only show up if the AST expression being lowered is actually a const block. It might be helpful to name its corresponding field as such too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ICE adjust mode unimplemented for ConstBlock

8 participants