From 0d73bb926c271f494f22818ec25984057dcdfb4d Mon Sep 17 00:00:00 2001 From: jumbatm Date: Thu, 2 Apr 2020 22:45:40 +1000 Subject: [PATCH 1/3] Extend #69020 test to include reversed order. Make sure we check the case where the generic operand comes first, in case any future changes make this ordering matter. --- src/test/ui/consts/issue-69020.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/test/ui/consts/issue-69020.rs b/src/test/ui/consts/issue-69020.rs index e079feb04d4..9a31c10a0c6 100644 --- a/src/test/ui/consts/issue-69020.rs +++ b/src/test/ui/consts/issue-69020.rs @@ -9,9 +9,16 @@ use std::i32; pub trait Foo { const NEG: i32; + const GEN: i32; + const ADD: i32; + const DDA: i32; + const DIV: i32; + const VID: i32; + const OOB: i32; + const BOO: i32; } // These constants cannot be evaluated already (they depend on `T::N`), so @@ -20,10 +27,21 @@ pub trait Foo { impl Foo for Vec { const NEG: i32 = -i32::MIN + T::NEG; //~^ ERROR arithmetic operation will overflow + const GEN: i32 = T::NEG + (-i32::MIN); + //~^ ERROR arithmetic operation will overflow + const ADD: i32 = (i32::MAX+1) + T::ADD; //~^ ERROR arithmetic operation will overflow + const DDA: i32 = T::ADD + (i32::MAX+1); + //~^ ERROR arithmetic operation will overflow + const DIV: i32 = (1/0) + T::DIV; //~^ ERROR operation will panic + const VID: i32 = T::DIV + (1/0); + //~^ ERROR operation will panic + const OOB: i32 = [1][1] + T::OOB; //~^ ERROR operation will panic + const BOO: i32 = T::OOB + [1][1]; + //~^ ERROR operation will panic } From de02a9ed67fb882f8fba5ed44162c6fdfa35964b Mon Sep 17 00:00:00 2001 From: jumbatm Date: Thu, 2 Apr 2020 22:47:53 +1000 Subject: [PATCH 2/3] Move #69020 test to ui/associated-const + rebless. --- ...20-assoc-const-arith-overflow.noopt.stderr | 54 +++++++++++++++++++ ...9020-assoc-const-arith-overflow.opt.stderr | 54 +++++++++++++++++++ ...h-overflow.opt_with_overflow_checks.stderr | 54 +++++++++++++++++++ ...issue-69020-assoc-const-arith-overflow.rs} | 0 src/test/ui/consts/issue-69020.noopt.stderr | 30 ----------- src/test/ui/consts/issue-69020.opt.stderr | 30 ----------- ...ssue-69020.opt_with_overflow_checks.stderr | 30 ----------- 7 files changed, 162 insertions(+), 90 deletions(-) create mode 100644 src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.noopt.stderr create mode 100644 src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.opt.stderr create mode 100644 src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.opt_with_overflow_checks.stderr rename src/test/ui/{consts/issue-69020.rs => associated-const/issue-69020-assoc-const-arith-overflow.rs} (100%) delete mode 100644 src/test/ui/consts/issue-69020.noopt.stderr delete mode 100644 src/test/ui/consts/issue-69020.opt.stderr delete mode 100644 src/test/ui/consts/issue-69020.opt_with_overflow_checks.stderr diff --git a/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.noopt.stderr b/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.noopt.stderr new file mode 100644 index 00000000000..017a6f41dd8 --- /dev/null +++ b/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.noopt.stderr @@ -0,0 +1,54 @@ +error: this arithmetic operation will overflow + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:28:22 + | +LL | const NEG: i32 = -i32::MIN + T::NEG; + | ^^^^^^^^^ attempt to negate with overflow + | + = note: `#[deny(arithmetic_overflow)]` on by default + +error: this arithmetic operation will overflow + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:30:31 + | +LL | const GEN: i32 = T::NEG + (-i32::MIN); + | ^^^^^^^^^^^ attempt to negate with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:33:22 + | +LL | const ADD: i32 = (i32::MAX+1) + T::ADD; + | ^^^^^^^^^^^^ attempt to add with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:35:32 + | +LL | const DDA: i32 = T::ADD + (i32::MAX+1); + | ^^^^^^^^^^^^ attempt to add with overflow + +error: this operation will panic at runtime + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:38:22 + | +LL | const DIV: i32 = (1/0) + T::DIV; + | ^^^^^ attempt to divide by zero + | + = note: `#[deny(unconditional_panic)]` on by default + +error: this operation will panic at runtime + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:40:31 + | +LL | const VID: i32 = T::DIV + (1/0); + | ^^^^^ attempt to divide by zero + +error: this operation will panic at runtime + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:43:22 + | +LL | const OOB: i32 = [1][1] + T::OOB; + | ^^^^^^ index out of bounds: the len is 1 but the index is 1 + +error: this operation will panic at runtime + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:45:31 + | +LL | const BOO: i32 = T::OOB + [1][1]; + | ^^^^^^ index out of bounds: the len is 1 but the index is 1 + +error: aborting due to 8 previous errors + diff --git a/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.opt.stderr b/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.opt.stderr new file mode 100644 index 00000000000..017a6f41dd8 --- /dev/null +++ b/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.opt.stderr @@ -0,0 +1,54 @@ +error: this arithmetic operation will overflow + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:28:22 + | +LL | const NEG: i32 = -i32::MIN + T::NEG; + | ^^^^^^^^^ attempt to negate with overflow + | + = note: `#[deny(arithmetic_overflow)]` on by default + +error: this arithmetic operation will overflow + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:30:31 + | +LL | const GEN: i32 = T::NEG + (-i32::MIN); + | ^^^^^^^^^^^ attempt to negate with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:33:22 + | +LL | const ADD: i32 = (i32::MAX+1) + T::ADD; + | ^^^^^^^^^^^^ attempt to add with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:35:32 + | +LL | const DDA: i32 = T::ADD + (i32::MAX+1); + | ^^^^^^^^^^^^ attempt to add with overflow + +error: this operation will panic at runtime + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:38:22 + | +LL | const DIV: i32 = (1/0) + T::DIV; + | ^^^^^ attempt to divide by zero + | + = note: `#[deny(unconditional_panic)]` on by default + +error: this operation will panic at runtime + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:40:31 + | +LL | const VID: i32 = T::DIV + (1/0); + | ^^^^^ attempt to divide by zero + +error: this operation will panic at runtime + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:43:22 + | +LL | const OOB: i32 = [1][1] + T::OOB; + | ^^^^^^ index out of bounds: the len is 1 but the index is 1 + +error: this operation will panic at runtime + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:45:31 + | +LL | const BOO: i32 = T::OOB + [1][1]; + | ^^^^^^ index out of bounds: the len is 1 but the index is 1 + +error: aborting due to 8 previous errors + diff --git a/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.opt_with_overflow_checks.stderr b/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.opt_with_overflow_checks.stderr new file mode 100644 index 00000000000..017a6f41dd8 --- /dev/null +++ b/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.opt_with_overflow_checks.stderr @@ -0,0 +1,54 @@ +error: this arithmetic operation will overflow + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:28:22 + | +LL | const NEG: i32 = -i32::MIN + T::NEG; + | ^^^^^^^^^ attempt to negate with overflow + | + = note: `#[deny(arithmetic_overflow)]` on by default + +error: this arithmetic operation will overflow + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:30:31 + | +LL | const GEN: i32 = T::NEG + (-i32::MIN); + | ^^^^^^^^^^^ attempt to negate with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:33:22 + | +LL | const ADD: i32 = (i32::MAX+1) + T::ADD; + | ^^^^^^^^^^^^ attempt to add with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:35:32 + | +LL | const DDA: i32 = T::ADD + (i32::MAX+1); + | ^^^^^^^^^^^^ attempt to add with overflow + +error: this operation will panic at runtime + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:38:22 + | +LL | const DIV: i32 = (1/0) + T::DIV; + | ^^^^^ attempt to divide by zero + | + = note: `#[deny(unconditional_panic)]` on by default + +error: this operation will panic at runtime + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:40:31 + | +LL | const VID: i32 = T::DIV + (1/0); + | ^^^^^ attempt to divide by zero + +error: this operation will panic at runtime + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:43:22 + | +LL | const OOB: i32 = [1][1] + T::OOB; + | ^^^^^^ index out of bounds: the len is 1 but the index is 1 + +error: this operation will panic at runtime + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:45:31 + | +LL | const BOO: i32 = T::OOB + [1][1]; + | ^^^^^^ index out of bounds: the len is 1 but the index is 1 + +error: aborting due to 8 previous errors + diff --git a/src/test/ui/consts/issue-69020.rs b/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.rs similarity index 100% rename from src/test/ui/consts/issue-69020.rs rename to src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.rs diff --git a/src/test/ui/consts/issue-69020.noopt.stderr b/src/test/ui/consts/issue-69020.noopt.stderr deleted file mode 100644 index c48a106ef46..00000000000 --- a/src/test/ui/consts/issue-69020.noopt.stderr +++ /dev/null @@ -1,30 +0,0 @@ -error: this arithmetic operation will overflow - --> $DIR/issue-69020.rs:21:22 - | -LL | const NEG: i32 = -i32::MIN + T::NEG; - | ^^^^^^^^^ attempt to negate with overflow - | - = note: `#[deny(arithmetic_overflow)]` on by default - -error: this arithmetic operation will overflow - --> $DIR/issue-69020.rs:23:22 - | -LL | const ADD: i32 = (i32::MAX+1) + T::ADD; - | ^^^^^^^^^^^^ attempt to add with overflow - -error: this operation will panic at runtime - --> $DIR/issue-69020.rs:25:22 - | -LL | const DIV: i32 = (1/0) + T::DIV; - | ^^^^^ attempt to divide by zero - | - = note: `#[deny(unconditional_panic)]` on by default - -error: this operation will panic at runtime - --> $DIR/issue-69020.rs:27:22 - | -LL | const OOB: i32 = [1][1] + T::OOB; - | ^^^^^^ index out of bounds: the len is 1 but the index is 1 - -error: aborting due to 4 previous errors - diff --git a/src/test/ui/consts/issue-69020.opt.stderr b/src/test/ui/consts/issue-69020.opt.stderr deleted file mode 100644 index c48a106ef46..00000000000 --- a/src/test/ui/consts/issue-69020.opt.stderr +++ /dev/null @@ -1,30 +0,0 @@ -error: this arithmetic operation will overflow - --> $DIR/issue-69020.rs:21:22 - | -LL | const NEG: i32 = -i32::MIN + T::NEG; - | ^^^^^^^^^ attempt to negate with overflow - | - = note: `#[deny(arithmetic_overflow)]` on by default - -error: this arithmetic operation will overflow - --> $DIR/issue-69020.rs:23:22 - | -LL | const ADD: i32 = (i32::MAX+1) + T::ADD; - | ^^^^^^^^^^^^ attempt to add with overflow - -error: this operation will panic at runtime - --> $DIR/issue-69020.rs:25:22 - | -LL | const DIV: i32 = (1/0) + T::DIV; - | ^^^^^ attempt to divide by zero - | - = note: `#[deny(unconditional_panic)]` on by default - -error: this operation will panic at runtime - --> $DIR/issue-69020.rs:27:22 - | -LL | const OOB: i32 = [1][1] + T::OOB; - | ^^^^^^ index out of bounds: the len is 1 but the index is 1 - -error: aborting due to 4 previous errors - diff --git a/src/test/ui/consts/issue-69020.opt_with_overflow_checks.stderr b/src/test/ui/consts/issue-69020.opt_with_overflow_checks.stderr deleted file mode 100644 index c48a106ef46..00000000000 --- a/src/test/ui/consts/issue-69020.opt_with_overflow_checks.stderr +++ /dev/null @@ -1,30 +0,0 @@ -error: this arithmetic operation will overflow - --> $DIR/issue-69020.rs:21:22 - | -LL | const NEG: i32 = -i32::MIN + T::NEG; - | ^^^^^^^^^ attempt to negate with overflow - | - = note: `#[deny(arithmetic_overflow)]` on by default - -error: this arithmetic operation will overflow - --> $DIR/issue-69020.rs:23:22 - | -LL | const ADD: i32 = (i32::MAX+1) + T::ADD; - | ^^^^^^^^^^^^ attempt to add with overflow - -error: this operation will panic at runtime - --> $DIR/issue-69020.rs:25:22 - | -LL | const DIV: i32 = (1/0) + T::DIV; - | ^^^^^ attempt to divide by zero - | - = note: `#[deny(unconditional_panic)]` on by default - -error: this operation will panic at runtime - --> $DIR/issue-69020.rs:27:22 - | -LL | const OOB: i32 = [1][1] + T::OOB; - | ^^^^^^ index out of bounds: the len is 1 but the index is 1 - -error: aborting due to 4 previous errors - From 0399d141b6730b2e3c84c5ed4af87ffd28402376 Mon Sep 17 00:00:00 2001 From: jumbatm Date: Fri, 3 Apr 2020 08:05:16 +1000 Subject: [PATCH 3/3] Add comment explaining the reversed operands tests Also, fix the goofy reversed names with something clearer. --- ...20-assoc-const-arith-overflow.noopt.stderr | 32 +++++++++---------- ...9020-assoc-const-arith-overflow.opt.stderr | 32 +++++++++---------- ...h-overflow.opt_with_overflow_checks.stderr | 32 +++++++++---------- .../issue-69020-assoc-const-arith-overflow.rs | 23 ++++++------- 4 files changed, 60 insertions(+), 59 deletions(-) diff --git a/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.noopt.stderr b/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.noopt.stderr index 017a6f41dd8..510a13ea5b1 100644 --- a/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.noopt.stderr +++ b/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.noopt.stderr @@ -1,5 +1,5 @@ error: this arithmetic operation will overflow - --> $DIR/issue-69020-assoc-const-arith-overflow.rs:28:22 + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:29:22 | LL | const NEG: i32 = -i32::MIN + T::NEG; | ^^^^^^^^^ attempt to negate with overflow @@ -7,25 +7,25 @@ LL | const NEG: i32 = -i32::MIN + T::NEG; = note: `#[deny(arithmetic_overflow)]` on by default error: this arithmetic operation will overflow - --> $DIR/issue-69020-assoc-const-arith-overflow.rs:30:31 + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:31:35 | -LL | const GEN: i32 = T::NEG + (-i32::MIN); - | ^^^^^^^^^^^ attempt to negate with overflow +LL | const NEG_REV: i32 = T::NEG + (-i32::MIN); + | ^^^^^^^^^^^ attempt to negate with overflow error: this arithmetic operation will overflow - --> $DIR/issue-69020-assoc-const-arith-overflow.rs:33:22 + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:34:22 | LL | const ADD: i32 = (i32::MAX+1) + T::ADD; | ^^^^^^^^^^^^ attempt to add with overflow error: this arithmetic operation will overflow - --> $DIR/issue-69020-assoc-const-arith-overflow.rs:35:32 + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:36:36 | -LL | const DDA: i32 = T::ADD + (i32::MAX+1); - | ^^^^^^^^^^^^ attempt to add with overflow +LL | const ADD_REV: i32 = T::ADD + (i32::MAX+1); + | ^^^^^^^^^^^^ attempt to add with overflow error: this operation will panic at runtime - --> $DIR/issue-69020-assoc-const-arith-overflow.rs:38:22 + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:39:22 | LL | const DIV: i32 = (1/0) + T::DIV; | ^^^^^ attempt to divide by zero @@ -33,22 +33,22 @@ LL | const DIV: i32 = (1/0) + T::DIV; = note: `#[deny(unconditional_panic)]` on by default error: this operation will panic at runtime - --> $DIR/issue-69020-assoc-const-arith-overflow.rs:40:31 + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:41:35 | -LL | const VID: i32 = T::DIV + (1/0); - | ^^^^^ attempt to divide by zero +LL | const DIV_REV: i32 = T::DIV + (1/0); + | ^^^^^ attempt to divide by zero error: this operation will panic at runtime - --> $DIR/issue-69020-assoc-const-arith-overflow.rs:43:22 + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:44:22 | LL | const OOB: i32 = [1][1] + T::OOB; | ^^^^^^ index out of bounds: the len is 1 but the index is 1 error: this operation will panic at runtime - --> $DIR/issue-69020-assoc-const-arith-overflow.rs:45:31 + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:46:35 | -LL | const BOO: i32 = T::OOB + [1][1]; - | ^^^^^^ index out of bounds: the len is 1 but the index is 1 +LL | const OOB_REV: i32 = T::OOB + [1][1]; + | ^^^^^^ index out of bounds: the len is 1 but the index is 1 error: aborting due to 8 previous errors diff --git a/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.opt.stderr b/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.opt.stderr index 017a6f41dd8..510a13ea5b1 100644 --- a/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.opt.stderr +++ b/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.opt.stderr @@ -1,5 +1,5 @@ error: this arithmetic operation will overflow - --> $DIR/issue-69020-assoc-const-arith-overflow.rs:28:22 + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:29:22 | LL | const NEG: i32 = -i32::MIN + T::NEG; | ^^^^^^^^^ attempt to negate with overflow @@ -7,25 +7,25 @@ LL | const NEG: i32 = -i32::MIN + T::NEG; = note: `#[deny(arithmetic_overflow)]` on by default error: this arithmetic operation will overflow - --> $DIR/issue-69020-assoc-const-arith-overflow.rs:30:31 + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:31:35 | -LL | const GEN: i32 = T::NEG + (-i32::MIN); - | ^^^^^^^^^^^ attempt to negate with overflow +LL | const NEG_REV: i32 = T::NEG + (-i32::MIN); + | ^^^^^^^^^^^ attempt to negate with overflow error: this arithmetic operation will overflow - --> $DIR/issue-69020-assoc-const-arith-overflow.rs:33:22 + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:34:22 | LL | const ADD: i32 = (i32::MAX+1) + T::ADD; | ^^^^^^^^^^^^ attempt to add with overflow error: this arithmetic operation will overflow - --> $DIR/issue-69020-assoc-const-arith-overflow.rs:35:32 + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:36:36 | -LL | const DDA: i32 = T::ADD + (i32::MAX+1); - | ^^^^^^^^^^^^ attempt to add with overflow +LL | const ADD_REV: i32 = T::ADD + (i32::MAX+1); + | ^^^^^^^^^^^^ attempt to add with overflow error: this operation will panic at runtime - --> $DIR/issue-69020-assoc-const-arith-overflow.rs:38:22 + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:39:22 | LL | const DIV: i32 = (1/0) + T::DIV; | ^^^^^ attempt to divide by zero @@ -33,22 +33,22 @@ LL | const DIV: i32 = (1/0) + T::DIV; = note: `#[deny(unconditional_panic)]` on by default error: this operation will panic at runtime - --> $DIR/issue-69020-assoc-const-arith-overflow.rs:40:31 + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:41:35 | -LL | const VID: i32 = T::DIV + (1/0); - | ^^^^^ attempt to divide by zero +LL | const DIV_REV: i32 = T::DIV + (1/0); + | ^^^^^ attempt to divide by zero error: this operation will panic at runtime - --> $DIR/issue-69020-assoc-const-arith-overflow.rs:43:22 + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:44:22 | LL | const OOB: i32 = [1][1] + T::OOB; | ^^^^^^ index out of bounds: the len is 1 but the index is 1 error: this operation will panic at runtime - --> $DIR/issue-69020-assoc-const-arith-overflow.rs:45:31 + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:46:35 | -LL | const BOO: i32 = T::OOB + [1][1]; - | ^^^^^^ index out of bounds: the len is 1 but the index is 1 +LL | const OOB_REV: i32 = T::OOB + [1][1]; + | ^^^^^^ index out of bounds: the len is 1 but the index is 1 error: aborting due to 8 previous errors diff --git a/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.opt_with_overflow_checks.stderr b/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.opt_with_overflow_checks.stderr index 017a6f41dd8..510a13ea5b1 100644 --- a/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.opt_with_overflow_checks.stderr +++ b/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.opt_with_overflow_checks.stderr @@ -1,5 +1,5 @@ error: this arithmetic operation will overflow - --> $DIR/issue-69020-assoc-const-arith-overflow.rs:28:22 + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:29:22 | LL | const NEG: i32 = -i32::MIN + T::NEG; | ^^^^^^^^^ attempt to negate with overflow @@ -7,25 +7,25 @@ LL | const NEG: i32 = -i32::MIN + T::NEG; = note: `#[deny(arithmetic_overflow)]` on by default error: this arithmetic operation will overflow - --> $DIR/issue-69020-assoc-const-arith-overflow.rs:30:31 + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:31:35 | -LL | const GEN: i32 = T::NEG + (-i32::MIN); - | ^^^^^^^^^^^ attempt to negate with overflow +LL | const NEG_REV: i32 = T::NEG + (-i32::MIN); + | ^^^^^^^^^^^ attempt to negate with overflow error: this arithmetic operation will overflow - --> $DIR/issue-69020-assoc-const-arith-overflow.rs:33:22 + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:34:22 | LL | const ADD: i32 = (i32::MAX+1) + T::ADD; | ^^^^^^^^^^^^ attempt to add with overflow error: this arithmetic operation will overflow - --> $DIR/issue-69020-assoc-const-arith-overflow.rs:35:32 + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:36:36 | -LL | const DDA: i32 = T::ADD + (i32::MAX+1); - | ^^^^^^^^^^^^ attempt to add with overflow +LL | const ADD_REV: i32 = T::ADD + (i32::MAX+1); + | ^^^^^^^^^^^^ attempt to add with overflow error: this operation will panic at runtime - --> $DIR/issue-69020-assoc-const-arith-overflow.rs:38:22 + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:39:22 | LL | const DIV: i32 = (1/0) + T::DIV; | ^^^^^ attempt to divide by zero @@ -33,22 +33,22 @@ LL | const DIV: i32 = (1/0) + T::DIV; = note: `#[deny(unconditional_panic)]` on by default error: this operation will panic at runtime - --> $DIR/issue-69020-assoc-const-arith-overflow.rs:40:31 + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:41:35 | -LL | const VID: i32 = T::DIV + (1/0); - | ^^^^^ attempt to divide by zero +LL | const DIV_REV: i32 = T::DIV + (1/0); + | ^^^^^ attempt to divide by zero error: this operation will panic at runtime - --> $DIR/issue-69020-assoc-const-arith-overflow.rs:43:22 + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:44:22 | LL | const OOB: i32 = [1][1] + T::OOB; | ^^^^^^ index out of bounds: the len is 1 but the index is 1 error: this operation will panic at runtime - --> $DIR/issue-69020-assoc-const-arith-overflow.rs:45:31 + --> $DIR/issue-69020-assoc-const-arith-overflow.rs:46:35 | -LL | const BOO: i32 = T::OOB + [1][1]; - | ^^^^^^ index out of bounds: the len is 1 but the index is 1 +LL | const OOB_REV: i32 = T::OOB + [1][1]; + | ^^^^^^ index out of bounds: the len is 1 but the index is 1 error: aborting due to 8 previous errors diff --git a/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.rs b/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.rs index 9a31c10a0c6..850f65ae9d1 100644 --- a/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.rs +++ b/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.rs @@ -9,39 +9,40 @@ use std::i32; pub trait Foo { const NEG: i32; - const GEN: i32; + const NEG_REV: i32; const ADD: i32; - const DDA: i32; + const ADD_REV: i32; const DIV: i32; - const VID: i32; + const DIV_REV: i32; const OOB: i32; - const BOO: i32; + const OOB_REV: i32; } -// These constants cannot be evaluated already (they depend on `T::N`), so -// they can just be linted like normal run-time code. But codegen works -// a bit different in const context, so this test makes sure that we still catch overflow. +// These constants cannot be evaluated already (they depend on `T::N`), so they can just be linted +// like normal run-time code. But codegen works a bit different in const context, so this test +// makes sure that we still catch overflow. Also make sure we emit the same lints if we reverse the +// operands (so that the generic operand comes first). impl Foo for Vec { const NEG: i32 = -i32::MIN + T::NEG; //~^ ERROR arithmetic operation will overflow - const GEN: i32 = T::NEG + (-i32::MIN); + const NEG_REV: i32 = T::NEG + (-i32::MIN); //~^ ERROR arithmetic operation will overflow const ADD: i32 = (i32::MAX+1) + T::ADD; //~^ ERROR arithmetic operation will overflow - const DDA: i32 = T::ADD + (i32::MAX+1); + const ADD_REV: i32 = T::ADD + (i32::MAX+1); //~^ ERROR arithmetic operation will overflow const DIV: i32 = (1/0) + T::DIV; //~^ ERROR operation will panic - const VID: i32 = T::DIV + (1/0); + const DIV_REV: i32 = T::DIV + (1/0); //~^ ERROR operation will panic const OOB: i32 = [1][1] + T::OOB; //~^ ERROR operation will panic - const BOO: i32 = T::OOB + [1][1]; + const OOB_REV: i32 = T::OOB + [1][1]; //~^ ERROR operation will panic }