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

remove notion of Implicit derefs from mem-cat #51235

Merged

Conversation

nikomatsakis
Copy link
Contributor

PointerKind is included in LoanPath and hence forms part of the equality check; this led to having two unequal paths that both represent *x, depending on whether the * was inserted automatically or explicitly. Bad mojo.

Fixes #51117

r? @eddyb

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 30, 2018
@nikomatsakis
Copy link
Contributor Author

(Travis will probably fail; I'm still running ./x.py test locally)

@nikomatsakis nikomatsakis force-pushed the issue-51117-borrowck-implicit-deref branch from 119210a to 6bb1853 Compare May 30, 2018 23:59
@eddyb eddyb added the beta-nominated Nominated for backporting to the compiler in the beta channel. label May 31, 2018
@eddyb
Copy link
Member

eddyb commented May 31, 2018

r=me with tests fixed

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-3.9 of your PR failed on Travis (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.
travis_time:start:test_ui
Check compiletest suite=ui mode=ui (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[00:40:33] 
[00:40:33] running 1479 tests
[00:40:37] ..............................................F...........................................i.........
[00:40:46] ....................................................................................................
[00:40:49] ....................................................................................................
[00:40:53] ....................................................................................................
[00:40:56] ....................................................................................................
[00:40:56] ....................................................................................................
[00:41:00] ....................................................................................................
[00:41:04] ..............................................................................................FF....
[00:41:14] ..............................................................................................i.....
[00:41:19] .......................................................................i............................
[00:41:24] ....................................................................................................
[00:41:29] ....................................................................................................
[00:41:29] ....................................................................................................
[00:41:35] ....................................................................................................
nformation about this error, try `rustc --explain E0499`.
[00:41:38] 
[00:41:38] 
[00:41:38] 
[00:41:38] The actual stderr differed from the expected stderr.
[00:41:38] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/issue-51117/issue-51117.stderr
[00:41:38] To update references, rerun the tests and pass the `--bless` flag
[00:41:38] To only update this specific test, also pass `--test-args borrowck/issue-51117.rs`
[00:41:38] error: 1 errors occurred comparing output.
[00:41:38] status: exit code: 101
[00:41:38] status: exit code: 101
[00:41:38] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/borrowck/issue-51117.rs" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/issue-51117/a" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/issue-51117/auxiliary" "-A" "unused"
[00:41:38] ------------------------------------------
[00:41:38] 
[00:41:38] ------------------------------------------
[00:41:38] stderr:
[00:41:38] stderr:
[00:41:38] ------------------------------------------
[00:41:38] {"message":"cannot borrow `*bar` as mutable more than once at a time","code":{"code":"E0499","explanation":"\nA variable was borrowed as mutable more than once. Erroneous code example:\n\n```compile_fail,E0499\nlet mut i = 0;\nlet mut x = &mut i;\nlet mut a = &mut i;\n// error: cannot borrow `i` as mutable more than oncee\n  --> /checkout/src/test/ui/borrowck/issue-51117.rs:20:13\n   |\nLL |         Some(baz) => {\n   |              --- first mutable borrow occurs here\nLL |             bar.take(); //~ ERROR cannot borrow\n   |             ^^^ second mutable borrow occurs here\n...\nLL |     }\n   |     - first borrow ends here\n\n"}
[00:41:38] {"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error\n\n"}
[00:41:38] {"message":"For more information about this error, try `rustc --explain E0499`.","code":null,"level":"","spans":[],"children":[],"rendered":"For more information about this error, try `rustc --explain E0499`.\n"}
[00:41:38] ------------------------------------------
[00:41:38] 
[00:41:38] thread '[ui] ui/borrowck/issue-51117.rs' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:3053:9
[00:41:38] note: Run with `RUST_BACKTRACE=1` for a backtrace.
---
[00:41:38] - error[E0507]: cannot move out of indexed content
[00:41:38] + error[E0507]: cannot move out of borrowed content
[00:41:38] 2   --> $DIR/issue-40402-1.rs:19:13
[00:41:38] 3    |
[00:41:38] 4 LL |     let e = f.v[0]; //~ ERROR cannot move out of indexed content
[00:41:38] 5    |             ^^^^^^
[00:41:38] 6    |             |
[00:41:38] -    |             cannot move out of indexed content
[00:41:38] +    |             cannot move out of borrowed content
[00:41:38] +    |             cannot move out of borrowed content
[00:41:38] 8    |             help: consider using38] {"message":"cannot move out of borrowed content","code":{"code":"E0507","explanation":"\nYou tried to move out of a value which was borrowed. Erroneous code example:\n\n```compile_fail,E0507\nuse std::cell::RefCell;\n\nstruct TheDarkKnight;\n\nimpl TheDarkKnight {\n    fn nothing_is_true(self) {}\n}\n\nfn main() {\n    let x = RefCell::new(TheDarkKnight);\n\n    x.borrow().nothing_is_true(); // error: cannot move out of borrowed content\n}\n```\n\nHere, the `nothing_is_true` method takes the ownership of `self`. However,\n`self` cannot be moved because `.borrow()` only provides an `&TheDarkKnight`,\nwhich is a borrow of the content owned by the `RefCell`. To fix this error,\nyou have three choices:\n\n* Try to avoid moving the variable.\n* Somehow reclaim the ownership.\n* Implement the `Copy` trait on the type.\n\nExamples:\n\n```\nuse std::cell::RefCell;\n\nstruct TheDarkKnight;\n\nimpl TheDarkKnight {\n    fn nothing_is_true(&self) {} // First case, we don't take ownership\n}\n\nfn main() {\n    let x = RefCell::new(TheDarkKnight);\n\n    x.borrow().nothing_is_true(); // ok!\n}\n```\n\nOr:\n\n```\nuse std::cell::RefCell;\n\nstruct TheDarkKnight;\n\nimpl TheDarkKnight {\n    fn nothing_is_true(self) {}\n}\n\nfn main() {\n    let x = RefCell::new(TheDarkKnight);\n    let x = x.into_inner(); // we get back ownership\n\n    x.nothing_is_true(); // ok!\n}\n```\n\nOr:\n\n```\nuse std::cell::RefCell;\n\n#[derive(Clone, Copy)] // we implement the Copy trait\nstruct TheDarkKnight;\n\nimpl TheDarkKnight {\n    fn nothing_is_true(self) {}\n}\n\nfn main() {\n    let x = RefCell::new(TheDarkKnight);\n\n    x.borrow().nothing_is_true(); // ok!\n}\n```\n\nMoving a member out of a mutably borrowed struct will also cause E0507 error:\n\n```compile_fail,E0507\nstruct TheDarkKnight;\n\nimpl TheDarkKnight {\n    fn nothing_is_true(self) {}\n}\n\nstruct Batcave {\n    knight: TheDarkKnight\n}\n\nfn main() {\n    let mut cave = Batcave {\n        knight: TheDarkKnight\n    };\n    let borrowed = &mut cave;\n\n    borrowed.knight.nothing_is_true(); // E0507\n}\n```\n\nIt is fine only if you put something back. `mem::replace` can be used for that:\n\n```\n# struct TheDarkKnight;\n# impl TheDarkKnight { fn nothing_is_true(self) {} }\n# struct Batcave { knight: TheDarkKnight }\nuse std::mem;\n\nlet mut cave = Batcave {\n    knight: TheDarkKnight\n};\nlet borrowed = &mut cave;\n\nmem::replace(&mut borrowed.knight, TheDarkKnight).nothing_is_true(); // ok!\n```\n\nYou can find more information about borrowing in the rust-book:\nhttp://doc.rust-lang.org/book/first-edition/references-and-borrowing.html\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/issue-40402-ref-hints/issue-40402-2.rs","byte_start":646,"byte_end":650,"line_start":15,"line_end":15,"column_start":18,"column_end":22,"is_primary":true,"text":[{"text":"    let (a, b) = x[0]; //~ ERROR cannot move out of indexed content","highlight_start":18,"highlight_end":22}],"label":"cannot move out of borrowed content","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"/checkout/src/test/ui/issue-40402-ref-hints/issue-40402-2.rs","byte_start":638,"byte_end":639,"line_start":15,"line_end":15,"column_start":10,"column_end":11,"is_primary":false,"text":[{"text":"730863262pt
103748 ./obj/build/bootstrap/debug/incremental/bootstrap-c730863262pt/s-f1j8x40deq-1x8944c-34q164wx8plum
103288 ./obj/build/x86_64-unknown-linux-gnu/stage0-tools/x86_64-unknown-linux-gnu
103284 ./obj/build/x86_64-unknown-linux-gnu/stage0-tools/x86_64-unknown-linux-gnu/release
99904 ./obj/build/x86_64-unknown-linux-gnu/stage0-tools/x86_64-unknown-linux-gnu/release/deps
90816 ./obj/build/x86_64-unknown-linux-gnu/stage1

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 @TimNN. (Feature Requests)

`PointerKind` is included in `LoanPath` and hence forms part of the
equality check; this led to having two unequal paths that both
represent `*x`, depending on whether the `*` was inserted
automatically or explicitly. Bad mojo. The `note` field, in contrast,
is intended more-or-less primarily for this purpose of adding extra
data.
@nikomatsakis nikomatsakis force-pushed the issue-51117-borrowck-implicit-deref branch from 3fc042e to 8a624b7 Compare May 31, 2018 14:19
@nikomatsakis
Copy link
Contributor Author

@eddyb I tweaked the approach somewhat to avoid impacting diagnostics. Maybe you want to re-review? Same basic idea.

// was not used). On other paths, it is not assigned,
// and hence if those paths *could* reach the code that
// comes after the match, this fn would not compile.
let convert_to_ambigious;
Copy link
Member

Choose a reason for hiding this comment

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

hax!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed...though I thought it was sort of beautiful in its own way :)

@eddyb
Copy link
Member

eddyb commented May 31, 2018

@bors r+ p=10

@bors
Copy link
Contributor

bors commented May 31, 2018

📌 Commit 8a624b7 has been approved by eddyb

@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 31, 2018
@bors
Copy link
Contributor

bors commented May 31, 2018

⌛ Testing commit 8a624b7 with merge 6de4ec6...

bors added a commit that referenced this pull request May 31, 2018
…ef, r=eddyb

remove notion of Implicit derefs from mem-cat

`PointerKind` is included in `LoanPath` and hence forms part of the equality check; this led to having two unequal paths that both represent `*x`, depending on whether the `*` was inserted automatically or explicitly. Bad mojo.

Fixes #51117

r? @eddyb
@bors
Copy link
Contributor

bors commented May 31, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: eddyb
Pushing 6de4ec6 to master...

@bors bors merged commit 8a624b7 into rust-lang:master May 31, 2018
@Mark-Simulacrum Mark-Simulacrum mentioned this pull request May 31, 2018
@oli-obk oli-obk added beta-accepted Accepted for backporting to the compiler in the beta channel. and removed beta-nominated Nominated for backporting to the compiler in the beta channel. labels Jun 1, 2018
bors added a commit that referenced this pull request Jun 1, 2018
[beta] Process backports

Merged and approved:

* #50812: Fix issue #50811 (`NaN > NaN` was true).
* #50827: Update LLVM to `56c931901cfb85cd6f7ed44c7d7520a8de1edf97`
* #50879: Fix naming conventions for new lints
* #51011: rustdoc: hide macro export statements from docs
* #51051: prohibit turbofish in `impl Trait` methods
* #51052: restore emplacement syntax (obsolete)
* #51146: typeck: Do not pass the field check on field error
* #51235: remove notion of Implicit derefs from mem-cat

r? @ghost
bors added a commit that referenced this pull request Jun 1, 2018
1.26.2 release

This includes a backport of #51235 which fixes #51117 on stable. It has not been tested.

r? @nikomatsakis since the backport was not clean.
cc @rust-lang/core @rust-lang/release
@pietroalbini pietroalbini added beta-nominated Nominated for backporting to the compiler in the beta channel. and removed beta-nominated Nominated for backporting to the compiler in the beta channel. labels Jun 3, 2018
bors added a commit that referenced this pull request Jun 3, 2018
[beta] Process backports

Merged and approved:

* #50812: Fix issue #50811 (`NaN > NaN` was true).
* #50879: Fix naming conventions for new lints
* #51011: rustdoc: hide macro export statements from docs
* #51051: prohibit turbofish in impl Trait methods
* #51052: restore emplacement syntax (obsolete)
* #51146: typeck: Do not pass the field check on field error
* #51235: remove notion of Implicit derefs from mem-cat

r? @ghost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta-accepted Accepted for backporting to the compiler in the beta channel. 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