mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
std meta: fix use of alignOf in meta.cast
This commit is contained in:
parent
39a80cf59e
commit
2a58e30bd5
@ -705,34 +705,34 @@ pub fn Vector(comptime len: u32, comptime child: type) type {
|
||||
pub fn cast(comptime DestType: type, target: anytype) DestType {
|
||||
const TargetType = @TypeOf(target);
|
||||
switch (@typeInfo(DestType)) {
|
||||
.Pointer => {
|
||||
.Pointer => |dest_ptr| {
|
||||
switch (@typeInfo(TargetType)) {
|
||||
.Int, .ComptimeInt => {
|
||||
return @intToPtr(DestType, target);
|
||||
},
|
||||
.Pointer => |ptr| {
|
||||
return @ptrCast(DestType, @alignCast(ptr.alignment, target));
|
||||
return @ptrCast(DestType, @alignCast(dest_ptr.alignment, target));
|
||||
},
|
||||
.Optional => |opt| {
|
||||
if (@typeInfo(opt.child) == .Pointer) {
|
||||
return @ptrCast(DestType, @alignCast(@alignOf(opt.child.Child), target));
|
||||
return @ptrCast(DestType, @alignCast(dest_ptr, target));
|
||||
}
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
},
|
||||
.Optional => |opt| {
|
||||
if (@typeInfo(opt.child) == .Pointer) {
|
||||
.Optional => |dest_opt| {
|
||||
if (@typeInfo(dest_opt.child) == .Pointer) {
|
||||
switch (@typeInfo(TargetType)) {
|
||||
.Int, .ComptimeInt => {
|
||||
return @intToPtr(DestType, target);
|
||||
},
|
||||
.Pointer => |ptr| {
|
||||
return @ptrCast(DestType, @alignCast(ptr.alignment, target));
|
||||
.Pointer => {
|
||||
return @ptrCast(DestType, @alignCast(@alignOf(dest_opt.child.Child), target));
|
||||
},
|
||||
.Optional => |target_opt| {
|
||||
if (@typeInfo(target_opt.child) == .Pointer) {
|
||||
return @ptrCast(DestType, @alignCast(@alignOf(target_opt.child.Child), target));
|
||||
return @ptrCast(DestType, @alignCast(@alignOf(dest_opt.child.Child), target));
|
||||
}
|
||||
},
|
||||
else => {},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user