-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Conversation
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. |
fn eat(val: Value) {} | ||
|
||
fn main() { | ||
let x = Value{}; | ||
{ | ||
let _ref_to_val: &Value = &x; | ||
borrow(_ref_to_val); | ||
} |
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.
Should I keep this set of braces in?
It is one way to resolve the error.
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.
Sorry, I forgot that we still have AST borrow check on the 2015 edition. Keep them for now.
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 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
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.
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.
@bors r+ rollup |
📌 Commit 6a5abea has been approved by |
@@ -1545,20 +1545,22 @@ Erroneous code example: | |||
```compile_fail,E0505 | |||
struct Value {} |
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.
Is there an opinion for struct Value {}
over struct Value;
?
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.
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.
…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
…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
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
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