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

Also run UnusedBrokenConst on associated consts. #70017

Closed
wants to merge 11 commits into from

Conversation

jumbatm
Copy link
Contributor

@jumbatm jumbatm commented Mar 15, 2020

Fixes #69021.

Changes UnusedBrokenConst to also run on associated consts (when previously, it only ran on consts). Previously, if an associated const was unused, we would not end up linting the value, because const_prop (where check_{unary, binary}_op are run) would never reach the value.

r? @RalfJung

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 15, 2020
@rust-highfive

This comment has been minimized.

@RalfJung
Copy link
Member

Cc @oli-obk @wesleywiser

@jumbatm jumbatm force-pushed the exceeding-bitshifts branch from d7a845c to 4af3649 Compare March 15, 2020 10:25
check_const(cx, body_id);
}
_ => {}
}
}
fn check_impl_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::ImplItem<'_>) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can also have associated constants with default values in trait definitions. Also consider const generics here, e.g. foo::<{BAD_CONSTANT}>();.

Copy link
Contributor

Choose a reason for hiding this comment

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

in order to do this you can eval all anonconsts, which will also cover a few other cases (though I think they are already evaluated elsewhere)

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's do this in a separate PR though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing

debug!("const_eval_poly: running on {:?}: {:?}", def_id, ty);

// FIXME: This check could be smarter / faster.
let is_generic = |t: Ty<'_>| -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

this isn't the only way that it can be too generic, the final decision on whether it is too generic is made during const eval. why was it necessary to add this check? just for speed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's to address this test case. In this case, the call to layout_of fails

let layout = self.layout_of(pointee_type)?;

because T isn't known yet -- we're not running on a specific instance of T. The error is bubbled up, transformed into a validation failure, and is caught in the catch-all here:

match err.struct_error(ecx.tcx, "it is undefined behavior to use this value", |mut diag| {
diag.note(note_on_undefined_behavior_error());
diag.emit();
}) {
Ok(_) => ErrorHandled::Reported,
Err(err) => err,

As I understand it, the test case failure boils down to not having a concrete type to substitute into T -- this is something we currently don't run into, because check_binary_op currently runs when const_prop reaches a use of the value, so there's always some actual type to substitute in to get a layout for.

Other TooGeneric failures are currently caught in that catch-all error emit above. My initial thought when I ran into this was to modify the functions along the callstack so instead of catching the error, turning it into a validation failure and reporting the error, they can throw TooGeneric all the way up and let the caller decide what to do with them (so, in the case of check_const, it would just ignore the TooGeneric and move on). This seemed a bit too specific, though, and checking here seemed sufficient -- and yes, maybe even a little bit faster.

I've just noticed the struct_error here is actually const eval's struct_error, which looks like could already bubble TooGeneric up. Hmm -- I'll have a look at how it goes if the layout_of caller does a check to throw TooGeneric instead of undefined pointer.

Copy link
Contributor

Choose a reason for hiding this comment

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

yea, I think we should fix this in const eval. although the last time I tried, I did it wrongly. maybe it suffices to use a UserFacing ParamEnv for associated constants?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just having this change didn't end up solving the issue -- as it turns out, it wasn't const eval that was failing in the first place, but validation afterwards. I resolved this by changing validation to not fail on pointers to Params (which should hopefully only be reached when checking unused constants).

@RalfJung
Copy link
Member

Fixes #69021.

If this was the case, the behavior of ui/lint/lint-exceeding-bitshifts.rs should change. There is a FIXME in that test that corresponds to #69021. But it seems this doesn't actually fix the problem? This is probably because const-prop does not run on that associated cons, and it cannot be evaluated because of the generic dependency.

let substs = InternalSubsts::identity_for_item(self, def_id);
let instance = ty::Instance::new(def_id, substs);
let cid = GlobalId { instance, promoted: None };
let param_env = self.param_env(def_id).with_reveal_all();
Copy link
Contributor

Choose a reason for hiding this comment

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

right here ,if you skip doing the reveal all if the instance .needs_subst() you should hopefully not get an ICE anymore, because the relevant code bails out with TooGeneric

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apologies if I wasn't clear -- I haven't been getting an ICE. In my previous comment, by an error bubbling up, I meant an Err being returned upwards (which ends in us gracefully emitting a diagnostic to the user). Hmm -- I'm wonder if doing this anyway will bail out with TooGeneric where I need it to.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, without reveal all, such errors will not be emitted but become TooGeneric

Copy link
Contributor

Choose a reason for hiding this comment

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

This hasn't been addressed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most feedback hasn't yet. I'm still working on this pr. I think it's showing as outdated because I squashed & dropped some commits. I will ping you all and re-mark as waiting on review when this is ready to go again 👍

@RalfJung RalfJung 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 Mar 18, 2020
@jumbatm jumbatm force-pushed the exceeding-bitshifts branch from 4af3649 to b34843f Compare March 18, 2020 20:35
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-7 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.
2020-03-18T20:43:07.3306796Z ========================== Starting Command Output ===========================
2020-03-18T20:43:07.3309253Z [command]/bin/bash --noprofile --norc /home/vsts/work/_temp/4e1ccbe8-a053-4397-9d0a-1bad7936445a.sh
2020-03-18T20:43:07.3309503Z 
2020-03-18T20:43:07.3313496Z ##[section]Finishing: Disable git automatic line ending conversion
2020-03-18T20:43:07.3328949Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/70017/merge to s
2020-03-18T20:43:07.3331568Z Task         : Get sources
2020-03-18T20:43:07.3331817Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-03-18T20:43:07.3332073Z Version      : 1.0.0
2020-03-18T20:43:07.3332235Z Author       : Microsoft
---
2020-03-18T20:43:08.6731461Z ##[command]git remote add origin https://github.com/rust-lang/rust
2020-03-18T20:43:08.6736076Z ##[command]git config gc.auto 0
2020-03-18T20:43:08.6738597Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2020-03-18T20:43:08.6740914Z ##[command]git config --get-all http.proxy
2020-03-18T20:43:08.6746021Z ##[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/70017/merge:refs/remotes/pull/70017/merge
---
2020-03-18T21:32:40.2561362Z .................................................................................................... 1700/9798
2020-03-18T21:32:43.9127050Z ...............................................FFF.................................................. 1800/9798
2020-03-18T21:32:53.6219701Z ............................................................................i....................... 1900/9798
2020-03-18T21:32:59.0286957Z .................................................................................................... 2000/9798
2020-03-18T21:33:05.9616291Z ..................................................................iiiii............................. 2100/9798
2020-03-18T21:33:21.4629011Z .................................................................................................... 2300/9798
2020-03-18T21:33:23.3727269Z .................................................................................................... 2400/9798
2020-03-18T21:33:25.7436658Z .................................................................................................... 2500/9798
2020-03-18T21:33:42.7413809Z .................................................................................................... 2600/9798
---
2020-03-18T21:36:00.9803857Z ......................................i...............i............................................. 5000/9798
2020-03-18T21:36:08.7609007Z .................................................................................................... 5100/9798
2020-03-18T21:36:14.2622790Z .................................................................................i.................. 5200/9798
2020-03-18T21:36:19.0265810Z .................................................................................................... 5300/9798
2020-03-18T21:36:27.5754145Z ..............................................................ii.ii........i...i.................... 5400/9798
2020-03-18T21:36:34.4968808Z .i.................................................................................................. 5600/9798
2020-03-18T21:36:42.5996518Z .................................................................................................... 5700/9798
2020-03-18T21:36:48.0077988Z .......................................................i............................................ 5800/9798
2020-03-18T21:36:53.5328175Z .................................................................................................... 5900/9798
2020-03-18T21:36:53.5328175Z .................................................................................................... 5900/9798
2020-03-18T21:37:00.6213461Z .................................................................................................... 6000/9798
2020-03-18T21:37:07.2888360Z .................................................ii...i..ii...........i............................. 6100/9798
2020-03-18T21:37:25.0967776Z .................................................................................................... 6300/9798
2020-03-18T21:37:28.2084919Z .................................................................................................... 6400/9798
2020-03-18T21:37:28.2084919Z .................................................................................................... 6400/9798
2020-03-18T21:37:31.7334321Z ...............................................................................i..ii................ 6500/9798
2020-03-18T21:37:51.6563298Z .................................................................................................... 6700/9798
2020-03-18T21:37:59.4860318Z .............................................................................i...................... 6800/9798
2020-03-18T21:38:01.2644646Z .................................................................................................... 6900/9798
2020-03-18T21:38:03.0914226Z .................................................................................................... 7000/9798
---
2020-03-18T21:39:32.1261837Z .................................................................................................... 7800/9798
2020-03-18T21:39:36.8438832Z .................................................................................................... 7900/9798
2020-03-18T21:39:42.1121157Z ...............................................................i.................................... 8000/9798
2020-03-18T21:39:50.9254009Z .................................................................................................... 8100/9798
2020-03-18T21:39:55.5997325Z ............iiiiiiiiii.i............................................................................ 8200/9798
2020-03-18T21:40:07.3718466Z .................................................................................................... 8400/9798
2020-03-18T21:40:14.2863854Z .................................................................................................... 8500/9798
2020-03-18T21:40:25.8747662Z .................................................................................................... 8600/9798
2020-03-18T21:40:31.4622466Z .................................................................................................... 8700/9798
---
2020-03-18T21:41:57.9338698Z .................................................................................................... 9700/9798
2020-03-18T21:42:10.4653408Z ..i...............................................................................................
2020-03-18T21:42:10.4658432Z failures:
2020-03-18T21:42:10.4678281Z 
2020-03-18T21:42:10.4679867Z ---- [ui] ui/associated-const/lints-used-unused.rs#unused stdout ----
2020-03-18T21:42:10.4680698Z error: this arithmetic operation will overflow
2020-03-18T21:42:10.4681359Z   --> $DIR/lints-used-unused.rs:16:20
2020-03-18T21:42:10.4681684Z    |
2020-03-18T21:42:10.4681975Z LL |     const N: i32 = 1 << 42;
---
2020-03-18T21:42:10.4693809Z 
2020-03-18T21:42:10.4694050Z 
2020-03-18T21:42:10.4694821Z 
2020-03-18T21:42:10.4695109Z The actual stderr differed from the expected stderr.
2020-03-18T21:42:10.4696692Z Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/associated-const/lints-used-unused.unused/lints-used-unused.unused.stderr
2020-03-18T21:42:10.4698246Z To update references, rerun the tests and pass the `--bless` flag
2020-03-18T21:42:10.4699537Z To only update this specific test, also pass `--test-args associated-const/lints-used-unused.rs`
2020-03-18T21:42:10.4702334Z error in revision `unused`: 1 errors occurred comparing output.
2020-03-18T21:42:10.4703644Z status: exit code: 1
2020-03-18T21:42:10.4703644Z status: exit code: 1
2020-03-18T21:42:10.4705938Z command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/associated-const/lints-used-unused.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--cfg" "unused" "--error-format" "json" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/associated-const/lints-used-unused.unused" "-Crpath" "-Cdebuginfo=0" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-A" "unused" "-Copt-level=2" "--emit" "link" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/associated-const/lints-used-unused.unused/auxiliary"
2020-03-18T21:42:10.4712204Z ------------------------------------------
2020-03-18T21:42:10.4713559Z 
2020-03-18T21:42:10.4714675Z ------------------------------------------
2020-03-18T21:42:10.4717045Z stderr:
---
2020-03-18T21:42:10.4732794Z 
2020-03-18T21:42:10.4733339Z ------------------------------------------
2020-03-18T21:42:10.4733643Z 
2020-03-18T21:42:10.4733861Z 
2020-03-18T21:42:10.4734427Z ---- [ui] ui/associated-const/lints-used-unused.rs#used stdout ----
2020-03-18T21:42:10.4735201Z error: this arithmetic operation will overflow
2020-03-18T21:42:10.4735801Z   --> $DIR/lints-used-unused.rs:16:20
2020-03-18T21:42:10.4736136Z    |
2020-03-18T21:42:10.4736451Z LL |     const N: i32 = 1 << 42;
---
2020-03-18T21:42:10.4745679Z 
2020-03-18T21:42:10.4745787Z 
2020-03-18T21:42:10.4745876Z 
2020-03-18T21:42:10.4746072Z The actual stderr differed from the expected stderr.
2020-03-18T21:42:10.4746748Z Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/associated-const/lints-used-unused.used/lints-used-unused.used.stderr
2020-03-18T21:42:10.4747385Z To update references, rerun the tests and pass the `--bless` flag
2020-03-18T21:42:10.4747960Z To only update this specific test, also pass `--test-args associated-const/lints-used-unused.rs`
2020-03-18T21:42:10.4748435Z error in revision `used`: 1 errors occurred comparing output.
2020-03-18T21:42:10.4748694Z status: exit code: 1
2020-03-18T21:42:10.4748694Z status: exit code: 1
2020-03-18T21:42:10.4753150Z command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/associated-const/lints-used-unused.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--cfg" "used" "--error-format" "json" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/associated-const/lints-used-unused.used" "-Crpath" "-Cdebuginfo=0" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-A" "unused" "-Copt-level=2" "--emit" "link" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/associated-const/lints-used-unused.used/auxiliary"
2020-03-18T21:42:10.4754837Z ------------------------------------------
2020-03-18T21:42:10.4755000Z 
2020-03-18T21:42:10.4755334Z ------------------------------------------
2020-03-18T21:42:10.4755519Z stderr:
---
2020-03-18T21:42:10.4763053Z ---- [ui] ui/consts/const-eval/ice-generic-assoc-const.rs stdout ----
2020-03-18T21:42:10.4763228Z 
2020-03-18T21:42:10.4763554Z error: test compilation failed although it shouldn't!
2020-03-18T21:42:10.4763763Z status: exit code: 1
2020-03-18T21:42:10.4765441Z command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/consts/const-eval/ice-generic-assoc-const.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/const-eval/ice-generic-assoc-const" "-Crpath" "-O" "-Cdebuginfo=0" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-A" "unused" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/const-eval/ice-generic-assoc-const/auxiliary"
2020-03-18T21:42:10.4766791Z ------------------------------------------
2020-03-18T21:42:10.4766935Z 
2020-03-18T21:42:10.4767222Z ------------------------------------------
2020-03-18T21:42:10.4767384Z stderr:
2020-03-18T21:42:10.4767384Z stderr:
2020-03-18T21:42:10.4767692Z ------------------------------------------
2020-03-18T21:42:10.4767929Z error[E0080]: it is undefined behavior to use this value
2020-03-18T21:42:10.4768391Z   --> /checkout/src/test/ui/consts/const-eval/ice-generic-assoc-const.rs:10:5
2020-03-18T21:42:10.4768626Z    |
2020-03-18T21:42:10.4768818Z LL |     const NULL: Self = core::ptr::null::<T>();
2020-03-18T21:42:10.4769189Z    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered undefined pointer
2020-03-18T21:42:10.4769458Z    |
2020-03-18T21:42:10.4770176Z    = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
2020-03-18T21:42:10.4770730Z error: aborting due to previous error
2020-03-18T21:42:10.4770901Z 
2020-03-18T21:42:10.4771273Z For more information about this error, try `rustc --explain E0080`.
2020-03-18T21:42:10.4771446Z 
---
2020-03-18T21:42:10.4773052Z 8 
2020-03-18T21:42:10.4773223Z + error: any use of this value will cause an error
2020-03-18T21:42:10.4773596Z +   --> $DIR/issue-69020.rs:21:22
2020-03-18T21:42:10.4773759Z +    |
2020-03-18T21:42:10.4774129Z + LL |     const NEG: i32 = -i32::MIN + T::NEG;
2020-03-18T21:42:10.4774731Z +    |                      |
2020-03-18T21:42:10.4774951Z +    |                      attempt to negate with overflow
2020-03-18T21:42:10.4775151Z +    |
2020-03-18T21:42:10.4775325Z +    = note: `#[deny(const_err)]` on by default
2020-03-18T21:42:10.4775325Z +    = note: `#[deny(const_err)]` on by default
2020-03-18T21:42:10.4775491Z + 
2020-03-18T21:42:10.4775675Z 9 error: this arithmetic operation will overflow
2020-03-18T21:42:10.4776030Z 10   --> $DIR/issue-69020.rs:23:22
2020-03-18T21:42:10.4776190Z 11    |
2020-03-18T21:42:10.4776280Z 
2020-03-18T21:42:10.4776484Z 12 LL |     const ADD: i32 = (i32::MAX+1) + T::ADD;
2020-03-18T21:42:10.4778978Z 14 
2020-03-18T21:42:10.4779167Z + error: any use of this value will cause an error
2020-03-18T21:42:10.4779691Z +   --> $DIR/issue-69020.rs:23:22
2020-03-18T21:42:10.4779851Z +    |
2020-03-18T21:42:10.4779851Z +    |
2020-03-18T21:42:10.4780059Z + LL |     const ADD: i32 = (i32::MAX+1) + T::ADD;
2020-03-18T21:42:10.4780665Z +    |                      |
2020-03-18T21:42:10.4780892Z +    |                      attempt to add with overflow
2020-03-18T21:42:10.4781065Z + 
2020-03-18T21:42:10.4781229Z 15 error: this operation will panic at runtime
---
2020-03-18T21:42:10.4782335Z 22 
2020-03-18T21:42:10.4782506Z + error: any use of this value will cause an error
2020-03-18T21:42:10.4782872Z +   --> $DIR/issue-69020.rs:25:22
2020-03-18T21:42:10.4783029Z +    |
2020-03-18T21:42:10.4783205Z + LL |     const DIV: i32 = (1/0) + T::DIV;
2020-03-18T21:42:10.4783779Z +    |                      |
2020-03-18T21:42:10.4783987Z +    |                      attempt to divide by zero
2020-03-18T21:42:10.4784154Z + 
2020-03-18T21:42:10.4784335Z 23 error: this operation will panic at runtime
2020-03-18T21:42:10.4784335Z 23 error: this operation will panic at runtime
2020-03-18T21:42:10.4784684Z 24   --> $DIR/issue-69020.rs:27:22
2020-03-18T21:42:10.4784842Z 25    |
2020-03-18T21:42:10.4784945Z 
2020-03-18T21:42:10.4785123Z 26 LL |     const OOB: i32 = [1][1] + T::OOB;
2020-03-18T21:42:10.4785696Z 28 
2020-03-18T21:42:10.4785995Z - error: aborting due to 4 previous errors
2020-03-18T21:42:10.4786224Z + error: any use of this value will cause an error
2020-03-18T21:42:10.4786782Z +   --> $DIR/issue-69020.rs:27:22
2020-03-18T21:42:10.4786782Z +   --> $DIR/issue-69020.rs:27:22
2020-03-18T21:42:10.4786979Z +    |
2020-03-18T21:42:10.4787441Z + LL |     const OOB: i32 = [1][1] + T::OOB;
2020-03-18T21:42:10.4788235Z +    |                      |
2020-03-18T21:42:10.4788540Z +    |                      index out of bounds: the len is 1 but the index is 1
2020-03-18T21:42:10.4788796Z + 
2020-03-18T21:42:10.4789043Z + error: aborting due to 8 previous errors
2020-03-18T21:42:10.4789043Z + error: aborting due to 8 previous errors
2020-03-18T21:42:10.4789225Z 30 
2020-03-18T21:42:10.4789339Z 31 
2020-03-18T21:42:10.4789436Z 
2020-03-18T21:42:10.4789630Z 
2020-03-18T21:42:10.4789823Z The actual stderr differed from the expected stderr.
2020-03-18T21:42:10.4790473Z Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/issue-69020.noopt/issue-69020.noopt.stderr
2020-03-18T21:42:10.4791077Z To update references, rerun the tests and pass the `--bless` flag
2020-03-18T21:42:10.4791606Z To only update this specific test, also pass `--test-args consts/issue-69020.rs`
2020-03-18T21:42:10.4791825Z 
2020-03-18T21:42:10.4792059Z error in revision `noopt`: 1 errors occurred comparing output.
2020-03-18T21:42:10.4792322Z status: exit code: 1
2020-03-18T21:42:10.4794336Z command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/consts/issue-69020.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--cfg" "noopt" "--error-format" "json" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/issue-69020.noopt" "-Crpath" "-Cdebuginfo=0" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-A" "unused" "-C" "opt-level=0" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/issue-69020.noopt/auxiliary"
2020-03-18T21:42:10.4796132Z ------------------------------------------
2020-03-18T21:42:10.4796318Z 
2020-03-18T21:42:10.4796678Z ------------------------------------------
2020-03-18T21:42:10.4797659Z stderr:
2020-03-18T21:42:10.4797659Z stderr:
2020-03-18T21:42:10.4798029Z ------------------------------------------
2020-03-18T21:42:10.4798289Z error: this arithmetic operation will overflow
2020-03-18T21:42:10.4798891Z   --> /checkout/src/test/ui/consts/issue-69020.rs:21:22
2020-03-18T21:42:10.4799124Z    |
2020-03-18T21:42:10.4799635Z LL |     const NEG: i32 = -i32::MIN + T::NEG;
2020-03-18T21:42:10.4800360Z    |
2020-03-18T21:42:10.4800571Z    = note: `#[deny(arithmetic_overflow)]` on by default
2020-03-18T21:42:10.4800754Z 
2020-03-18T21:42:10.4800942Z error: any use of this value will cause an error
2020-03-18T21:42:10.4800942Z error: any use of this value will cause an error
2020-03-18T21:42:10.4801433Z   --> /checkout/src/test/ui/consts/issue-69020.rs:21:22
2020-03-18T21:42:10.4801645Z    |
2020-03-18T21:42:10.4802010Z LL |     const NEG: i32 = -i32::MIN + T::NEG;
2020-03-18T21:42:10.4802672Z    |                      |
2020-03-18T21:42:10.4803024Z    |                      attempt to negate with overflow
2020-03-18T21:42:10.4808116Z    |
2020-03-18T21:42:10.4808307Z    = note: `#[deny(const_err)]` on by default
2020-03-18T21:42:10.4808307Z    = note: `#[deny(const_err)]` on by default
2020-03-18T21:42:10.4808455Z 
2020-03-18T21:42:10.4808615Z error: this arithmetic operation will overflow
2020-03-18T21:42:10.4814877Z   --> /checkout/src/test/ui/consts/issue-69020.rs:23:22
2020-03-18T21:42:10.4815132Z    |
2020-03-18T21:42:10.4815355Z LL |     const ADD: i32 = (i32::MAX+1) + T::ADD;
2020-03-18T21:42:10.4815895Z 
2020-03-18T21:42:10.4816084Z error: any use of this value will cause an error
2020-03-18T21:42:10.4816809Z   --> /checkout/src/test/ui/consts/issue-69020.rs:23:22
2020-03-18T21:42:10.4817044Z    |
2020-03-18T21:42:10.4817044Z    |
2020-03-18T21:42:10.4817260Z LL |     const ADD: i32 = (i32::MAX+1) + T::ADD;
2020-03-18T21:42:10.4817966Z    |                      |
2020-03-18T21:42:10.4818204Z    |                      attempt to add with overflow
2020-03-18T21:42:10.4818520Z 
2020-03-18T21:42:10.4818718Z error: this operation will panic at runtime
2020-03-18T21:42:10.4818718Z error: this operation will panic at runtime
2020-03-18T21:42:10.4819183Z   --> /checkout/src/test/ui/consts/issue-69020.rs:25:22
2020-03-18T21:42:10.4819395Z    |
2020-03-18T21:42:10.4819681Z LL |     const DIV: i32 = (1/0) + T::DIV;
2020-03-18T21:42:10.4820161Z    |
2020-03-18T21:42:10.4820369Z    = note: `#[deny(unconditional_panic)]` on by default
2020-03-18T21:42:10.4820570Z 
2020-03-18T21:42:10.4820756Z error: any use of this value will cause an error
2020-03-18T21:42:10.4820756Z error: any use of this value will cause an error
2020-03-18T21:42:10.4821224Z   --> /checkout/src/test/ui/consts/issue-69020.rs:25:22
2020-03-18T21:42:10.4821449Z    |
2020-03-18T21:42:10.4821642Z LL |     const DIV: i32 = (1/0) + T::DIV;
2020-03-18T21:42:10.4822276Z    |                      |
2020-03-18T21:42:10.4822507Z    |                      attempt to divide by zero
2020-03-18T21:42:10.4822676Z 
2020-03-18T21:42:10.4822859Z error: this operation will panic at runtime
2020-03-18T21:42:10.4822859Z error: this operation will panic at runtime
2020-03-18T21:42:10.4823319Z   --> /checkout/src/test/ui/consts/issue-69020.rs:27:22
2020-03-18T21:42:10.4823669Z    |
2020-03-18T21:42:10.4823874Z LL |     const OOB: i32 = [1][1] + T::OOB;
2020-03-18T21:42:10.4824503Z 
2020-03-18T21:42:10.4824693Z error: any use of this value will cause an error
2020-03-18T21:42:10.4825177Z   --> /checkout/src/test/ui/consts/issue-69020.rs:27:22
2020-03-18T21:42:10.4825388Z    |
2020-03-18T21:42:10.4825388Z    |
2020-03-18T21:42:10.4825590Z LL |     const OOB: i32 = [1][1] + T::OOB;
2020-03-18T21:42:10.4826437Z    |                      |
2020-03-18T21:42:10.4826959Z    |                      index out of bounds: the len is 1 but the index is 1
2020-03-18T21:42:10.4827204Z 
2020-03-18T21:42:10.4827401Z error: aborting due to 8 previous errors
---
2020-03-18T21:42:10.4829904Z 8 
2020-03-18T21:42:10.4830115Z + error: any use of this value will cause an error
2020-03-18T21:42:10.4830543Z +   --> $DIR/issue-69020.rs:21:22
2020-03-18T21:42:10.4830904Z +    |
2020-03-18T21:42:10.4831329Z + LL |     const NEG: i32 = -i32::MIN + T::NEG;
2020-03-18T21:42:10.4832046Z +    |                      |
2020-03-18T21:42:10.4832329Z +    |                      attempt to negate with overflow
2020-03-18T21:42:10.4832553Z +    |
2020-03-18T21:42:10.4832773Z +    = note: `#[deny(const_err)]` on by default
2020-03-18T21:42:10.4832773Z +    = note: `#[deny(const_err)]` on by default
2020-03-18T21:42:10.4832992Z + 
2020-03-18T21:42:10.4833197Z 9 error: this arithmetic operation will overflow
2020-03-18T21:42:10.4833637Z 10   --> $DIR/issue-69020.rs:23:22
2020-03-18T21:42:10.4833856Z 11    |
2020-03-18T21:42:10.4833967Z 
2020-03-18T21:42:10.4834198Z 12 LL |     const ADD: i32 = (i32::MAX+1) + T::ADD;
2020-03-18T21:42:10.4834802Z 14 
2020-03-18T21:42:10.4835014Z + error: any use of this value will cause an error
2020-03-18T21:42:10.4835451Z +   --> $DIR/issue-69020.rs:23:22
2020-03-18T21:42:10.4835665Z +    |
2020-03-18T21:42:10.4835665Z +    |
2020-03-18T21:42:10.4836048Z + LL |     const ADD: i32 = (i32::MAX+1) + T::ADD;
2020-03-18T21:42:10.4836822Z +    |                      |
2020-03-18T21:42:10.4837084Z +    |                      attempt to add with overflow
2020-03-18T21:42:10.4837295Z + 
2020-03-18T21:42:10.4837588Z 15 error: this operation will panic at runtime
---
2020-03-18T21:42:10.4839051Z 22 
2020-03-18T21:42:10.4839390Z + error: any use of this value will cause an error
2020-03-18T21:42:10.4839819Z +   --> $DIR/issue-69020.rs:25:22
2020-03-18T21:42:10.4839999Z +    |
2020-03-18T21:42:10.4840200Z + LL |     const DIV: i32 = (1/0) + T::DIV;
2020-03-18T21:42:10.4840851Z +    |                      |
2020-03-18T21:42:10.4841090Z +    |                      attempt to divide by zero
2020-03-18T21:42:10.4841300Z + 
2020-03-18T21:42:10.4841490Z 23 error: this operation will panic at runtime
2020-03-18T21:42:10.4841490Z 23 error: this operation will panic at runtime
2020-03-18T21:42:10.4841893Z 24   --> $DIR/issue-69020.rs:27:22
2020-03-18T21:42:10.4842204Z 25    |
2020-03-18T21:42:10.4842318Z 
2020-03-18T21:42:10.4842523Z 26 LL |     const OOB: i32 = [1][1] + T::OOB;
2020-03-18T21:42:10.4843252Z 28 
2020-03-18T21:42:10.4843558Z - error: aborting due to 4 previous errors
2020-03-18T21:42:10.4843789Z + error: any use of this value will cause an error
2020-03-18T21:42:10.4844154Z +   --> $DIR/issue-69020.rs:27:22
2020-03-18T21:42:10.4844154Z +   --> $DIR/issue-69020.rs:27:22
2020-03-18T21:42:10.4844311Z +    |
2020-03-18T21:42:10.4844495Z + LL |     const OOB: i32 = [1][1] + T::OOB;
2020-03-18T21:42:10.4845080Z +    |                      |
2020-03-18T21:42:10.4845445Z +    |                      index out of bounds: the len is 1 but the index is 1
2020-03-18T21:42:10.4845685Z + 
2020-03-18T21:42:10.4845842Z + error: aborting due to 8 previous errors
2020-03-18T21:42:10.4845842Z + error: aborting due to 8 previous errors
2020-03-18T21:42:10.4845998Z 30 
2020-03-18T21:42:10.4846111Z 31 
2020-03-18T21:42:10.4846198Z 
2020-03-18T21:42:10.4846277Z 
2020-03-18T21:42:10.4846442Z The actual stderr differed from the expected stderr.
2020-03-18T21:42:10.4847011Z Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/issue-69020.opt/issue-69020.opt.stderr
2020-03-18T21:42:10.4847530Z To update references, rerun the tests and pass the `--bless` flag
2020-03-18T21:42:10.4847992Z To only update this specific test, also pass `--test-args consts/issue-69020.rs`
2020-03-18T21:42:10.4848483Z error in revision `opt`: 1 errors occurred comparing output.
2020-03-18T21:42:10.4848705Z status: exit code: 1
2020-03-18T21:42:10.4848705Z status: exit code: 1
2020-03-18T21:42:10.4850301Z command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/consts/issue-69020.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--cfg" "opt" "--error-format" "json" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/issue-69020.opt" "-Crpath" "-Cdebuginfo=0" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-A" "unused" "-O" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/issue-69020.opt/auxiliary"
2020-03-18T21:42:10.4851901Z ------------------------------------------
2020-03-18T21:42:10.4852061Z 
2020-03-18T21:42:10.4852514Z ------------------------------------------
2020-03-18T21:42:10.4852725Z stderr:
2020-03-18T21:42:10.4852725Z stderr:
2020-03-18T21:42:10.4853075Z ------------------------------------------
2020-03-18T21:42:10.4853328Z error: this arithmetic operation will overflow
2020-03-18T21:42:10.4853792Z   --> /checkout/src/test/ui/consts/issue-69020.rs:21:22
2020-03-18T21:42:10.4854006Z    |
2020-03-18T21:42:10.4854378Z LL |     const NEG: i32 = -i32::MIN + T::NEG;
2020-03-18T21:42:10.4855034Z    |
2020-03-18T21:42:10.4855294Z    = note: `#[deny(arithmetic_overflow)]` on by default
2020-03-18T21:42:10.4855480Z 
2020-03-18T21:42:10.4855681Z error: any use of this value will cause an error
2020-03-18T21:42:10.4855681Z error: any use of this value will cause an error
2020-03-18T21:42:10.4856155Z   --> /checkout/src/test/ui/consts/issue-69020.rs:21:22
2020-03-18T21:42:10.4856530Z    |
2020-03-18T21:42:10.4856938Z LL |     const NEG: i32 = -i32::MIN + T::NEG;
2020-03-18T21:42:10.4857587Z    |                      |
2020-03-18T21:42:10.4857843Z    |                      attempt to negate with overflow
2020-03-18T21:42:10.4858221Z    |
2020-03-18T21:42:10.4858427Z    = note: `#[deny(const_err)]` on by default
2020-03-18T21:42:10.4858427Z    = note: `#[deny(const_err)]` on by default
2020-03-18T21:42:10.4858608Z 
2020-03-18T21:42:10.4858820Z error: this arithmetic operation will overflow
2020-03-18T21:42:10.4859308Z   --> /checkout/src/test/ui/consts/issue-69020.rs:23:22
2020-03-18T21:42:10.4859534Z    |
2020-03-18T21:42:10.4859882Z LL |     const ADD: i32 = (i32::MAX+1) + T::ADD;
2020-03-18T21:42:10.4860391Z 
2020-03-18T21:42:10.4860590Z error: any use of this value will cause an error
2020-03-18T21:42:10.4861044Z   --> /checkout/src/test/ui/consts/issue-69020.rs:23:22
2020-03-18T21:42:10.4861259Z    |
2020-03-18T21:42:10.4861259Z    |
2020-03-18T21:42:10.4861472Z LL |     const ADD: i32 = (i32::MAX+1) + T::ADD;
2020-03-18T21:42:10.4862266Z    |                      |
2020-03-18T21:42:10.4862502Z    |                      attempt to add with overflow
2020-03-18T21:42:10.4862691Z 
2020-03-18T21:42:10.4862869Z error: this operation will panic at runtime
2020-03-18T21:42:10.4862869Z error: this operation will panic at runtime
2020-03-18T21:42:10.4863324Z   --> /checkout/src/test/ui/consts/issue-69020.rs:25:22
2020-03-18T21:42:10.4863549Z    |
2020-03-18T21:42:10.4863743Z LL |     const DIV: i32 = (1/0) + T::DIV;
2020-03-18T21:42:10.4864239Z    |
2020-03-18T21:42:10.4864453Z    = note: `#[deny(unconditional_panic)]` on by default
2020-03-18T21:42:10.4864637Z 
2020-03-18T21:42:10.4864822Z error: any use of this value will cause an error
2020-03-18T21:42:10.4864822Z error: any use of this value will cause an error
2020-03-18T21:42:10.4865289Z   --> /checkout/src/test/ui/consts/issue-69020.rs:25:22
2020-03-18T21:42:10.4865505Z    |
2020-03-18T21:42:10.4865697Z LL |     const DIV: i32 = (1/0) + T::DIV;
2020-03-18T21:42:10.4866332Z    |                      |
2020-03-18T21:42:10.4866561Z    |                      attempt to divide by zero
2020-03-18T21:42:10.4866731Z 
2020-03-18T21:42:10.4866924Z error: this operation will panic at runtime
2020-03-18T21:42:10.4866924Z error: this operation will panic at runtime
2020-03-18T21:42:10.4867367Z   --> /checkout/src/test/ui/consts/issue-69020.rs:27:22
2020-03-18T21:42:10.4867578Z    |
2020-03-18T21:42:10.4867796Z LL |     const OOB: i32 = [1][1] + T::OOB;
2020-03-18T21:42:10.4868400Z 
2020-03-18T21:42:10.4868608Z error: any use of this value will cause an error
2020-03-18T21:42:10.4869061Z   --> /checkout/src/test/ui/consts/issue-69020.rs:27:22
2020-03-18T21:42:10.4869268Z    |
2020-03-18T21:42:10.4869268Z    |
2020-03-18T21:42:10.4869650Z LL |     const OOB: i32 = [1][1] + T::OOB;
2020-03-18T21:42:10.4870214Z    |                      |
2020-03-18T21:42:10.4870485Z    |                      index out of bounds: the len is 1 but the index is 1
2020-03-18T21:42:10.4870866Z 
2020-03-18T21:42:10.4871039Z error: aborting due to 8 previous errors
---
2020-03-18T21:42:10.4873272Z 8 
2020-03-18T21:42:10.4873495Z + error: any use of this value will cause an error
2020-03-18T21:42:10.4873915Z +   --> $DIR/issue-69020.rs:21:22
2020-03-18T21:42:10.4874185Z +    |
2020-03-18T21:42:10.4874573Z + LL |     const NEG: i32 = -i32::MIN + T::NEG;
2020-03-18T21:42:10.4875254Z +    |                      |
2020-03-18T21:42:10.4875504Z +    |                      attempt to negate with overflow
2020-03-18T21:42:10.4875712Z +    |
2020-03-18T21:42:10.4875929Z +    = note: `#[deny(const_err)]` on by default
2020-03-18T21:42:10.4875929Z +    = note: `#[deny(const_err)]` on by default
2020-03-18T21:42:10.4876118Z + 
2020-03-18T21:42:10.4876310Z 9 error: this arithmetic operation will overflow
2020-03-18T21:42:10.4876729Z 10   --> $DIR/issue-69020.rs:23:22
2020-03-18T21:42:10.4876913Z 11    |
2020-03-18T21:42:10.4877015Z 
2020-03-18T21:42:10.4877227Z 12 LL |     const ADD: i32 = (i32::MAX+1) + T::ADD;
2020-03-18T21:42:10.4877789Z 14 
2020-03-18T21:42:10.4877983Z + error: any use of this value will cause an error
2020-03-18T21:42:10.4878405Z +   --> $DIR/issue-69020.rs:23:22
2020-03-18T21:42:10.4879043Z +    |
2020-03-18T21:42:10.4879043Z +    |
2020-03-18T21:42:10.4879285Z + LL |     const ADD: i32 = (i32::MAX+1) + T::ADD;
2020-03-18T21:42:10.4880055Z +    |                      |
2020-03-18T21:42:10.4880317Z +    |                      attempt to add with overflow
2020-03-18T21:42:10.4880544Z + 
2020-03-18T21:42:10.4880750Z 15 error: this operation will panic at runtime
---
2020-03-18T21:42:10.4882279Z 22 
2020-03-18T21:42:10.4882493Z + error: any use of this value will cause an error
2020-03-18T21:42:10.4882945Z +   --> $DIR/issue-69020.rs:25:22
2020-03-18T21:42:10.4883154Z +    |
2020-03-18T21:42:10.4883372Z + LL |     const DIV: i32 = (1/0) + T::DIV;
2020-03-18T21:42:10.4884079Z +    |                      |
2020-03-18T21:42:10.4884336Z +    |                      attempt to divide by zero
2020-03-18T21:42:10.4884542Z + 
2020-03-18T21:42:10.4884743Z 23 error: this operation will panic at runtime
2020-03-18T21:42:10.4884743Z 23 error: this operation will panic at runtime
2020-03-18T21:42:10.4885191Z 24   --> $DIR/issue-69020.rs:27:22
2020-03-18T21:42:10.4885388Z 25    |
2020-03-18T21:42:10.4885499Z 
2020-03-18T21:42:10.4885733Z 26 LL |     const OOB: i32 = [1][1] + T::OOB;
2020-03-18T21:42:10.4886429Z 28 
2020-03-18T21:42:10.4886813Z - error: aborting due to 4 previous errors
2020-03-18T21:42:10.4887102Z + error: any use of this value will cause an error
2020-03-18T21:42:10.4887538Z +   --> $DIR/issue-69020.rs:27:22
2020-03-18T21:42:10.4887538Z +   --> $DIR/issue-69020.rs:27:22
2020-03-18T21:42:10.4887748Z +    |
2020-03-18T21:42:10.4887977Z + LL |     const OOB: i32 = [1][1] + T::OOB;
2020-03-18T21:42:10.4888684Z +    |                      |
2020-03-18T21:42:10.4889023Z +    |                      index out of bounds: the len is 1 but the index is 1
2020-03-18T21:42:10.4889302Z + 
2020-03-18T21:42:10.4889495Z + error: aborting due to 8 previous errors
2020-03-18T21:42:10.4889495Z + error: aborting due to 8 previous errors
2020-03-18T21:42:10.4889702Z 30 
2020-03-18T21:42:10.4889824Z 31 
2020-03-18T21:42:10.4889928Z 
2020-03-18T21:42:10.4890024Z 
2020-03-18T21:42:10.4890243Z The actual stderr differed from the expected stderr.
2020-03-18T21:42:10.4891015Z Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/issue-69020.opt_with_overflow_checks/issue-69020.opt_with_overflow_checks.stderr
2020-03-18T21:42:10.4891899Z To update references, rerun the tests and pass the `--bless` flag
2020-03-18T21:42:10.4892466Z To only update this specific test, also pass `--test-args consts/issue-69020.rs`
2020-03-18T21:42:10.4892793Z 
2020-03-18T21:42:10.4893016Z error in revision `opt_with_overflow_checks`: 1 errors occurred comparing output.
2020-03-18T21:42:10.4893325Z status: exit code: 1
2020-03-18T21:42:10.4895091Z command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/consts/issue-69020.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--cfg" "opt_with_overflow_checks" "--error-format" "json" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/issue-69020.opt_with_overflow_checks" "-Crpath" "-Cdebuginfo=0" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-A" "unused" "-C" "overflow-checks=on" "-O" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/issue-69020.opt_with_overflow_checks/auxiliary"
2020-03-18T21:42:10.4896503Z ------------------------------------------
2020-03-18T21:42:10.4896654Z 
2020-03-18T21:42:10.4896940Z ------------------------------------------
2020-03-18T21:42:10.4897105Z stderr:
2020-03-18T21:42:10.4897105Z stderr:
2020-03-18T21:42:10.4897396Z ------------------------------------------
2020-03-18T21:42:10.4897629Z error: this arithmetic operation will overflow
2020-03-18T21:42:10.4898023Z   --> /checkout/src/test/ui/consts/issue-69020.rs:21:22
2020-03-18T21:42:10.4898209Z    |
2020-03-18T21:42:10.4898543Z LL |     const NEG: i32 = -i32::MIN + T::NEG;
2020-03-18T21:42:10.4899001Z    |
2020-03-18T21:42:10.4899196Z    = note: `#[deny(arithmetic_overflow)]` on by default
2020-03-18T21:42:10.4899355Z 
2020-03-18T21:42:10.4899517Z error: any use of this value will cause an error
2020-03-18T21:42:10.4899517Z error: any use of this value will cause an error
2020-03-18T21:42:10.4899929Z   --> /checkout/src/test/ui/consts/issue-69020.rs:21:22
2020-03-18T21:42:10.4900113Z    |
2020-03-18T21:42:10.4900431Z LL |     const NEG: i32 = -i32::MIN + T::NEG;
2020-03-18T21:42:10.4905358Z    |                      |
2020-03-18T21:42:10.4905674Z    |                      attempt to negate with overflow
2020-03-18T21:42:10.4905846Z    |
2020-03-18T21:42:10.4906030Z    = note: `#[deny(const_err)]` on by default
2020-03-18T21:42:10.4906030Z    = note: `#[deny(const_err)]` on by default
2020-03-18T21:42:10.4906177Z 
2020-03-18T21:42:10.4906337Z error: this arithmetic operation will overflow
2020-03-18T21:42:10.4906875Z   --> /checkout/src/test/ui/consts/issue-69020.rs:23:22
2020-03-18T21:42:10.4907061Z    |
2020-03-18T21:42:10.4907248Z LL |     const ADD: i32 = (i32::MAX+1) + T::ADD;
2020-03-18T21:42:10.4907705Z 
2020-03-18T21:42:10.4907868Z error: any use of this value will cause an error
2020-03-18T21:42:10.4908275Z   --> /checkout/src/test/ui/consts/issue-69020.rs:23:22
2020-03-18T21:42:10.4908476Z    |
2020-03-18T21:42:10.4908476Z    |
2020-03-18T21:42:10.4908661Z LL |     const ADD: i32 = (i32::MAX+1) + T::ADD;
2020-03-18T21:42:10.4909263Z    |                      |
2020-03-18T21:42:10.4909469Z    |                      attempt to add with overflow
2020-03-18T21:42:10.4909753Z 
2020-03-18T21:42:10.4909910Z error: this operation will panic at runtime
2020-03-18T21:42:10.4909910Z error: this operation will panic at runtime
2020-03-18T21:42:10.4910324Z   --> /checkout/src/test/ui/consts/issue-69020.rs:25:22
2020-03-18T21:42:10.4910509Z    |
2020-03-18T21:42:10.4910855Z LL |     const DIV: i32 = (1/0) + T::DIV;
2020-03-18T21:42:10.4911350Z    |
2020-03-18T21:42:10.4911556Z    = note: `#[deny(unconditional_panic)]` on by default
2020-03-18T21:42:10.4911752Z 
2020-03-18T21:42:10.4911936Z error: any use of this value will cause an error
2020-03-18T21:42:10.4911936Z error: any use of this value will cause an error
2020-03-18T21:42:10.4912527Z   --> /checkout/src/test/ui/consts/issue-69020.rs:25:22
2020-03-18T21:42:10.4912755Z    |
2020-03-18T21:42:10.4912949Z LL |     const DIV: i32 = (1/0) + T::DIV;
2020-03-18T21:42:10.4913644Z    |                      |
2020-03-18T21:42:10.4913890Z    |                      attempt to divide by zero
2020-03-18T21:42:10.4914062Z 
2020-03-18T21:42:10.4914240Z error: this operation will panic at runtime
2020-03-18T21:42:10.4914240Z error: this operation will panic at runtime
2020-03-18T21:42:10.4914715Z   --> /checkout/src/test/ui/consts/issue-69020.rs:27:22
2020-03-18T21:42:10.4914924Z    |
2020-03-18T21:42:10.4915126Z LL |     const OOB: i32 = [1][1] + T::OOB;
2020-03-18T21:42:10.4915745Z 
2020-03-18T21:42:10.4915935Z error: any use of this value will cause an error
2020-03-18T21:42:10.4916390Z   --> /checkout/src/test/ui/consts/issue-69020.rs:27:22
2020-03-18T21:42:10.4919146Z    |
2020-03-18T21:42:10.4919146Z    |
2020-03-18T21:42:10.4919369Z LL |     const OOB: i32 = [1][1] + T::OOB;
2020-03-18T21:42:10.4920151Z    |                      |
2020-03-18T21:42:10.4920449Z    |                      index out of bounds: the len is 1 but the index is 1
2020-03-18T21:42:10.4920692Z 
2020-03-18T21:42:10.4921090Z error: aborting due to 8 previous errors
2020-03-18T21:42:10.4921090Z error: aborting due to 8 previous errors
2020-03-18T21:42:10.4921258Z 
2020-03-18T21:42:10.4921347Z 
2020-03-18T21:42:10.4921697Z ------------------------------------------
2020-03-18T21:42:10.4921853Z 
2020-03-18T21:42:10.4921957Z 
2020-03-18T21:42:10.4922045Z 
2020-03-18T21:42:10.4922167Z failures:
2020-03-18T21:42:10.4922545Z     [ui] ui/associated-const/lints-used-unused.rs#unused
2020-03-18T21:42:10.4923077Z     [ui] ui/associated-const/lints-used-unused.rs#used
2020-03-18T21:42:10.4923827Z     [ui] ui/consts/issue-69020.rs#noopt
2020-03-18T21:42:10.4924178Z     [ui] ui/consts/issue-69020.rs#opt
2020-03-18T21:42:10.4924558Z     [ui] ui/consts/issue-69020.rs#opt_with_overflow_checks
2020-03-18T21:42:10.4924720Z 
2020-03-18T21:42:10.4924720Z 
2020-03-18T21:42:10.4925139Z test result: FAILED. 9735 passed; 6 failed; 57 ignored; 0 measured; 0 filtered out
2020-03-18T21:42:10.4925359Z 
2020-03-18T21:42:10.4925823Z thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:348:22
2020-03-18T21:42:10.4926155Z note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
2020-03-18T21:42:10.4926356Z 
2020-03-18T21:42:10.4926434Z 
2020-03-18T21:42:10.4929960Z 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-7/bin/FileCheck" "--nodejs" "/usr/bin/node" "--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" "7.0.0\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
2020-03-18T21:42:10.4932462Z 
2020-03-18T21:42:10.4932556Z 
2020-03-18T21:42:10.4933133Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test --exclude src/tools/tidy
2020-03-18T21:42:10.4933498Z Build completed unsuccessfully in 0:55:22
2020-03-18T21:42:10.4933498Z Build completed unsuccessfully in 0:55:22
2020-03-18T21:42:10.4933767Z == clock drift check ==
2020-03-18T21:42:10.4934062Z   local time: Wed Mar 18 21:42:10 UTC 2020
2020-03-18T21:42:11.0350174Z   network time: Wed, 18 Mar 2020 21:42:11 GMT
2020-03-18T21:42:11.0350700Z == end clock drift check ==
2020-03-18T21:42:11.4253542Z 
2020-03-18T21:42:11.4328681Z ##[error]Bash exited with code '1'.
2020-03-18T21:42:11.4339621Z ##[section]Finishing: Run build
2020-03-18T21:42:11.4385114Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/70017/merge to s
2020-03-18T21:42:11.4389310Z Task         : Get sources
2020-03-18T21:42:11.4389724Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-03-18T21:42:11.4389999Z Version      : 1.0.0
2020-03-18T21:42:11.4390183Z Author       : Microsoft
2020-03-18T21:42:11.4390183Z Author       : Microsoft
2020-03-18T21:42:11.4390477Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
2020-03-18T21:42:11.4390820Z ==============================================================================
2020-03-18T21:42:11.7314538Z Cleaning any cached credential from repository: rust-lang/rust (GitHub)
2020-03-18T21:42:11.7354570Z ##[section]Finishing: Checkout rust-lang/rust@refs/pull/70017/merge to s
2020-03-18T21:42:11.7427381Z Cleaning up task key
2020-03-18T21:42:11.7428467Z Start cleaning up orphan processes.
2020-03-18T21:42:11.7677438Z Terminate orphan process: pid (3805) (python)
2020-03-18T21:42:11.7716406Z ##[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)

@RalfJung
Copy link
Member

@jumbatm there seem to be test failures?

@JohnCSimon
Copy link
Member

Ping from triage
@jumbatm can you please address the test failures?

@jumbatm
Copy link
Contributor Author

jumbatm commented Mar 29, 2020

Apologies - I'm still working on this PR, and yet to address most of the review comments. The test failures are because I updated the test cases to include some cases that were missed before (and that my original set of changes didn't address).

@jumbatm jumbatm force-pushed the exceeding-bitshifts branch from b34843f to 6d33a18 Compare March 29, 2020 07:34
Comment on lines +482 to +483
// Creating pointers to T is valid. We only reach this case for unused
// associated consts.
Copy link
Member

Choose a reason for hiding this comment

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

This change only affects raw pointers. And it anyway was only checking that the pointer itself is not Undef -- whatever the pointer points to is already irrelevant here. I don't see how this change makes any sense.

However, validity certainly assumes that the type is fully known. It makes little sense to call validity at all when there are still ty::Param around.

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 still have ty::Param around in cases for unused associated consts, unfortunately, because I don't have a use-site to pull a type from. When ref_to_mplace calls layout_of, because the type is unknown, the layout is unknown, and validation fails. This breaks code which like this:

impl<T> Nullable for *const T {
const NULL: Self = core::ptr::null::<T>();

I didn't realise that this was just checking for Undef of the pointer value itself. I got the impression the purpose of this check was to check that the pointee had a valid layout (ie, that it's okay to dereference the raw pointer), so I thought skipping this check made sense because it's not until the pointer is dereferenced that any issues could occur.

I see a lot of const errors are picked up during const_eval_raw, before validation even happens - does it make sense to just not run validation for unused associated consts, then?

Copy link
Member

Choose a reason for hiding this comment

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

ie, that it's okay to dereference the raw pointer

Raw pointers may dangle. So such a check would be incorrect.

I still have ty::Param around in cases for unused associated consts, unfortunately, because I don't have a use-site to pull a type from.

Such constant should not have validation run on them, anyway, We cannot validate them, after all, with some type information missing.

I get the feeling you are sticking values into compiler passes that are not prepared to handle those values. I don't think this approach can work. In other words, I think this (running const-eval on associated consts) is the wrong approach to fix #69021.

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 this (running const-eval on associated consts) is the wrong approach to fix #69021

After the poking I've done here, I've come to realise the issue is a bit broader than just missing bitshifts. We only get lints for associated consts if const_eval reaches the const through some use of it. That is, all lints for associated consts are missed if the associated const is unused. For example, the out-of-range access here isn't picked up if S::N is left unused:

trait Foo {
    const N: i32;
}

struct S;
impl Foo for S {
    const N: i32 = [10][1];
}

fn main() {
    //println!("{}", S::N);
}

As for running const-eval being the wrong approach, I'd argue that associated consts are suitable for const eval in much of the same way normal consts are: by definition, they, like normal consts, must be able to be evaluated at compile time, and they also can be complex enough that just linting the AST without doing at least some form of const evaluation isn't enough.

I get the feeling you are sticking values into compiler passes that are not prepared to handle those values.

Mmm, I agree with your assessment. However, for the reason above, I'm inclined towards making const-eval work (but perhaps shoehorning const_eval_poly into this is the wrong approach).

Copy link
Member

@RalfJung RalfJung Mar 29, 2020

Choose a reason for hiding this comment

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

As for running const-eval being the wrong approach, I'd argue that associated consts are suitable for const eval in much of the same way normal consts are: by definition, they, like normal consts, must be able to be evaluated at compile time, and they also can be complex enough that just linting the AST without doing at least some form of const evaluation isn't enough.

This only makes sense for monomorphized associated consts. It makes no sense when there are still unknown generics around, like what you are seeing here.

Associated consts with missing generics are much more like const functions than consts. And for const functions, we don't run const-eval either. And indeed the entire concept of executing such a constant/function is meaningless as some inputs are missing!

const fn do_something(b: bool, x: i32) -> i32 {
  if b { x } else { x << 44 }
}

What does it mean do "run" do_something? It means nothing. You can only run do_something after picking some b and x.


I really wonder why you are so focused on const_eval. Most of these lints don't come from const_eval. They come from const_prop. That's how the lint is triggered in run-time (non-const) functions, such as this.

Here is the code triggering the lint:

// Check for exceeding shifts *even if* we cannot evaluate the LHS.
if op == BinOp::Shr || op == BinOp::Shl {
// We need the type of the LHS. We cannot use `place_layout` as that is the type
// of the result, which for checked binops is not the same!
let left_ty = left.ty(&self.local_decls, self.tcx);
let left_size_bits = self.ecx.layout_of(left_ty).ok()?.size.bits();
let right_size = r.layout.size;
let r_bits = r.to_scalar().ok();
// This is basically `force_bits`.
let r_bits = r_bits.and_then(|r| r.to_bits_or_ptr(right_size, &self.tcx).ok());
if r_bits.map_or(false, |b| b >= left_size_bits as u128) {
self.report_assert_as_lint(
lint::builtin::ARITHMETIC_OVERFLOW,
source_info,
"this arithmetic operation will overflow",
AssertKind::Overflow(op),
)?;
}
}

const_prop is an optimization pass that expects to run on polymorphic functions with partial information, unlike const_eval which expects to run on fully monomorphic code. Thus I think the right fix here is to run const_prop on associated consts. That is also why in this comment I talked about the relevant parts of const_prop. I wonder if there was any specific reason you went for const_eval?

Copy link
Contributor

Choose a reason for hiding this comment

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

as some inputs are missing!

I actually love that

impl<T> Nullable for *const T { 
     const NULL: Self = core::ptr::null::<T>(); 

is evaluable polymorphically. Not sure if this is relevant for @davidtwco.

If a constant (associated or not) can be evaluated polymorphically, then we don't need to run it again. We may experiment with this in const_eval_raw.

back to topic:

I think we should do something where associated constants and regular constants get handled the same way by UnusedBrokenConst. Not sure what that is, but the current PR is heading in that direction although maybe not on the path that we want. The reason we even have UnusedBrokenConst instead of doing everything in const_prop is the statement at the entry function of const_prop: we're going to evaluate the constant anyway.

So... I'm not sure what I think is the best way forward, but in general doing const_prop is more powerful because it doesn't bail out early if there's an error.

Copy link
Member

@RalfJung RalfJung Mar 29, 2020

Choose a reason for hiding this comment

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

I feel associated consts are more like (const) fn: there might be inputs missing. Thus we need const_prop, which is prepared for that case.

Of course, the actual "propagation" part of const_prop makes little sense here. Maybe putting lint and transformation together was just a bad call? (Another weird effect of this is that some warnings only appear in release mode, such as this one.) (This is already fixed on beta.)

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 wonder if there was any specific reason you went for const_eval?

I looked into how unused non-assoc constants were linted and found UnusedBrokenConst, which runs const_eval_poly. I was hoping running const_eval_poly would handle all the cases where there weren't missing substitutions, and just bail out with TooGeneric in other cases:

/// Evaluates a constant without providing any substitutions. This is useful to evaluate consts
/// that can't take any generic arguments like statics, const items or enum discriminants. If a
/// generic parameter is used within the constant `ErrorHandled::ToGeneric` will be returned.
pub fn const_eval_poly(self, def_id: DefId) -> ConstEvalResult<'tcx> {

On a second reading, and in light of everything you've both informed me here, I've realised I've focussed on the wrong part of that doc comment.

Associated consts with missing generics are much more like const functions than consts. And for const functions, we don't run const-eval either. And indeed the entire concept of executing such a constant/function is meaningless as some inputs are missing!

const_prop is an optimization pass that expects to run on polymorphic functions with partial information, unlike const_eval which expects to run on fully monomorphic code.

in general doing const_prop is more powerful because it doesn't bail out early if there's an error

Ah, and that's why const_eval_poly was suitable for normal consts, but is not suitable for associated consts.

Maybe putting lint and transformation together was just a bad call

I'm inclined to agree, and moreso when the transformation isn't always run. I'll pull the linting code into its own function as a very first step.

Comment on lines +1 to +21
error: this arithmetic operation will overflow
--> $DIR/lints-used-unused.rs:16:20
|
LL | const N: i32 = 1 << 42;
| ^^^^^^^ attempt to shift left with overflow
|
note: the lint level is defined here
--> $DIR/lints-used-unused.rs:7:9
|
LL | #![deny(arithmetic_overflow)]
| ^^^^^^^^^^^^^^^^^^^

error: any use of this value will cause an error
--> $DIR/lints-used-unused.rs:16:20
|
LL | const N: i32 = 1 << 42;
| ---------------^^^^^^^-
| |
| attempt to shift left with overflow
|
= note: `#[deny(const_err)]` on by default
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does it make sense to try to deduplicate these errors? From a front-facing perspective, they're two different lints (arithmetic_overflow and const_err), and if someone wanted to silence these errors, they would have to disable both lints. What's the go for duplicates like this?

@bors
Copy link
Contributor

bors commented Mar 29, 2020

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

@jumbatm
Copy link
Contributor Author

jumbatm commented Mar 30, 2020

Closing in favour of the PR I've just opened that uses const prop instead of const eval as suggested. The discussion here was really informative -- thanks, everyone! :)

@jumbatm jumbatm closed this Mar 30, 2020
@RalfJung
Copy link
Member

For future reference, that other PR is #70566

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Apr 14, 2020
…op, r=RalfJung

Don't bail out before linting in generic contexts.

Fixes rust-lang#69021.

cc rust-lang#70017

r? @RalfJung
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Apr 16, 2020
…op, r=RalfJung

Don't bail out before linting in generic contexts.

Fixes rust-lang#69021.

cc rust-lang#70017

r? @RalfJung
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Apr 16, 2020
…op, r=RalfJung

Don't bail out before linting in generic contexts.

Fixes rust-lang#69021.

cc rust-lang#70017

r? @RalfJung
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"exceeding_bitshifts" lint does not work in associated consts
7 participants