Skip to content

Suggestion: say "field is never read" instead of "field is never used"  #64465

Closed
@xpe

Description

@xpe

As of rustc 1.37.0, this code:

pub struct Owl { tree: u16 }

fn exist(tree: u16) -> bool { tree > 0 && tree <= 3 }

impl Owl {
    pub fn find(tree: u16) -> Option<Owl> {
        if exist(tree) { Some(Owl { tree }) } else { None }
    }
}

fn main() { Owl::find(1); }

gives the warning:

warning: field is never used: `tree`
 --> src/main.rs:5:18

I understand that the compiler can optimize out the tree field. Forgive me for stating the obvious; namely, the warning doesn't mention anything about "optimizing away" the field; it only says "field is never used". A user would be justified in thinking: "this warning doesn't make sense; the Owl::find method most certainly uses the tree field.

Suggestion

I'd suggest changing the warning to say "warning: field is never read".

Rationale

By the common understanding of the word 'use', the tree field indeed is 'used', because the word 'use' can mean 'read' or 'write'. Being more specific (i.e. saying "field is never read") will help users understand what kind of use the compiler means.

This issue has been assigned to @CosineP via this comment.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions