A record declares a constructor or accessor that does exactly what the record would do without it
What it finds
A record already has a canonical constructor that assigns its fields and accessors that return them. Writing them out adds code that only restates the header.
Reported is a canonical constructor whose body only assigns each component to its field, a compact constructor with an empty body, and an accessor whose body only returns its field.
From the rule's source, redundant_record_member.rs.
record Point(int x, int y) { Point(int x, int y) {tx0 reports: already provides this.x = x; this.y = y; } public int x() {tx0 reports: already provides return x; } public int y() { return Math.abs(y); }}record Range(int low, int high) { Range {tx0 reports: already provides }}record Checked(int low) { Checked { if (low < 0) { throw new IllegalArgumentException(); } }} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/java:redundant-record-member" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/java:redundant-record-member] reason="..."tx0 explain tx0/java:redundant-record-member shows the same in the terminal. Found a false positive? Report it.