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

Handle const-checks for &mut outside of HasMutInterior #66654

Merged
merged 12 commits into from
Dec 2, 2019

Conversation

ecstatic-morse
Copy link
Contributor

@ecstatic-morse ecstatic-morse commented Nov 23, 2019

Addresses this comment.

Const-checking relied on HasMutInterior to forbid &mut in a const context. This was strange because all we needed to do was look for an Rvalue::Ref with a certain BorrowKind, whereas the Qualif traits are specifically meant to get the qualifs for a value. This PR removes that logic from HasMutInterior and moves it into check_consts::Validator.

As a result, we can now properly handle qualifications for statics, which had to be ignored previously since you can e.g. borrow a static Cell from another static. We also remove the derived_from_illegal_borrow logic, since it is no longer necessary; we give good errors for subsequent reborrows/borrows of illegal borrows.

@rust-highfive
Copy link
Collaborator

r? @matthewjasper

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 23, 2019
@ecstatic-morse
Copy link
Contributor Author

ecstatic-morse commented Nov 23, 2019

r? @eddyb

(although I'd like to work on this a bit more, it's not quite ready)

@rust-highfive rust-highfive assigned eddyb and unassigned matthewjasper Nov 23, 2019
@ecstatic-morse ecstatic-morse changed the title Handle &mut outside of HasMutInterior Handle const-checks for &mut outside of HasMutInterior Nov 23, 2019
@bors
Copy link
Contributor

bors commented Nov 23, 2019

☔ The latest upstream changes (presumably #66640) made this pull request unmergeable. Please resolve the merge conflicts.

@Centril Centril added the F-const_mut_refs `#![feature(const_mut_refs)]` label Nov 23, 2019
fn in_static(_cx: &ConstCx<'_, 'tcx>, _static: &Static<'tcx>) -> bool {
// FIXME(eddyb) should we do anything here for value properties?
false
fn in_static(cx: &ConstCx<'_, 'tcx>, statik: &Static<'tcx>) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

(btw, a doc comment on these methods would be great)

.as_local()
.map_or(false, |local| self.derived_from_illegal_borrow.contains(local));

// Don't emit errors for borrows of values that are *themselves* the result of
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we delay_span_bug just in case?

@Centril
Copy link
Contributor

Centril commented Nov 23, 2019

cc @oli-obk @RalfJung

// Don't emit errors for borrows of values that are *themselves* the result of
// an illegal borrow (e.g., the outermost `&` in `&&Cell::new(42)`). We want to
// point the user to the place where the original illegal borrow occurred, not
// to subsequent borrows of the resulting value.
Copy link
Member

Choose a reason for hiding this comment

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

I thought this was resolved by simply not having any qualifs on &Cell::new(42).

&T is always Freeze + Copy, regardless of T, so no qualif bits need to be set.

The only reason they were before was for promotion, which is why we split promotion into its own check.

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 think you're right. This means I can clean up a lot more!

@ecstatic-morse ecstatic-morse force-pushed the check-consts-ref branch 2 times, most recently from c93bb56 to 639aeec Compare November 26, 2019 20:17
@ecstatic-morse ecstatic-morse marked this pull request as ready for review November 26, 2019 20:18
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 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.
2019-11-26T20:26:51.6870866Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-11-26T20:26:51.6903354Z ##[command]git config gc.auto 0
2019-11-26T20:26:51.6908846Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-11-26T20:26:51.6913595Z ##[command]git config --get-all http.proxy
2019-11-26T20:26:51.6919731Z ##[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/66654/merge:refs/remotes/pull/66654/merge
---
2019-11-26T21:25:38.2143962Z .................................................................................................... 1600/9295
2019-11-26T21:25:42.8018807Z .................................................................................................... 1700/9295
2019-11-26T21:25:55.6811304Z ................................i................................................................... 1800/9295
2019-11-26T21:26:02.5562769Z .................................................................................................... 1900/9295
2019-11-26T21:26:16.3348453Z .................iiiii.............................................................................. 2000/9295
2019-11-26T21:26:26.0703150Z .................................................................................................... 2200/9295
2019-11-26T21:26:28.5175957Z ..........F......................................................................................... 2300/9295
2019-11-26T21:26:33.5075819Z .................................................................................................... 2400/9295
2019-11-26T21:26:54.6075939Z .................................................................................................... 2500/9295
---
2019-11-26T21:29:31.3576682Z ..................i...............i................................................................. 4800/9295
2019-11-26T21:29:41.3974313Z .................................................................................................... 4900/9295
2019-11-26T21:29:47.2218832Z .................................................................................................... 5000/9295
2019-11-26T21:29:56.5631465Z .................................................................................................... 5100/9295
2019-11-26T21:30:02.7862513Z .......................ii.ii...........i............................................................ 5200/9295
2019-11-26T21:30:11.7894951Z .................................................................................................... 5400/9295
2019-11-26T21:30:22.4643240Z .................................................................................................... 5500/9295
2019-11-26T21:30:29.3904765Z .....i.............................................................................................. 5600/9295
2019-11-26T21:30:35.4539607Z .................................................................................................... 5700/9295
2019-11-26T21:30:35.4539607Z .................................................................................................... 5700/9295
2019-11-26T21:30:45.9135146Z ...........................................................................................ii...i..i 5800/9295
2019-11-26T21:30:58.2742645Z i...........i....................................................................................... 5900/9295
2019-11-26T21:31:16.0966157Z .................................................................................................... 6100/9295
2019-11-26T21:31:22.2939656Z .................................................................................................... 6200/9295
2019-11-26T21:31:22.2939656Z .................................................................................................... 6200/9295
2019-11-26T21:31:35.6874917Z ..............i..ii................................................................................. 6300/9295
2019-11-26T21:31:54.8735439Z ..................................................................................i................. 6500/9295
2019-11-26T21:31:57.1056972Z .................................................................................................... 6600/9295
2019-11-26T21:31:59.3626232Z .........................................................................i.......................... 6700/9295
2019-11-26T21:32:02.1179085Z .................................................................................................... 6800/9295
---
2019-11-26T21:36:43.5513322Z 
2019-11-26T21:36:43.5514067Z ---- [ui] ui/error-codes/E0017.rs stdout ----
2019-11-26T21:36:43.5514324Z diff of stderr:
2019-11-26T21:36:43.5514574Z 
2019-11-26T21:36:43.5515019Z 4 LL | const CR: &'static mut i32 = &mut C;
2019-11-26T21:36:43.5515245Z 5    |                              ^^^^^^ constants require immutable values
2019-11-26T21:36:43.5516188Z - error[E0017]: references in statics may only refer to immutable values
2019-11-26T21:36:43.5516639Z -   --> $DIR/E0017.rs:5:39
2019-11-26T21:36:43.5517086Z -    |
2019-11-26T21:36:43.5517086Z -    |
2019-11-26T21:36:43.5517510Z - LL | static STATIC_REF: &'static mut i32 = &mut X;
2019-11-26T21:36:43.5517986Z -    |                                       ^^^^^^ statics require immutable values
2019-11-26T21:36:43.5518607Z 13 error[E0596]: cannot borrow immutable static item `X` as mutable
2019-11-26T21:36:43.5518999Z 14   --> $DIR/E0017.rs:5:39
2019-11-26T21:36:43.5519201Z 15    |
2019-11-26T21:36:43.5519343Z 
---
2019-11-26T21:36:43.5521491Z 28 For more information about an error, try `rustc --explain E0017`.
2019-11-26T21:36:43.5522063Z 
2019-11-26T21:36:43.5524433Z 
2019-11-26T21:36:43.5524808Z The actual stderr differed from the expected stderr.
2019-11-26T21:36:43.5525381Z Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/error-codes/E0017/E0017.stderr
2019-11-26T21:36:43.5526288Z To update references, rerun the tests and pass the `--bless` flag
2019-11-26T21:36:43.5526798Z To only update this specific test, also pass `--test-args error-codes/E0017.rs`
2019-11-26T21:36:43.5527181Z error: 1 errors occurred comparing output.
2019-11-26T21:36:43.5527345Z status: exit code: 1
2019-11-26T21:36:43.5527345Z status: exit code: 1
2019-11-26T21:36:43.5528262Z command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/error-codes/E0017.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/error-codes/E0017" "-Crpath" "-O" "-Cdebuginfo=0" "-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/error-codes/E0017/auxiliary" "-A" "unused"
2019-11-26T21:36:43.5528962Z ------------------------------------------
2019-11-26T21:36:43.5529154Z 
2019-11-26T21:36:43.5529541Z ------------------------------------------
2019-11-26T21:36:43.5529764Z stderr:
2019-11-26T21:36:43.5529764Z stderr:
2019-11-26T21:36:43.5530140Z ------------------------------------------
2019-11-26T21:36:43.5530373Z error[E0017]: references in constants may only refer to immutable values
2019-11-26T21:36:43.5530796Z   --> /checkout/src/test/ui/error-codes/E0017.rs:4:30
2019-11-26T21:36:43.5531008Z    |
2019-11-26T21:36:43.5531404Z LL | const CR: &'static mut i32 = &mut C; //~ ERROR E0017
2019-11-26T21:36:43.5531644Z    |                              ^^^^^^ constants require immutable values
2019-11-26T21:36:43.5532002Z error[E0596]: cannot borrow immutable static item `X` as mutable
2019-11-26T21:36:43.5532549Z   --> /checkout/src/test/ui/error-codes/E0017.rs:5:39
2019-11-26T21:36:43.5535121Z    |
2019-11-26T21:36:43.5535121Z    |
2019-11-26T21:36:43.5538170Z LL | static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0017
2019-11-26T21:36:43.5538722Z 
2019-11-26T21:36:43.5538915Z error[E0017]: references in statics may only refer to immutable values
2019-11-26T21:36:43.5539353Z   --> /checkout/src/test/ui/error-codes/E0017.rs:7:38
2019-11-26T21:36:43.5545169Z    |
2019-11-26T21:36:43.5545169Z    |
2019-11-26T21:36:43.5546568Z LL | static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0017
2019-11-26T21:36:43.5546956Z    |                                      ^^^^^^ statics require immutable values
2019-11-26T21:36:43.5547379Z error: aborting due to 3 previous errors
2019-11-26T21:36:43.5547541Z 
2019-11-26T21:36:43.5547726Z Some errors have detailed explanations: E0017, E0596.
2019-11-26T21:36:43.5548303Z For more information about an error, try `rustc --explain E0017`.
2019-11-26T21:36:43.5548303Z For more information about an error, try `rustc --explain E0017`.
2019-11-26T21:36:43.5548549Z 
2019-11-26T21:36:43.5549005Z ------------------------------------------
2019-11-26T21:36:43.5549217Z 
2019-11-26T21:36:43.5549378Z 
2019-11-26T21:36:43.5549812Z ---- [ui] ui/error-codes/E0388.rs stdout ----
2019-11-26T21:36:43.5550074Z diff of stderr:
2019-11-26T21:36:43.5550259Z 
2019-11-26T21:36:43.5550700Z 4 LL | const CR: &'static mut i32 = &mut C;
2019-11-26T21:36:43.5550948Z 5    |                              ^^^^^^ constants require immutable values
2019-11-26T21:36:43.5551597Z - error[E0017]: references in statics may only refer to immutable values
2019-11-26T21:36:43.5552089Z -   --> $DIR/E0388.rs:5:39
2019-11-26T21:36:43.5552536Z -    |
2019-11-26T21:36:43.5552536Z -    |
2019-11-26T21:36:43.5553016Z - LL | static STATIC_REF: &'static mut i32 = &mut X;
2019-11-26T21:36:43.5553535Z -    |                                       ^^^^^^ statics require immutable values
2019-11-26T21:36:43.5554500Z 13 error[E0596]: cannot borrow immutable static item `X` as mutable
2019-11-26T21:36:43.5554946Z 14   --> $DIR/E0388.rs:5:39
2019-11-26T21:36:43.5555207Z 15    |
2019-11-26T21:36:43.5555365Z 
---
2019-11-26T21:36:43.5558348Z 28 For more information about an error, try `rustc --explain E0017`.
2019-11-26T21:36:43.5558587Z 
2019-11-26T21:36:43.5558757Z 
2019-11-26T21:36:43.5558939Z The actual stderr differed from the expected stderr.
2019-11-26T21:36:43.5559489Z Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/error-codes/E0388/E0388.stderr
2019-11-26T21:36:43.5560152Z To update references, rerun the tests and pass the `--bless` flag
2019-11-26T21:36:43.5560716Z To only update this specific test, also pass `--test-args error-codes/E0388.rs`
2019-11-26T21:36:43.5561130Z error: 1 errors occurred comparing output.
2019-11-26T21:36:43.5561311Z status: exit code: 1
2019-11-26T21:36:43.5561311Z status: exit code: 1
2019-11-26T21:36:43.5562364Z command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/error-codes/E0388.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/error-codes/E0388" "-Crpath" "-O" "-Cdebuginfo=0" "-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/error-codes/E0388/auxiliary" "-A" "unused"
2019-11-26T21:36:43.5563100Z ------------------------------------------
2019-11-26T21:36:43.5563471Z 
2019-11-26T21:36:43.5564075Z ------------------------------------------
2019-11-26T21:36:43.5564328Z stderr:
2019-11-26T21:36:43.5564328Z stderr:
2019-11-26T21:36:43.5564826Z ------------------------------------------
2019-11-26T21:36:43.5565084Z error[E0017]: references in constants may only refer to immutable values
2019-11-26T21:36:43.5570187Z   --> /checkout/src/test/ui/error-codes/E0388.rs:4:30
2019-11-26T21:36:43.5570550Z    |
2019-11-26T21:36:43.5571798Z LL | const CR: &'static mut i32 = &mut C; //~ ERROR E0017
2019-11-26T21:36:43.5575935Z    |                              ^^^^^^ constants require immutable values
2019-11-26T21:36:43.5576072Z error[E0596]: cannot borrow immutable static item `X` as mutable
2019-11-26T21:36:43.5576499Z   --> /checkout/src/test/ui/error-codes/E0388.rs:5:39
2019-11-26T21:36:43.5576556Z    |
2019-11-26T21:36:43.5576556Z    |
2019-11-26T21:36:43.5576870Z LL | static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0017
2019-11-26T21:36:43.5576982Z 
2019-11-26T21:36:43.5577034Z error[E0017]: references in statics may only refer to immutable values
2019-11-26T21:36:43.5577315Z   --> /checkout/src/test/ui/error-codes/E0388.rs:7:38
2019-11-26T21:36:43.5577368Z    |
2019-11-26T21:36:43.5577368Z    |
2019-11-26T21:36:43.5577637Z LL | static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0017
2019-11-26T21:36:43.5577717Z    |                                      ^^^^^^ statics require immutable values
2019-11-26T21:36:43.5577802Z error: aborting due to 3 previous errors
2019-11-26T21:36:43.5577835Z 
2019-11-26T21:36:43.5577899Z Some errors have detailed explanations: E0017, E0596.
2019-11-26T21:36:43.5578174Z For more information about an error, try `rustc --explain E0017`.
---
2019-11-26T21:36:43.5580015Z thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:537:22
2019-11-26T21:36:43.5580079Z note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
2019-11-26T21:36:43.5580116Z 
2019-11-26T21:36:43.5580160Z 
2019-11-26T21:36:43.5581853Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/ui" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "ui" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-6.0/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "6.0.0\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
2019-11-26T21:36:43.5582134Z 
2019-11-26T21:36:43.5582166Z 
2019-11-26T21:36:43.5582318Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
2019-11-26T21:36:43.5582385Z Build completed unsuccessfully in 1:04:00
2019-11-26T21:36:43.5582385Z Build completed unsuccessfully in 1:04:00
2019-11-26T21:36:43.5604435Z == clock drift check ==
2019-11-26T21:36:43.5621323Z   local time: Tue Nov 26 21:36:43 UTC 2019
2019-11-26T21:36:44.0965552Z   network time: Tue, 26 Nov 2019 21:36:44 GMT
2019-11-26T21:36:44.0974798Z == end clock drift check ==
2019-11-26T21:36:44.9331703Z 
2019-11-26T21:36:44.9471412Z ##[error]Bash exited with code '1'.
2019-11-26T21:36:44.9526744Z ##[section]Starting: Checkout
2019-11-26T21:36:44.9528990Z ==============================================================================
2019-11-26T21:36:44.9529077Z Task         : Get sources
2019-11-26T21:36:44.9529133Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

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)

@bors
Copy link
Contributor

bors commented Nov 27, 2019

☔ The latest upstream changes (presumably #66677) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Member

@eddyb eddyb left a comment

Choose a reason for hiding this comment

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

r=me

@ecstatic-morse
Copy link
Contributor Author

ecstatic-morse commented Nov 27, 2019

Now that #66640 has been merged, the const-checker treats borrows of a static as a reborrow since it looks like &(*_2) where _2 is a const pointer to the allocation for the static. See 7f35ab6dcc9d28e19dd39e7a413b47af0809acaf for a side-effect of this.

@matthewjasper I'm not quite sure why #66587 didn't cause this test to change. How do I check that &(*_2) is a reference to a static and not a reborrow of a local?

@matthewjasper
Copy link
Contributor

I believe it didn't change in that PR because we don't special case reborrows in visit_assign in master. From the changes shown this only appears to affect &mut IMMUTABLE_STATIC, which isn't a case that really matters.

@matthewjasper
Copy link
Contributor

The check_static_ptr method introduced in #66587 is the preferred way to check for statics.

This error code is never emitted, and the contents of this test are
identical to that of `E0017.rs`.
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 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.
2019-11-27T22:39:15.9017945Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-11-27T22:39:15.9198095Z ##[command]git config gc.auto 0
2019-11-27T22:39:15.9273760Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-11-27T22:39:15.9324970Z ##[command]git config --get-all http.proxy
2019-11-27T22:39:15.9467787Z ##[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/66654/merge:refs/remotes/pull/66654/merge
---
2019-11-27T23:35:29.3664487Z .................................................................................................... 1600/9297
2019-11-27T23:35:34.2446687Z .................................................................................................... 1700/9297
2019-11-27T23:35:46.9183205Z ...................................i................................................................ 1800/9297
2019-11-27T23:35:54.5729627Z .................................................................................................... 1900/9297
2019-11-27T23:36:08.2199834Z ....................iiiii........................................................................... 2000/9297
2019-11-27T23:36:18.2957489Z .................................................................................................... 2200/9297
2019-11-27T23:36:20.8593812Z .................................................................................................... 2300/9297
2019-11-27T23:36:25.7541058Z .................................................................................................... 2400/9297
2019-11-27T23:36:46.5730561Z .................................................................................................... 2500/9297
---
2019-11-27T23:39:26.8554452Z ....................i...............i............................................................... 4800/9297
2019-11-27T23:39:36.8948556Z ......................F............................................................................. 4900/9297
2019-11-27T23:39:42.3375024Z .................................................................................................... 5000/9297
2019-11-27T23:39:50.4419040Z .................................................................................................... 5100/9297
2019-11-27T23:39:57.5701872Z .........................ii.ii...........i.......................................................... 5200/9297
2019-11-27T23:40:06.6494136Z .................................................................................................... 5400/9297
2019-11-27T23:40:17.2677575Z .................................................................................................... 5500/9297
2019-11-27T23:40:24.1436208Z .......i............................................................................................ 5600/9297
2019-11-27T23:40:30.3823101Z .................................................................................................... 5700/9297
2019-11-27T23:40:30.3823101Z .................................................................................................... 5700/9297
2019-11-27T23:40:40.8788029Z .............................................................................................ii...i. 5800/9297
2019-11-27T23:40:53.0136355Z .ii...........i..................................................................................... 5900/9297
2019-11-27T23:41:11.0379104Z .................................................................................................... 6100/9297
2019-11-27T23:41:16.4742387Z .................................................................................................... 6200/9297
2019-11-27T23:41:16.4742387Z .................................................................................................... 6200/9297
2019-11-27T23:41:30.3943050Z ................i..ii............................................................................... 6300/9297
2019-11-27T23:41:49.6879464Z ....................................................................................i............... 6500/9297
2019-11-27T23:41:51.9847155Z .................................................................................................... 6600/9297
2019-11-27T23:41:54.2636855Z ...........................................................................i........................ 6700/9297
2019-11-27T23:41:56.9761978Z .................................................................................................... 6800/9297
---
2019-11-27T23:46:41.2473327Z failures:
2019-11-27T23:46:41.2513123Z 
2019-11-27T23:46:41.2513885Z ---- [ui] ui/issues/issue-52060.rs stdout ----
2019-11-27T23:46:41.2514101Z 
2019-11-27T23:46:41.2514327Z error: Error: expected failure status (Some(1)) but received status Some(101).
2019-11-27T23:46:41.2514487Z status: exit code: 101
2019-11-27T23:46:41.2515532Z command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/issues/issue-52060.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/issues/issue-52060" "-Crpath" "-O" "-Cdebuginfo=0" "-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/issues/issue-52060/auxiliary" "-A" "unused"
2019-11-27T23:46:41.2516132Z ------------------------------------------
2019-11-27T23:46:41.2516292Z 
2019-11-27T23:46:41.2516628Z ------------------------------------------
2019-11-27T23:46:41.2516825Z stderr:
2019-11-27T23:46:41.2516825Z stderr:
2019-11-27T23:46:41.2517176Z ------------------------------------------
2019-11-27T23:46:41.2517357Z error[E0013]: constants cannot refer to statics, use a constant instead
2019-11-27T23:46:41.2517750Z   --> /checkout/src/test/ui/issues/issue-52060.rs:4:26
2019-11-27T23:46:41.2517929Z    |
2019-11-27T23:46:41.2518064Z LL | static B: [u32; 1] = [0; A.len()];
2019-11-27T23:46:41.2518580Z 
2019-11-27T23:46:41.2518580Z 
2019-11-27T23:46:41.2519001Z thread 'rustc' panicked at 'assertion failed: inner.is_empty()', src/librustc_mir/transform/check_consts/validation.rs:713:21
2019-11-27T23:46:41.2519401Z 
2019-11-27T23:46:41.2519559Z error: internal compiler error: unexpected panic
2019-11-27T23:46:41.2519909Z 
2019-11-27T23:46:41.2520056Z note: the compiler unexpectedly panicked. this is a bug.
2019-11-27T23:46:41.2520056Z note: the compiler unexpectedly panicked. this is a bug.
2019-11-27T23:46:41.2520177Z 
2019-11-27T23:46:41.2520919Z note: we would appreciate a bug report: ***/blob/master/CONTRIBUTING.md#bug-reports
2019-11-27T23:46:41.2521495Z note: rustc 1.41.0-dev running on x86_64-unknown-linux-gnu
2019-11-27T23:46:41.2521673Z 
2019-11-27T23:46:41.2521673Z 
2019-11-27T23:46:41.2522076Z note: compiler flags: -Z threads=1 -Z ui-testing -Z unstable-options -C prefer-dynamic -C rpath -C debuginfo=0
2019-11-27T23:46:41.2522397Z error: aborting due to previous error
2019-11-27T23:46:41.2522515Z 
2019-11-27T23:46:41.2522868Z For more information about this error, try `rustc --explain E0013`.
2019-11-27T23:46:41.2523041Z 
---
2019-11-27T23:46:41.2556827Z thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:537:22
2019-11-27T23:46:41.2557173Z note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
2019-11-27T23:46:41.2573774Z 
2019-11-27T23:46:41.2574416Z 
2019-11-27T23:46:41.2576746Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/ui" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "ui" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-6.0/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "6.0.0\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
2019-11-27T23:46:41.2577029Z 
2019-11-27T23:46:41.2577080Z 
2019-11-27T23:46:41.2590223Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
2019-11-27T23:46:41.2590338Z Build completed unsuccessfully in 1:01:36
2019-11-27T23:46:41.2590338Z Build completed unsuccessfully in 1:01:36
2019-11-27T23:46:41.2647475Z == clock drift check ==
2019-11-27T23:46:41.2664751Z   local time: Wed Nov 27 23:46:41 UTC 2019
2019-11-27T23:46:41.7894175Z   network time: Wed, 27 Nov 2019 23:46:41 GMT
2019-11-27T23:46:41.7894913Z == end clock drift check ==
2019-11-27T23:46:42.4700512Z 
2019-11-27T23:46:42.4794734Z ##[error]Bash exited with code '1'.
2019-11-27T23:46:42.4840262Z ##[section]Starting: Checkout
2019-11-27T23:46:42.4842100Z ==============================================================================
2019-11-27T23:46:42.4842156Z Task         : Get sources
2019-11-27T23:46:42.4842205Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

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)

They now look the same in the MIR after rust-lang#66587.
This checks `static mut` as well for E0017, and blesses tests now that
we emit an error for a mut deref.
@ecstatic-morse
Copy link
Contributor Author

ecstatic-morse commented Nov 28, 2019

@eddyb I had to make a few changes in place_as_reborrow now that we use a const pointer to memory to represent a static. I also refactored my changes a bit and removed CheckOpResult as well. The basic idea remains the same.

if let LocalInfo::StaticRef { .. } = decl.local_info {
return None;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

@matthewjasper isn't this supposed to use a helper method?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, there's body.local_decls[local].is_ref_to_static

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@matthewjasper Resolved in ccb4eed.

| Rvalue::Ref(_, BorrowKind::Shared, ref place)
| Rvalue::Ref(_, BorrowKind::Shallow, ref place)
if matches!(place.base, PlaceBase::Static(_))
=> {}
Copy link
Member

Choose a reason for hiding this comment

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

Does this make sense anymore, with the static changes?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, this shouldn't be reachable, since the only PlaceBase::Statics are promoted. This maybe should be bug!() for now.

@eddyb
Copy link
Member

eddyb commented Nov 28, 2019

r? @matthewjasper for all the static-related parts (as I'm not familiar with the new setup)

@rust-highfive rust-highfive assigned matthewjasper and unassigned eddyb Nov 28, 2019
@matthewjasper matthewjasper added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 30, 2019
@matthewjasper
Copy link
Contributor

@bors r=eddyb,matthewjasper

@bors
Copy link
Contributor

bors commented Dec 2, 2019

📌 Commit ccb4eed has been approved by eddyb,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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 2, 2019
RalfJung added a commit to RalfJung/rust that referenced this pull request Dec 2, 2019
…eddyb,matthewjasper

Handle const-checks for `&mut` outside of `HasMutInterior`

Addresses [this comment](rust-lang#64470 (comment)).

Const-checking relied on `HasMutInterior` to forbid `&mut` in a const context. This was strange because all we needed to do was look for an `Rvalue::Ref` with a certain `BorrowKind`, whereas the `Qualif` traits are specifically meant to get the qualifs for a *value*. This PR removes that logic from `HasMutInterior` and moves it into `check_consts::Validator`.

As a result, we can now properly handle qualifications for `static`s, which had to be ignored previously since you can e.g. borrow a static `Cell` from another `static`. We also remove the `derived_from_illegal_borrow` logic, since it is no longer necessary; we give good errors for subsequent reborrows/borrows of illegal borrows.
bors added a commit that referenced this pull request Dec 2, 2019
Rollup of 5 pull requests

Successful merges:

 - #66245 (Conditional compilation for sanitizers)
 - #66654 (Handle const-checks for `&mut` outside of `HasMutInterior`)
 - #66822 (libunwind_panic: adjust miri panic hack)
 - #66827 (handle diverging functions forwarding their return place)
 - #66834 (rustbuild fixes)

Failed merges:

r? @ghost
@bors bors merged commit ccb4eed into rust-lang:master Dec 2, 2019
@ecstatic-morse ecstatic-morse deleted the check-consts-ref branch October 6, 2020 01:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-const_mut_refs `#![feature(const_mut_refs)]` 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