Skip to content

std.meta.trait: mark all the functions as 'inline' #17654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

wrongnull
Copy link
Contributor

Currently there is nothing indicates that those functions should be called with explicit comptime. This can lead to strange error messages in user code such as following:

const std = @import("std");

const MyUnion = union(enum) {
    field1: u32,
    field2: [] const u8,
};


fn constructMyUnion(comptime arg: anytype) MyUnion {
    if (std.meta.trait.isIntegral(@TypeOf(arg))) {
        return .{ .field1 = arg };
    }
    return .{ .field2 = arg };
}

pub fn main() void {
    _ = constructMyUnion(1);
}
error: expected type '[]const u8', found 'comptime_int'


pub fn multiTrait(comptime traits: anytype) TraitFn {
pub inline fn multiTrait(comptime traits: anytype) TraitFn {
Copy link
Member

@mlugg mlugg Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functions returning TraitFn need not be marked inline; they're already comptime-only.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wrongnull
Copy link
Contributor Author

I close this pr in favor of #18061

@wrongnull wrongnull closed this Nov 22, 2023
@wrongnull wrongnull deleted the inline-trait-functions branch November 22, 2023 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants