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

Projects
None yet
6 participants
@QuietMisdreavus
Member

QuietMisdreavus commented Aug 17, 2016

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

@rust-highfive

This comment has been minimized.

Collaborator

rust-highfive commented Aug 17, 2016

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"]`

This comment has been minimized.

@steveklabnik

steveklabnik Aug 17, 2016

Member

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

This comment has been minimized.

@Manishearth

Manishearth Aug 17, 2016

Member

The crate isn't actually important here?

This comment has been minimized.

@QuietMisdreavus

QuietMisdreavus Aug 17, 2016

Member

@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

This comment has been minimized.

Member

Manishearth commented Aug 17, 2016

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

@QuietMisdreavus QuietMisdreavus force-pushed the QuietMisdreavus:must-use-reference branch from d83efa7 to 3f54852 Aug 17, 2016

@QuietMisdreavus

This comment has been minimized.

Member

QuietMisdreavus commented Aug 17, 2016

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.

This comment has been minimized.

@jonas-schievink

jonas-schievink Aug 17, 2016

Contributor

This has little to do with binding to variables - after all, .unwrap() makes the warning go away

This comment has been minimized.

@steveklabnik

steveklabnik Aug 17, 2016

Member

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

This comment has been minimized.

@Manishearth

Manishearth Aug 17, 2016

Member

"will warn when a function returning such a value is called without the returned value being used or assigned to a variable"

This comment has been minimized.

@jonas-schievink

jonas-schievink Aug 17, 2016

Contributor

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.

This comment has been minimized.

@jonas-schievink

jonas-schievink Aug 17, 2016

Contributor

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.

This comment has been minimized.

@QuietMisdreavus

QuietMisdreavus Aug 17, 2016

Member

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

This comment has been minimized.

@jonas-schievink

jonas-schievink Aug 17, 2016

Contributor

Possibly "will warn when a value of this type isn't used or assigned to a variable"?

This comment has been minimized.

@QuietMisdreavus

QuietMisdreavus Aug 17, 2016

Member

I like it, I'll use that version.

@QuietMisdreavus QuietMisdreavus force-pushed the QuietMisdreavus:must-use-reference branch from 3f54852 to 0384722 Aug 17, 2016

@steveklabnik

This comment has been minimized.

Member

steveklabnik commented Sep 1, 2016

@bors: r=Manishearth rollup

@bors

This comment has been minimized.

Contributor

bors commented Sep 1, 2016

📌 Commit 0384722 has been approved by Manishearth

@Manishearth

This comment has been minimized.

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)

jonathandturner added a commit to jonathandturner/rust that referenced this pull request Sep 2, 2016

Rollup merge of rust-lang#35754 - QuietMisdreavus:must-use-reference,…
… 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.

jonathandturner added a commit to jonathandturner/rust that referenced this pull request Sep 2, 2016

Rollup merge of rust-lang#35754 - QuietMisdreavus:must-use-reference,…
… 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 2, 2016

jonathandturner added a commit to jonathandturner/rust that referenced this pull request Sep 2, 2016

Rollup merge of rust-lang#35754 - QuietMisdreavus:must-use-reference,…
… 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

Auto merge of #36227 - jonathandturner:rollup, r=jonathandturner
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

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@QuietMisdreavus QuietMisdreavus deleted the QuietMisdreavus:must-use-reference branch Sep 6, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment