Skip to content

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

Closed

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.

Activity

  1. changed the title [-]Suggestion[/-] [+]Suggestion: say "field is never read" instead of "field is never used" [/+] on Sep 14, 2019
  2. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Sep 14, 2019
  3. added
    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
    on Oct 5, 2019
  4. XiangQingW commented on Oct 6, 2019

    @XiangQingW
    Contributor

    @rustbot claim

  5. self-assigned this
    on Oct 6, 2019
  6. tesuji commented on Oct 17, 2019

    @tesuji
    Contributor

    Ping @XiangQingW , do you still working on it?

  7. XiangQingW commented on Oct 19, 2019

    @XiangQingW
    Contributor

    @lzutao Not yet. I'm working on other issues currently. Please take it if you want.

  8. CosineP commented on Nov 16, 2019

    @CosineP

    i will take it? @rustbot claim? first time sorry

  9. rustbot commented on Nov 16, 2019

    @rustbot
    Collaborator

    Error: Parsing assign command in comment failed: ...tbot claim|error: expected end of command at >|? first ti...

    Please let @rust-lang/release know if you're having trouble with this bot.

  10. jplatte commented on Nov 16, 2019

    @jplatte
    Contributor

    @CosineP I think rostbot was confused by the questionmark after claim ;)

  11. CosineP commented on Nov 16, 2019

    @CosineP

    @rustbot claim

  12. assigned and unassigned on Nov 16, 2019
  13. added a commit that references this issue on Nov 17, 2019
    c269580
  14. added a commit that references this issue on Nov 17, 2019
    c0fccf5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to 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