Getter returns a field unrelated to its own name

ID

rust.correctness.getters_access_expected_fields

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Suspicious Construct

Language

Rust

Description

This accessor returns a field whose name has nothing in common with the method name, which is the signature of a copy-paste slip: callers get a different value from the one the name promises. Return the matching field, or rename the method after the field it exposes.

Rationale

This accessor returns a field whose name has nothing in common with the method name, which is the signature of a copy-paste slip: callers get a different value from the one the name promises. Return the matching field, or rename the method after the field it exposes.

The following code illustrates the pattern detected by this rule:

pub struct Rect {
    width: u32,
    height: u32,
    label: String,
    tooltip: String,
}

impl Rect {
    // FLAGGED: Getter returns a field unrelated to its own name
    pub fn width(&self) -> u32 { self.height }
}

Remediation

Follow secure coding practices and review the references below for detailed remediation guidance.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved