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

Add must_use to the Reference #35754

Merged
merged 1 commit into from
Sep 3, 2016

Conversation

QuietMisdreavus
Copy link
Member

I'm a bit uncertain about the exact phrasing, but having it mentioned at all is probably better than before.

@rust-highfive
Copy link
Collaborator

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"]`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two things

  1. "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."
  2. rather than "full version" I would say "You can additionally pass a message with this syntax that allows you..."

Copy link
Member

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?

Copy link
Member Author

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.

@Manishearth
Copy link
Member

r=me -- could you squash the two commits?

@QuietMisdreavus
Copy link
Member Author

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.
Copy link
Contributor

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

Copy link
Member

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, 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.

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:/rust-lang/rust/pull/35754/files/3f54852aa06c063b5c4b08846f583ac6d57cfc82#r75178315), or mute the thread (https:/notifications/unsubscribe-auth/AABsiuZJ1yZrRya9Qz8pn55F9oKkfVSvks5qg1F8gaJpZM4Jmqe9).

Copy link
Member

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"

Copy link
Contributor

@jonas-schievink jonas-schievink Aug 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But isn't some_fn(my_var) a use of my_var, too? This doesn't warn, however. What does actually warn is an expression statement <expr>; where <expr> has a #[must_use] type.

Copy link
Contributor

@jonas-schievink jonas-schievink Aug 17, 2016

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.

Copy link
Member Author

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"?

Copy link
Contributor

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"?

Copy link
Member Author

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.

@steveklabnik
Copy link
Member

@bors: r=Manishearth rollup

@bors
Copy link
Contributor

bors commented Sep 1, 2016

📌 Commit 0384722 has been approved by Manishearth

@Manishearth
Copy link
Member

Manishearth commented Sep 2, 2016

Sorry for missing this!

(I have the time to review things, just ping me in two days if I forget)

sophiajt pushed a commit to sophiajt/rust that referenced this pull request Sep 2, 2016
… 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.
sophiajt pushed a commit to sophiajt/rust that referenced this pull request Sep 2, 2016
… 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.
sophiajt pushed a commit to sophiajt/rust that referenced this pull request Sep 2, 2016
… 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.
bors added a commit that referenced this pull request Sep 3, 2016
Rollup of 12 pull requests

- Successful merges: #35754, #35793, #36099, #36160, #36171, #36178, #36180, #36190, #36198, #36205, #36210, #36223
- Failed merges:
@bors bors merged commit 0384722 into rust-lang:master Sep 3, 2016
@QuietMisdreavus QuietMisdreavus deleted the must-use-reference branch September 6, 2016 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants