ziglint Changelog View on GitHub

Z019: @This() in named struct

Detects const Self = @This() inside a named struct where the struct's name should be used instead.

Examples

Bad

// expect: Z019
const Point = struct {
    const Self = @This();
    x: i32,
    y: i32,
};

Good

Use the struct's name directly:

pub const Point = struct {
    x: i32,
    y: i32,

    pub fn origin() Point {
        return .{ .x = 0, .y = 0 };
    }
};

@This() is appropriate in anonymous or local structs:

fn MakeStruct() type {
    return struct {
        const Self = @This();
        value: u32,
    };
}

Rationale

In named structs, using the actual name is clearer than @This(). It makes the type explicit and is easier to search for. @This() is designed for anonymous structs where there is no name to use.