Skip to content
Merged
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
8 changes: 7 additions & 1 deletion compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Original file line number Diff line number Diff line change
@@ -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>()];
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/const-generics/mgca/tuple_ctor_erroneous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/const-generics/mgca/tuple_ctor_erroneous.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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) }>();
Expand Down
Loading