authorgravatar for lachlan@lakebythewoods.xyzLachlan Easton <lachlan@lakebythewoods.xyz> 2020-09-03 20:16:12+10:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-03 14:11:04-04:00
log2a58e30bd5f522bf3077f556f47a1e28c537627e
treefc3d6ee155a6b8ecc7287cc308f330da410a1acb
parent39a80cf59e082b57606e5ddc074b5ae1337c0d79

std meta: fix use of alignOf in meta.cast


1 files changed, 8 insertions(+), 8 deletions(-)

lib/std/meta.zig+8-8
...@@ -705,34 +705,34 @@ pub fn Vector(comptime len: u32, comptime child: type) type {...@@ -705,34 +705,34 @@ pub fn Vector(comptime len: u32, comptime child: type) type {
705pub fn cast(comptime DestType: type, target: anytype) DestType {705pub fn cast(comptime DestType: type, target: anytype) DestType {
706 const TargetType = @TypeOf(target);706 const TargetType = @TypeOf(target);
707 switch (@typeInfo(DestType)) {707 switch (@typeInfo(DestType)) {
708 .Pointer => {708 .Pointer => |dest_ptr| {
709 switch (@typeInfo(TargetType)) {709 switch (@typeInfo(TargetType)) {
710 .Int, .ComptimeInt => {710 .Int, .ComptimeInt => {
711 return @intToPtr(DestType, target);711 return @intToPtr(DestType, target);
712 },712 },
713 .Pointer => |ptr| {713 .Pointer => |ptr| {
714 return @ptrCast(DestType, @alignCast(ptr.alignment, target));714 return @ptrCast(DestType, @alignCast(dest_ptr.alignment, target));
715 },715 },
716 .Optional => |opt| {716 .Optional => |opt| {
717 if (@typeInfo(opt.child) == .Pointer) {717 if (@typeInfo(opt.child) == .Pointer) {
718 return @ptrCast(DestType, @alignCast(@alignOf(opt.child.Child), target));718 return @ptrCast(DestType, @alignCast(dest_ptr, target));
719 }719 }
720 },720 },
721 else => {},721 else => {},
722 }722 }
723 },723 },
724 .Optional => |opt| {724 .Optional => |dest_opt| {
725 if (@typeInfo(opt.child) == .Pointer) {725 if (@typeInfo(dest_opt.child) == .Pointer) {
726 switch (@typeInfo(TargetType)) {726 switch (@typeInfo(TargetType)) {
727 .Int, .ComptimeInt => {727 .Int, .ComptimeInt => {
728 return @intToPtr(DestType, target);728 return @intToPtr(DestType, target);
729 },729 },
730 .Pointer => |ptr| {730 .Pointer => {
731 return @ptrCast(DestType, @alignCast(ptr.alignment, target));731 return @ptrCast(DestType, @alignCast(@alignOf(dest_opt.child.Child), target));
732 },732 },
733 .Optional => |target_opt| {733 .Optional => |target_opt| {
734 if (@typeInfo(target_opt.child) == .Pointer) {734 if (@typeInfo(target_opt.child) == .Pointer) {
735 return @ptrCast(DestType, @alignCast(@alignOf(target_opt.child.Child), target));735 return @ptrCast(DestType, @alignCast(@alignOf(dest_opt.child.Child), target));
736 }736 }
737 },737 },
738 else => {},738 else => {},