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

Fixes #58586: Make E0505 erronous example fail for the 2018 edition #58607

Merged
merged 2 commits into from
Feb 23, 2019

Conversation

gurgalex
Copy link
Contributor

@gurgalex gurgalex commented Feb 20, 2019

The original example worked for 2015, but not the 2018 edition of Rust.

Borrowing the moved value after ownership is transferred seems required for 2018.

this line though is correct for 2018, but not for the 2015 edition.

Fix #58586

@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 @varkor (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.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 20, 2019
fn eat(val: Value) {}

fn main() {
let x = Value{};
{
let _ref_to_val: &Value = &x;
borrow(_ref_to_val);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I keep this set of braces in?
It is one way to resolve the error.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I forgot that we still have AST borrow check on the 2015 edition. Keep them for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can remove the braces from all the examples except this one, and they give the expected results for both 2015 and 2018.

erroneous: Fails
Take by ref: Passes
Implement Copy: Passes

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, it's fine like this for now.

The solution which uses braces to release the borrow
before it is moved is only required to satisfy the 2015
edition borrow checker.

All other examples give the expected results for both
2015 and 2018 editions.
@matthewjasper
Copy link
Contributor

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Feb 20, 2019

📌 Commit 6a5abea has been approved by matthewjasper

@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 Feb 20, 2019
@@ -1545,20 +1545,22 @@ Erroneous code example:
```compile_fail,E0505
struct Value {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there an opinion for struct Value {} over struct Value;?

Copy link
Contributor Author

@gurgalex gurgalex Feb 21, 2019

Choose a reason for hiding this comment

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

Didn't know that an empty struct could be made like that.

I'd want to keep the {} so that the reader doesn't have to guess what is being expressed.

Centril added a commit to Centril/rust that referenced this pull request Feb 22, 2019
…n, r=matthewjasper

Fixes rust-lang#58586: Make E0505 erronous example fail for the 2018 edition

The original example worked for 2015, but not the 2018 edition of Rust.

Borrowing the moved value after ownership is transferred seems required for 2018.

[this](rust-lang/rust@rust-lang:f66e469...gurgalex:b2a02c8#diff-4ca866aea4a6efecd732f1975faaad88R1564) line though is correct for 2018, but not for the 2015 edition.

Fix rust-lang#58586
Centril added a commit to Centril/rust that referenced this pull request Feb 22, 2019
…n, r=matthewjasper

Fixes rust-lang#58586: Make E0505 erronous example fail for the 2018 edition

The original example worked for 2015, but not the 2018 edition of Rust.

Borrowing the moved value after ownership is transferred seems required for 2018.

[this](rust-lang/rust@rust-lang:f66e469...gurgalex:b2a02c8#diff-4ca866aea4a6efecd732f1975faaad88R1564) line though is correct for 2018, but not for the 2015 edition.

Fix rust-lang#58586
bors added a commit that referenced this pull request Feb 22, 2019
Rollup of 17 pull requests

Successful merges:

 - #57656 (Deprecate the unstable Vec::resize_default)
 - #58059 (deprecate before_exec in favor of unsafe pre_exec)
 - #58064 (override `VecDeque::try_rfold`, also update iterator)
 - #58198 (Suggest removing parentheses surrounding lifetimes)
 - #58431 (fix overlapping references in BTree)
 - #58555 (Add a note about 2018e if someone uses `try {` in 2015e)
 - #58588 (remove a bit of dead code)
 - #58589 (cleanup macro after 2018 transition)
 - #58591 (Dedup a rustdoc diagnostic construction)
 - #58600 (fix small documentation typo)
 - #58601 (Search for target_triple.json only if builtin target not found)
 - #58606 (Docs: put Future trait into spotlight)
 - #58607 (Fixes #58586: Make E0505 erronous example fail for the 2018 edition)
 - #58615 (miri: explain why we use static alignment in ref-to-place conversion)
 - #58620 (introduce benchmarks of BTreeSet.intersection)
 - #58621 (Update miri links)
 - #58632 (Make std feature list sorted)

Failed merges:

r? @ghost
@bors bors merged commit 6a5abea into rust-lang:master Feb 23, 2019
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