Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
xpe opened this issue Sep 14, 2019 · 7 comments · Fixed by #66469
Closed

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

xpe opened this issue Sep 14, 2019 · 7 comments · Fixed by #66469
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@xpe
Copy link

xpe commented Sep 14, 2019

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.

@xpe xpe changed the title Suggestion Suggestion: say "field is never read" instead of "field is never used" Sep 14, 2019
@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 14, 2019
@estebank estebank added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Oct 5, 2019
@XiangQingW
Copy link
Contributor

@rustbot claim

@rustbot rustbot self-assigned this Oct 6, 2019
@tesuji
Copy link
Contributor

tesuji commented Oct 17, 2019

Ping @XiangQingW , do you still working on it?

@XiangQingW
Copy link
Contributor

XiangQingW commented Oct 19, 2019

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

@CosineP
Copy link

CosineP commented Nov 16, 2019

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

@rustbot
Copy link
Collaborator

rustbot commented Nov 16, 2019

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.

@jplatte
Copy link
Contributor

jplatte commented Nov 16, 2019

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

@CosineP
Copy link

CosineP commented Nov 16, 2019

@rustbot claim

@rustbot rustbot assigned rustbot and unassigned rustbot Nov 16, 2019
Centril added a commit to Centril/rust that referenced this issue Nov 17, 2019
Use "field is never read" instead of "field is never used"

this is my first PR here so please let me know if i am doing it wrong
closes rust-lang#64465
i will be referencing this with a book PR that updates the same language
@bors bors closed this as completed in c0fccf5 Nov 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants