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

make offset must_use #72143

Merged
merged 1 commit into from
May 18, 2020
Merged

make offset must_use #72143

merged 1 commit into from
May 18, 2020

Conversation

steveklabnik
Copy link
Member

https://djugei.github.io/bad-at-unsafe/ describes an error a user had when trying to use offset:

At first I just assumed that the .add() and .offset() methods on pointers would mutate the pointer. They do not. Instead they return a new pointer, which gets dropped silently if you don't use it. Unlike for example Result, which is must_use annotated.

This PR only adds offset, because I wanted to float the idea; I'm imagining that there's more than just add and offset that could use this. I am also very open to re-wording the warning.

r? @rust-lang/libs

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 12, 2020
@CAD97
Copy link
Contributor

CAD97 commented May 12, 2020

Did you mean to annotate the intrinsic rather than the stable API?

@steveklabnik
Copy link
Member Author

Did you mean to annotate the intrinsic rather than the stable API?

My thought process was:

  1. oh, this is the intrinsic.
  2. you know what, I think that the stable api is just a re-export?
  3. I could go check but, if this is accepted, I'm gonna have to go in and update at least add anyway.
  4. I'd rather get the conversation started, so just send it in. I'll fix it later if it needs fixing.

@sfackler
Copy link
Member

We've added must_use to similar methods like wrapping_add in the past. r=me with it on the public API

@Mark-Simulacrum
Copy link
Member

I would suggest expanding to all pointer methods which don't mutate self - that seems consistent to me. And presumably we should put the attribute on both the intrinsic and the stabilized methods? Seems odd to do just one.

@sfackler
Copy link
Member

No one should be calling the intrinsics though.

@Mark-Simulacrum
Copy link
Member

I don't mind not touching the intrinsics; I agree no one should be calling them. But the cost is tiny so seems like it wouldn't hurt to at least make sure our internal uses are also doing the right thing. I agree there's very little benefit.

@steveklabnik
Copy link
Member Author

So, before I add them, what's the call here? I personally would choose to add them to both, but don't have a super strong preference. @sfackler , do you actively oppose adding them, or do you not mind if it's both?

@sfackler
Copy link
Member

Sure, I have no objection to adding them to the intrinsics.

@steveklabnik steveklabnik force-pushed the steveklabnik-must-use branch from 356d64d to 98eb699 Compare May 17, 2020 15:30
@steveklabnik
Copy link
Member Author

Sigh, I do not know why this updated some submodules. trying to fix it now

@rust-highfive
Copy link
Collaborator

The job mingw-check of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
##[section]Starting: Linux mingw-check
##[section]Starting: Initialize job
Agent name: 'Hosted Agent'
Agent machine name: 'fv-az619'
Current agent version: '2.168.2'
##[group]Operating System
16.04.6
LTS
LTS
##[endgroup]
##[group]Virtual Environment
Environment: ubuntu-16.04
Version: 20200430.2
Included Software: /~https://github.com/actions/virtual-environments/blob/ubuntu16/20200430.2/images/linux/Ubuntu1604-README.md
##[endgroup]
Agent running as: 'vsts'
Prepare build directory.
Set build variables.
Download all required tasks.
Download all required tasks.
Downloading task: Bash (3.163.2)
Checking job knob settings.
   Knob: AgentToolsDirectory = /opt/hostedtoolcache Source: ${AGENT_TOOLSDIRECTORY} 
   Knob: AgentPerflog = /home/vsts/perflog Source: ${VSTS_AGENT_PERFLOG} 
Start tracking orphan processes.
##[section]Finishing: Initialize job
##[section]Starting: Configure Job Name
==============================================================================
---
========================== Starting Command Output ===========================
[command]/bin/bash --noprofile --norc /home/vsts/work/_temp/26900dd8-74b9-4a7f-aaad-2182a6b7d9fa.sh

##[section]Finishing: Disable git automatic line ending conversion
##[section]Starting: Checkout rust-lang/rust@refs/pull/72143/merge to s
Task         : Get sources
Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
Version      : 1.0.0
Author       : Microsoft
---
##[command]git remote add origin /~https://github.com/rust-lang/rust
##[command]git config gc.auto 0
##[command]git config --get-all http./~https://github.com/rust-lang/rust.extraheader
##[command]git config --get-all http.proxy
##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/72143/merge:refs/remotes/pull/72143/merge
---
 ---> 3adb0605cc65
Step 6/7 : ENV RUN_CHECK_WITH_PARALLEL_QUERIES 1
 ---> Using cache
 ---> 28dbc326cb7f
Step 7/7 : ENV SCRIPT python3 ../x.py test src/tools/expand-yaml-anchors &&            python3 ../x.py check --target=i686-pc-windows-gnu --host=i686-pc-windows-gnu &&            python3 ../x.py build --stage 0 src/tools/build-manifest &&            python3 ../x.py test --stage 0 src/tools/compiletest &&            python3 ../x.py test src/tools/tidy &&            python3 ../x.py doc --stage 0 src/libstd &&            /scripts/validate-toolstate.sh
 ---> 537a01811900
Successfully built 537a01811900
Successfully tagged rust-ci:latest
Built container sha256:537a018119009dc218456238dec90b5530050db1e2a1e166550c218003f6159d
---
  local time: Sun May 17 15:34:04 UTC 2020
  network time: Sun, 17 May 2020 15:34:04 GMT
== end clock drift check ==

##[error]Bash exited with code '1'.
##[section]Finishing: Run build
##[section]Starting: Checkout rust-lang/rust@refs/pull/72143/merge to s
Task         : Get sources
Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
Version      : 1.0.0
Author       : Microsoft
Author       : Microsoft
Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
==============================================================================
Cleaning any cached credential from repository: rust-lang/rust (GitHub)
##[section]Finishing: Checkout rust-lang/rust@refs/pull/72143/merge to s
Cleaning up task key
Start cleaning up orphan processes.
Terminate orphan process: pid (5559) (python)
##[section]Finishing: Finalize Job

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @rust-lang/infra. (Feature Requests)

https://djugei.github.io/bad-at-unsafe/ describes an error a user had when trying to use offset:

> At first I just assumed that the .add() and .offset() methods on pointers would mutate the pointer. They do not. Instead they return a new pointer, which gets dropped silently if you don't use it. Unlike for example Result, which is must_use annotated.
@steveklabnik steveklabnik force-pushed the steveklabnik-must-use branch from 98eb699 to aea0186 Compare May 17, 2020 15:36
@steveklabnik
Copy link
Member Author

Okay, this is ready for a re-review. I did the intrinsics as well as the functions that returned a new pointer. I'd appreciate someone checking that this is all accurate. :)

@sfackler
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented May 17, 2020

📌 Commit aea0186 has been approved by sfackler

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 17, 2020
RalfJung added a commit to RalfJung/rust that referenced this pull request May 17, 2020
…sfackler

make offset must_use

https://djugei.github.io/bad-at-unsafe/ describes an error a user had when trying to use offset:

> At first I just assumed that the .add() and .offset() methods on pointers would mutate the pointer. They do not. Instead they return a new pointer, which gets dropped silently if you don't use it. Unlike for example Result, which is must_use annotated.

This PR only adds `offset`, because I wanted to float the idea; I'm imagining that there's more than just `add` and `offset` that could use this. I am also very open to re-wording the warning.

r? @rust-lang/libs
bors added a commit to rust-lang-ci/rust that referenced this pull request May 18, 2020
Rollup of 2 pull requests

Successful merges:

 - rust-lang#72143 (make offset must_use)
 - rust-lang#72307 (use the new interface to initialize conditional variables)

Failed merges:

r? @ghost
@bors bors merged commit 2a90664 into master May 18, 2020
@steveklabnik steveklabnik deleted the steveklabnik-must-use branch May 18, 2020 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants