-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Description
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.