Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/rustc_middle/src/mir/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ impl<'tcx> Const<'tcx> {
) -> Result<ConstValue, ErrorHandled> {
match self {
Const::Ty(_, c) => {
if let Err(e) = c.error_reported() {
return Err(ReportedErrorInfo::non_const_eval_error(e).into());
}

// FIXME(generic_const_exprs): We shouldn't encounter placeholders here
// and could change this to ICE when encountering them instead.
if c.has_non_region_param() || c.has_non_region_placeholders() {
Expand Down
7 changes: 0 additions & 7 deletions tests/crashes/150969.rs

This file was deleted.

14 changes: 14 additions & 0 deletions tests/ui/const-generics/mgca/none-as-usize-const-arg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Regression test for https://github.com/rust-lang/rust/issues/150969

#![feature(generic_const_exprs)]
#![feature(min_generic_const_args)]

fn pass_enum<const N: usize, const M: usize = const { N }> {
//~^ ERROR: missing parameters for function definition
//~| ERROR: defaults for generic parameters are not allowed here
//~| ERROR: overly complex generic constant
pass_enum::<{ core::direct_const_arg!(None) }>
//~^ ERROR: missing generics for enum `Option` [E0107]
}

fn main() {}
40 changes: 40 additions & 0 deletions tests/ui/const-generics/mgca/none-as-usize-const-arg.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
error: missing parameters for function definition
--> $DIR/none-as-usize-const-arg.rs:6:59
|
LL | fn pass_enum<const N: usize, const M: usize = const { N }> {
| ^
|
help: add a parameter list
|
LL | fn pass_enum<const N: usize, const M: usize = const { N }>() {
| ++

error: defaults for generic parameters are not allowed here
--> $DIR/none-as-usize-const-arg.rs:6:30
|
LL | fn pass_enum<const N: usize, const M: usize = const { N }> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0107]: missing generics for enum `Option`
--> $DIR/none-as-usize-const-arg.rs:10:43
|
LL | pass_enum::<{ core::direct_const_arg!(None) }>
| ^^^^ expected 1 generic argument
|
help: add missing generic argument
|
LL | pass_enum::<{ core::direct_const_arg!(None<T>) }>
| +++

error: overly complex generic constant
--> $DIR/none-as-usize-const-arg.rs:6:47
|
LL | fn pass_enum<const N: usize, const M: usize = const { N }> {
| ^^^^^^^^^^^ const blocks are not supported in generic constants
|
= help: consider moving this anonymous constant into a `const` function
= note: this operation may be supported in the future

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0107`.
14 changes: 14 additions & 0 deletions tests/ui/const-generics/mgca/type_const-adt-expr-missing-field.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Regression test for https://github.com/rust-lang/rust/issues/154632

#![feature(generic_const_exprs)]
#![feature(min_generic_const_args)]
#![feature(macroless_generic_const_args)]
#![feature(generic_const_items)]

type const ADD1<const N: usize>: usize = const { N + 1 };
//~^ ERROR: unconstrained generic constant
type const AliasFnUnused: ADD1 = ADD1::<{ Some::<usize> {} }>;
//~^ ERROR: cannot find type `ADD1` in this scope [E0573]
//~| ERROR: struct expression with missing field initialiser for `0`

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
error[E0573]: cannot find type `ADD1` in this scope
--> $DIR/type_const-adt-expr-missing-field.rs:10:27
|
LL | type const AliasFnUnused: ADD1 = ADD1::<{ Some::<usize> {} }>;
| ^^^^ not found in this scope
|
= note: a constant named `ADD1` exists in another namespace

error: unconstrained generic constant
--> $DIR/type_const-adt-expr-missing-field.rs:8:1
|
LL | type const ADD1<const N: usize>: usize = const { N + 1 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: try adding a `where` bound
|
LL | type const ADD1<const N: usize>: usize where [(); const { N + 1 }]: = const { N + 1 };
| ++++++++++++++++++++++++++++

error: struct expression with missing field initialiser for `0`
--> $DIR/type_const-adt-expr-missing-field.rs:10:43
|
LL | type const AliasFnUnused: ADD1 = ADD1::<{ Some::<usize> {} }>;
| ^^^^^^^^^^^^^^^^

error: aborting due to 3 previous errors

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

@lapla-cogito lapla-cogito Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The case reported in the original issue goes through lower_const_arg_struct(). I found that a similar ICE can also occur through lower_const_arg_tuple_call(), and this serves as a regression test for that case.

View changes since the review

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#![feature(generic_const_exprs)]
#![feature(min_generic_const_args)]
#![feature(macroless_generic_const_args)]
#![feature(adt_const_params)]
#![feature(generic_const_items)]

use std::marker::ConstParamTy;

#[derive(Eq, PartialEq, ConstParamTy)]
struct Wrap(usize);

type const ADD1<const N: usize>: usize = const { N + 1 };
//~^ ERROR: unconstrained generic constant
type const AliasFnUnused: ADD1 = ADD1::<{ Wrap(Some::<usize> {}) }>;
//~^ ERROR: cannot find type `ADD1` in this scope [E0573]
//~| ERROR: struct expression with missing field initialiser for `0`

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
error[E0573]: cannot find type `ADD1` in this scope
--> $DIR/type_const-tuple-call-expr-missing-field.rs:14:27
|
LL | type const AliasFnUnused: ADD1 = ADD1::<{ Wrap(Some::<usize> {}) }>;
| ^^^^ not found in this scope
|
= note: a constant named `ADD1` exists in another namespace

error: unconstrained generic constant
--> $DIR/type_const-tuple-call-expr-missing-field.rs:12:1
|
LL | type const ADD1<const N: usize>: usize = const { N + 1 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: try adding a `where` bound
|
LL | type const ADD1<const N: usize>: usize where [(); const { N + 1 }]: = const { N + 1 };
| ++++++++++++++++++++++++++++

error: struct expression with missing field initialiser for `0`
--> $DIR/type_const-tuple-call-expr-missing-field.rs:14:48
|
LL | type const AliasFnUnused: ADD1 = ADD1::<{ Wrap(Some::<usize> {}) }>;
| ^^^^^^^^^^^^^^^^

error: aborting due to 3 previous errors

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