| ... | ... | @@ -20923,7 +20923,7 @@ fn zirReify( |
| 20923 | 20923 | break :msg msg; |
| 20924 | 20924 | }; |
| 20925 | 20925 | return sema.failWithOwnedErrorMsg(block, msg); |
| 20926 | | } else if (layout == .Packed and !(validatePackedType(field_ty, mod))) { |
| 20926 | } else if (layout == .Packed and !try sema.validatePackedType(field_ty)) { |
| 20927 | 20927 | const msg = msg: { |
| 20928 | 20928 | const msg = try sema.errMsg(block, src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); |
| 20929 | 20929 | errdefer msg.destroy(gpa); |
| ... | ... | @@ -21290,7 +21290,7 @@ fn reifyStruct( |
| 21290 | 21290 | break :msg msg; |
| 21291 | 21291 | }; |
| 21292 | 21292 | return sema.failWithOwnedErrorMsg(block, msg); |
| 21293 | | } else if (layout == .Packed and !(validatePackedType(field_ty, mod))) { |
| 21293 | } else if (layout == .Packed and !try sema.validatePackedType(field_ty)) { |
| 21294 | 21294 | const msg = msg: { |
| 21295 | 21295 | const msg = try sema.errMsg(block, src, "packed structs cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)}); |
| 21296 | 21296 | errdefer msg.destroy(gpa); |
| ... | ... | @@ -25663,8 +25663,9 @@ fn explainWhyTypeIsNotExtern( |
| 25663 | 25663 | } |
| 25664 | 25664 | |
| 25665 | 25665 | /// Returns true if `ty` is allowed in packed types. |
| 25666 | | /// Does *NOT* require `ty` to be resolved in any way. |
| 25667 | | fn validatePackedType(ty: Type, mod: *Module) bool { |
| 25666 | /// Does not require `ty` to be resolved in any way, but may resolve whether it is comptime-only. |
| 25667 | fn validatePackedType(sema: *Sema, ty: Type) !bool { |
| 25668 | const mod = sema.mod; |
| 25668 | 25669 | switch (ty.zigTypeTag(mod)) { |
| 25669 | 25670 | .Type, |
| 25670 | 25671 | .ComptimeFloat, |
| ... | ... | @@ -25689,7 +25690,7 @@ fn validatePackedType(ty: Type, mod: *Module) bool { |
| 25689 | 25690 | .Vector, |
| 25690 | 25691 | .Enum, |
| 25691 | 25692 | => return true, |
| 25692 | | .Pointer => return !ty.isSlice(mod), |
| 25693 | .Pointer => return !ty.isSlice(mod) and !try sema.typeRequiresComptime(ty), |
| 25693 | 25694 | .Struct, .Union => return ty.containerLayout(mod) == .Packed, |
| 25694 | 25695 | } |
| 25695 | 25696 | } |
| ... | ... | @@ -25724,7 +25725,12 @@ fn explainWhyTypeIsNotPacked( |
| 25724 | 25725 | .Optional, |
| 25725 | 25726 | .Array, |
| 25726 | 25727 | => try mod.errNoteNonLazy(src_loc, msg, "type has no guaranteed in-memory representation", .{}), |
| 25727 | | .Pointer => try mod.errNoteNonLazy(src_loc, msg, "slices have no guaranteed in-memory representation", .{}), |
| 25728 | .Pointer => if (ty.isSlice(mod)) { |
| 25729 | try mod.errNoteNonLazy(src_loc, msg, "slices have no guaranteed in-memory representation", .{}); |
| 25730 | } else { |
| 25731 | try mod.errNoteNonLazy(src_loc, msg, "comptime-only pointer has no guaranteed in-memory representation", .{}); |
| 25732 | try sema.explainWhyTypeIsComptime(msg, src_loc, ty); |
| 25733 | }, |
| 25728 | 25734 | .Fn => { |
| 25729 | 25735 | try mod.errNoteNonLazy(src_loc, msg, "type has no guaranteed in-memory representation", .{}); |
| 25730 | 25736 | try mod.errNoteNonLazy(src_loc, msg, "use '*const ' to make a function pointer type", .{}); |
| ... | ... | @@ -35890,7 +35896,7 @@ fn semaStructFields( |
| 35890 | 35896 | }; |
| 35891 | 35897 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 35892 | 35898 | }, |
| 35893 | | .Packed => if (!validatePackedType(field_ty, mod)) { |
| 35899 | .Packed => if (!try sema.validatePackedType(field_ty)) { |
| 35894 | 35900 | const msg = msg: { |
| 35895 | 35901 | const ty_src = mod.fieldSrcLoc(decl_index, .{ |
| 35896 | 35902 | .index = field_i, |
| ... | ... | @@ -36443,7 +36449,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un |
| 36443 | 36449 | break :msg msg; |
| 36444 | 36450 | }; |
| 36445 | 36451 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 36446 | | } else if (layout == .Packed and !validatePackedType(field_ty, mod)) { |
| 36452 | } else if (layout == .Packed and !try sema.validatePackedType(field_ty)) { |
| 36447 | 36453 | const msg = msg: { |
| 36448 | 36454 | const ty_src = mod.fieldSrcLoc(union_type.decl, .{ |
| 36449 | 36455 | .index = field_i, |