From 9e0a27cfa9a35e35a9065a2802a9b1620639845d Mon Sep 17 00:00:00 2001 From: mu001999 Date: Fri, 9 Jan 2026 19:31:53 +0800 Subject: [PATCH 1/2] Emit error instead of delayed bug when meeting mismatch type for const tuple --- compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs | 5 +++-- .../const-generics/mgca/tuple_expr_arg_mismatch_type.rs | 8 ++++++++ .../mgca/tuple_expr_arg_mismatch_type.stderr | 8 ++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 tests/ui/const-generics/mgca/tuple_expr_arg_mismatch_type.rs create mode 100644 tests/ui/const-generics/mgca/tuple_expr_arg_mismatch_type.stderr diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index 1dd9bff425759..f3b4e7a9072c5 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -2502,11 +2502,12 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { let tcx = self.tcx(); let FeedConstTy::WithTy(ty) = feed else { - return Const::new_error_with_message(tcx, span, "unsupported const tuple"); + return Const::new_error_with_message(tcx, span, "const tuple lack type information"); }; let ty::Tuple(tys) = ty.kind() else { - return Const::new_error_with_message(tcx, span, "const tuple must have a tuple type"); + let e = tcx.dcx().span_err(span, format!("expected {}, found const tuple", ty)); + return Const::new_error(tcx, e); }; let exprs = exprs diff --git a/tests/ui/const-generics/mgca/tuple_expr_arg_mismatch_type.rs b/tests/ui/const-generics/mgca/tuple_expr_arg_mismatch_type.rs new file mode 100644 index 0000000000000..02807dfc302e8 --- /dev/null +++ b/tests/ui/const-generics/mgca/tuple_expr_arg_mismatch_type.rs @@ -0,0 +1,8 @@ +#![feature(min_generic_const_args)] +#![expect(incomplete_features)] + +pub fn takes_nested_tuple() { + takes_nested_tuple::<{ () }> //~ ERROR expected u32, found const tuple +} + +fn main() {} diff --git a/tests/ui/const-generics/mgca/tuple_expr_arg_mismatch_type.stderr b/tests/ui/const-generics/mgca/tuple_expr_arg_mismatch_type.stderr new file mode 100644 index 0000000000000..ad6db9e12373f --- /dev/null +++ b/tests/ui/const-generics/mgca/tuple_expr_arg_mismatch_type.stderr @@ -0,0 +1,8 @@ +error: expected u32, found const tuple + --> $DIR/tuple_expr_arg_mismatch_type.rs:5:28 + | +LL | takes_nested_tuple::<{ () }> + | ^^ + +error: aborting due to 1 previous error + From 8ca1c9eb8fb16c97892a9628a6f94466d54ba24a Mon Sep 17 00:00:00 2001 From: mu001999 Date: Fri, 9 Jan 2026 19:32:23 +0800 Subject: [PATCH 2/2] Rename tests for const tuple properly --- compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs | 2 +- ...rg_tuple_expr_complex.rs => tuple_expr_arg_complex.rs} | 0 ..._expr_complex.stderr => tuple_expr_arg_complex.stderr} | 8 ++++---- .../const-generics/mgca/tuple_expr_arg_mismatch_type.rs | 2 +- .../mgca/tuple_expr_arg_mismatch_type.stderr | 2 +- ..._arg_tuple_expr_simple.rs => tuple_expr_arg_simple.rs} | 0 6 files changed, 7 insertions(+), 7 deletions(-) rename tests/ui/const-generics/mgca/{adt_expr_arg_tuple_expr_complex.rs => tuple_expr_arg_complex.rs} (100%) rename tests/ui/const-generics/mgca/{adt_expr_arg_tuple_expr_complex.stderr => tuple_expr_arg_complex.stderr} (77%) rename tests/ui/const-generics/mgca/{adt_expr_arg_tuple_expr_simple.rs => tuple_expr_arg_simple.rs} (100%) diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index f3b4e7a9072c5..4f610d2512a43 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -2506,7 +2506,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { }; let ty::Tuple(tys) = ty.kind() else { - let e = tcx.dcx().span_err(span, format!("expected {}, found const tuple", ty)); + let e = tcx.dcx().span_err(span, format!("expected `{}`, found const tuple", ty)); return Const::new_error(tcx, e); }; diff --git a/tests/ui/const-generics/mgca/adt_expr_arg_tuple_expr_complex.rs b/tests/ui/const-generics/mgca/tuple_expr_arg_complex.rs similarity index 100% rename from tests/ui/const-generics/mgca/adt_expr_arg_tuple_expr_complex.rs rename to tests/ui/const-generics/mgca/tuple_expr_arg_complex.rs diff --git a/tests/ui/const-generics/mgca/adt_expr_arg_tuple_expr_complex.stderr b/tests/ui/const-generics/mgca/tuple_expr_arg_complex.stderr similarity index 77% rename from tests/ui/const-generics/mgca/adt_expr_arg_tuple_expr_complex.stderr rename to tests/ui/const-generics/mgca/tuple_expr_arg_complex.stderr index dbc64a1bf59d3..b294e1032ce8f 100644 --- a/tests/ui/const-generics/mgca/adt_expr_arg_tuple_expr_complex.stderr +++ b/tests/ui/const-generics/mgca/tuple_expr_arg_complex.stderr @@ -1,23 +1,23 @@ error: complex const arguments must be placed inside of a `const` block - --> $DIR/adt_expr_arg_tuple_expr_complex.rs:13:25 + --> $DIR/tuple_expr_arg_complex.rs:13:25 | LL | takes_tuple::<{ (N, N + 1) }>(); | ^^^^^ error: complex const arguments must be placed inside of a `const` block - --> $DIR/adt_expr_arg_tuple_expr_complex.rs:14:25 + --> $DIR/tuple_expr_arg_complex.rs:14:25 | LL | takes_tuple::<{ (N, T::ASSOC + 1) }>(); | ^^^^^^^^^^^^ error: complex const arguments must be placed inside of a `const` block - --> $DIR/adt_expr_arg_tuple_expr_complex.rs:16:36 + --> $DIR/tuple_expr_arg_complex.rs:16:36 | LL | takes_nested_tuple::<{ (N, (N, N + 1)) }>(); | ^^^^^ error: generic parameters may not be used in const operations - --> $DIR/adt_expr_arg_tuple_expr_complex.rs:17:44 + --> $DIR/tuple_expr_arg_complex.rs:17:44 | LL | takes_nested_tuple::<{ (N, (N, const { N + 1 })) }>(); | ^ diff --git a/tests/ui/const-generics/mgca/tuple_expr_arg_mismatch_type.rs b/tests/ui/const-generics/mgca/tuple_expr_arg_mismatch_type.rs index 02807dfc302e8..95acd66074f6f 100644 --- a/tests/ui/const-generics/mgca/tuple_expr_arg_mismatch_type.rs +++ b/tests/ui/const-generics/mgca/tuple_expr_arg_mismatch_type.rs @@ -2,7 +2,7 @@ #![expect(incomplete_features)] pub fn takes_nested_tuple() { - takes_nested_tuple::<{ () }> //~ ERROR expected u32, found const tuple + takes_nested_tuple::<{ () }> //~ ERROR expected `u32`, found const tuple } fn main() {} diff --git a/tests/ui/const-generics/mgca/tuple_expr_arg_mismatch_type.stderr b/tests/ui/const-generics/mgca/tuple_expr_arg_mismatch_type.stderr index ad6db9e12373f..dfbd294951fdc 100644 --- a/tests/ui/const-generics/mgca/tuple_expr_arg_mismatch_type.stderr +++ b/tests/ui/const-generics/mgca/tuple_expr_arg_mismatch_type.stderr @@ -1,4 +1,4 @@ -error: expected u32, found const tuple +error: expected `u32`, found const tuple --> $DIR/tuple_expr_arg_mismatch_type.rs:5:28 | LL | takes_nested_tuple::<{ () }> diff --git a/tests/ui/const-generics/mgca/adt_expr_arg_tuple_expr_simple.rs b/tests/ui/const-generics/mgca/tuple_expr_arg_simple.rs similarity index 100% rename from tests/ui/const-generics/mgca/adt_expr_arg_tuple_expr_simple.rs rename to tests/ui/const-generics/mgca/tuple_expr_arg_simple.rs