Rollup merge of #152565 - Kivooeo:ctor-diag, r=BoxyUwU

fix missleading error for tuple ctor

r? BoxyUwU

fixes https://github.com/rust-lang/rust/issues/151414
This commit is contained in:
Jonathan Brouwer 2026-02-13 13:35:04 +01:00 committed by GitHub
commit d93a38a488
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 12 additions and 5 deletions

View file

@ -2465,7 +2465,13 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
let parent_did = tcx.parent(*def_id);
(tcx.adt_def(parent_did), fn_args, parent_did)
}
_ => return non_adt_or_variant_res(),
_ => {
let e = self.dcx().span_err(
span,
"complex const arguments must be placed inside of a `const` block",
);
return Const::new_error(tcx, e);
}
};
let variant_def = adt_def.variant_with_id(variant_did);

View file

@ -4,9 +4,10 @@
fn foo<T>() {
[0; size_of::<*mut T>()];
//~^ ERROR: tuple constructor with invalid base path
//~^ ERROR: complex const arguments must be placed inside of a `const` block
[0; const { size_of::<*mut T>() }];
//~^ ERROR: generic parameters may not be used in const operations
[0; const { size_of::<*mut i32>() }];
}
fn main() {}

View file

@ -1,4 +1,4 @@
error: tuple constructor with invalid base path
error: complex const arguments must be placed inside of a `const` block
--> $DIR/size-of-generic-ptr-in-array-len.rs:6:9
|
LL | [0; size_of::<*mut T>()];

View file

@ -32,7 +32,7 @@ fn test_errors<const N: usize>() {
//~| ERROR tuple constructor with invalid base path
accepts_point::<{ non_ctor(N, N) }>();
//~^ ERROR tuple constructor with invalid base path
//~^ ERROR complex const arguments must be placed inside of a `const` block
accepts_point::<{ CONST_ITEM(N, N) }>();
//~^ ERROR tuple constructor with invalid base path

View file

@ -27,7 +27,7 @@ error: tuple constructor with invalid base path
LL | accepts_point::<{ UnresolvedIdent(N, N) }>();
| ^^^^^^^^^^^^^^^^^^^^^
error: tuple constructor with invalid base path
error: complex const arguments must be placed inside of a `const` block
--> $DIR/tuple_ctor_erroneous.rs:34:23
|
LL | accepts_point::<{ non_ctor(N, N) }>();