-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Add must_use
to the Reference
#35754
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Manishearth (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
@@ -2070,6 +2070,9 @@ macro scope. | |||
trait of the same name. `{Self}` will be replaced with the type that is supposed | |||
to implement the trait but doesn't. To use this, the `on_unimplemented` feature gate | |||
must be enabled. | |||
- `must_use` - on structs and enums, requires that instances are either consumed | |||
or passed outside the crate. Using the full version `#[must_use = "message"]` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two things
- "consumed or passed outside the crate" is not 100% accurate here. "consumed" means something specific in Rust, I would say something more like "will warn if this value isn't bound to a variable."
- rather than "full version" I would say "You can additionally pass a message with this syntax that allows you..."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The crate isn't actually important here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Manishearth On second thought, you're absolutely right. I guess I was reading too into the lint that emitted the warning.
@steveklabnik I like that! I'll get that written in.
r=me -- could you squash the two commits? |
d83efa7
to
3f54852
Compare
There you go, should be all set now. |
@@ -2070,6 +2070,9 @@ macro scope. | |||
trait of the same name. `{Self}` will be replaced with the type that is supposed | |||
to implement the trait but doesn't. To use this, the `on_unimplemented` feature gate | |||
must be enabled. | |||
- `must_use` - on structs and enums, will warn if this value isn't bound to a variable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has little to do with binding to variables - after all, .unwrap()
makes the warning go away
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, both work, because they both count as "use" . It's hard not to get circular here...
On Aug 17, 2016, 14:22 -0400, Jonas Schievink [email protected], wrote:
In src/doc/reference.md (#35754 (comment)):
@@ -2070,6 +2070,9 @@ macro scope. > trait of the same name.
{Self}
will be replaced with the type that is supposed > to implement the trait but doesn't. To use this, theon_unimplemented
feature gate > must be enabled. > +-must_use
- on structs and enums, will warn if this value isn't bound to a variable.This has little to do with binding to variables - after all, .unwrap() makes the warning go away
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub (https://github.com/rust-lang/rust/pull/35754/files/3f54852aa06c063b5c4b08846f583ac6d57cfc82#r75178315), or mute the thread (https://github.com/notifications/unsubscribe-auth/AABsiuZJ1yZrRya9Qz8pn55F9oKkfVSvks5qg1F8gaJpZM4Jmqe9).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"will warn when a function returning such a value is called without the returned value being used or assigned to a variable"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But isn't What does actually warn is an expression statement some_fn(my_var)
a use of my_var
, too? This doesn't warn, however.<expr>;
where <expr>
has a #[must_use]
type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess what I'm getting at is that "isn't bound to a variable" is a necessary but not sufficient requirement for the lint to fire.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would argue that some_fn(my_var)
is a use under @Manishearth's version. It feels a little vague to put "isn't used" without refining it further, but at the same time trying to define what a "use" is feels like it would get overly wordy. Maybe "will warn when this value isn't used or assigned to a variable"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly "will warn when a value of this type isn't used or assigned to a variable"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it, I'll use that version.
3f54852
to
0384722
Compare
@bors: r=Manishearth rollup |
📌 Commit 0384722 has been approved by |
Sorry for missing this! (I have the time to review things, just ping me in two days if I forget) |
… r=Manishearth Add `must_use` to the Reference I'm a bit uncertain about the exact phrasing, but having it mentioned at all is probably better than before.
… r=Manishearth Add `must_use` to the Reference I'm a bit uncertain about the exact phrasing, but having it mentioned at all is probably better than before.
… r=Manishearth Add `must_use` to the Reference I'm a bit uncertain about the exact phrasing, but having it mentioned at all is probably better than before.
I'm a bit uncertain about the exact phrasing, but having it mentioned at all is probably better than before.