From 7ed7fc881e7f4dabcdc45646257ddb979822d7f4 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 19 Sep 2018 17:22:03 +0200 Subject: [PATCH] add the lint back to the list, and fix tests --- src/librustc_lint/builtin.rs | 15 ------ src/librustc_lint/lib.rs | 1 + src/test/ui/array_const_index-0.rs | 2 +- src/test/ui/array_const_index-0.stderr | 9 +--- src/test/ui/array_const_index-1.rs | 2 +- src/test/ui/array_const_index-1.stderr | 9 +--- src/test/ui/consts/const-err-early.rs | 12 ++--- src/test/ui/consts/const-err-early.stderr | 39 +------------- src/test/ui/consts/const-err-multi.rs | 1 - src/test/ui/consts/const-err-multi.stderr | 9 +--- .../consts/const-eval/const-eval-overflow2.rs | 16 +++--- .../const-eval/const-eval-overflow2.stderr | 51 +------------------ .../const-eval/const-eval-overflow2b.rs | 16 +++--- .../const-eval/const-eval-overflow2b.stderr | 51 +------------------ .../const-eval/const-eval-overflow2c.rs | 16 +++--- .../const-eval/const-eval-overflow2c.stderr | 51 +------------------ .../ui/consts/const-eval/pub_const_err.rs | 2 - .../ui/consts/const-eval/pub_const_err_bin.rs | 2 - .../const-eval/union-const-eval-field.rs | 2 - .../const-eval/union-const-eval-field.stderr | 22 +------- .../consts/const-eval/unused-broken-const.rs | 18 +++++++ .../const-eval/unused-broken-const.stderr | 14 +++++ src/test/ui/consts/const-slice-oob.rs | 1 - src/test/ui/consts/const-slice-oob.stderr | 9 +--- 24 files changed, 74 insertions(+), 296 deletions(-) create mode 100644 src/test/ui/consts/const-eval/unused-broken-const.rs create mode 100644 src/test/ui/consts/const-eval/unused-broken-const.stderr diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 597b6ae2366..c50f57e6c90 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1607,17 +1607,6 @@ fn check_const(cx: &LateContext, body_id: hir::BodyId) { let _ = cx.tcx.const_eval(param_env.and(cid)); } -struct UnusedBrokenConstVisitor<'a, 'tcx: 'a>(&'a LateContext<'a, 'tcx>); - -impl<'a, 'tcx, 'v> hir::intravisit::Visitor<'v> for UnusedBrokenConstVisitor<'a, 'tcx> { - fn visit_nested_body(&mut self, id: hir::BodyId) { - check_const(self.0, id); - } - fn nested_visit_map<'this>(&'this mut self) -> hir::intravisit::NestedVisitorMap<'this, 'v> { - hir::intravisit::NestedVisitorMap::None - } -} - impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedBrokenConst { fn check_item(&mut self, cx: &LateContext, it: &hir::Item) { match it.node { @@ -1627,10 +1616,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedBrokenConst { hir::ItemKind::Static(_, _, body_id) => { check_const(cx, body_id); }, - hir::ItemKind::Ty(ref ty, _) => hir::intravisit::walk_ty( - &mut UnusedBrokenConstVisitor(cx), - ty - ), _ => {}, } } diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 211b8471115..5bf2b76e668 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -152,6 +152,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { UnreachablePub: UnreachablePub, UnnameableTestItems: UnnameableTestItems::new(), TypeAliasBounds: TypeAliasBounds, + UnusedBrokenConst: UnusedBrokenConst, TrivialConstraints: TrivialConstraints, TypeLimits: TypeLimits::new(), MissingDoc: MissingDoc::new(), diff --git a/src/test/ui/array_const_index-0.rs b/src/test/ui/array_const_index-0.rs index 0ad297eeb5c..e82458b10d9 100644 --- a/src/test/ui/array_const_index-0.rs +++ b/src/test/ui/array_const_index-0.rs @@ -14,5 +14,5 @@ const B: i32 = (&A)[1]; //~| ERROR any use of this value will cause an error fn main() { - let _ = B; //~ ERROR erroneous constant used + let _ = B; } diff --git a/src/test/ui/array_const_index-0.stderr b/src/test/ui/array_const_index-0.stderr index 38163b1f4b1..49c316eee12 100644 --- a/src/test/ui/array_const_index-0.stderr +++ b/src/test/ui/array_const_index-0.stderr @@ -8,12 +8,5 @@ LL | const B: i32 = (&A)[1]; | = note: #[deny(const_err)] on by default -error[E0080]: erroneous constant used - --> $DIR/array_const_index-0.rs:17:13 - | -LL | let _ = B; //~ ERROR erroneous constant used - | ^ referenced constant has errors +error: aborting due to previous error -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/array_const_index-1.rs b/src/test/ui/array_const_index-1.rs index 4c7dcfbb347..21028a447f4 100644 --- a/src/test/ui/array_const_index-1.rs +++ b/src/test/ui/array_const_index-1.rs @@ -14,5 +14,5 @@ const B: i32 = A[1]; //~| ERROR any use of this value will cause an error fn main() { - let _ = B; //~ ERROR erroneous constant used + let _ = B; } diff --git a/src/test/ui/array_const_index-1.stderr b/src/test/ui/array_const_index-1.stderr index b122e590c88..fa0e6e6afc6 100644 --- a/src/test/ui/array_const_index-1.stderr +++ b/src/test/ui/array_const_index-1.stderr @@ -8,12 +8,5 @@ LL | const B: i32 = A[1]; | = note: #[deny(const_err)] on by default -error[E0080]: erroneous constant used - --> $DIR/array_const_index-1.rs:17:13 - | -LL | let _ = B; //~ ERROR erroneous constant used - | ^ referenced constant has errors +error: aborting due to previous error -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-err-early.rs b/src/test/ui/consts/const-err-early.rs index 1cbfb918427..39b1b342eac 100644 --- a/src/test/ui/consts/const-err-early.rs +++ b/src/test/ui/consts/const-err-early.rs @@ -17,10 +17,10 @@ pub const D: u8 = 42u8 - (42u8 + 1); //~ ERROR const_err pub const E: u8 = [5u8][1]; //~ ERROR const_err fn main() { - let _a = A; //~ ERROR erroneous constant used - let _b = B; //~ ERROR erroneous constant used - let _c = C; //~ ERROR erroneous constant used - let _d = D; //~ ERROR erroneous constant used - let _e = E; //~ ERROR erroneous constant used - let _e = [6u8][1]; //~ ERROR index out of bounds + let _a = A; + let _b = B; + let _c = C; + let _d = D; + let _e = E; + let _e = [6u8][1]; } diff --git a/src/test/ui/consts/const-err-early.stderr b/src/test/ui/consts/const-err-early.stderr index 8cc112191b5..1dd6c096e37 100644 --- a/src/test/ui/consts/const-err-early.stderr +++ b/src/test/ui/consts/const-err-early.stderr @@ -44,42 +44,5 @@ LL | pub const E: u8 = [5u8][1]; //~ ERROR const_err | | | index out of bounds: the len is 1 but the index is 1 -error[E0080]: erroneous constant used - --> $DIR/const-err-early.rs:20:14 - | -LL | let _a = A; //~ ERROR erroneous constant used - | ^ referenced constant has errors +error: aborting due to 5 previous errors -error[E0080]: erroneous constant used - --> $DIR/const-err-early.rs:21:14 - | -LL | let _b = B; //~ ERROR erroneous constant used - | ^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-err-early.rs:22:14 - | -LL | let _c = C; //~ ERROR erroneous constant used - | ^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-err-early.rs:23:14 - | -LL | let _d = D; //~ ERROR erroneous constant used - | ^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-err-early.rs:24:14 - | -LL | let _e = E; //~ ERROR erroneous constant used - | ^ referenced constant has errors - -error: index out of bounds: the len is 1 but the index is 1 - --> $DIR/const-err-early.rs:25:14 - | -LL | let _e = [6u8][1]; //~ ERROR index out of bounds - | ^^^^^^^^ - -error: aborting due to 11 previous errors - -For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-err-multi.rs b/src/test/ui/consts/const-err-multi.rs index 20eaebfbe56..5cf3114c64a 100644 --- a/src/test/ui/consts/const-err-multi.rs +++ b/src/test/ui/consts/const-err-multi.rs @@ -21,5 +21,4 @@ pub const D: i8 = 50 - A; fn main() { let _ = (A, B, C, D); - //~^ ERROR erroneous constant used } diff --git a/src/test/ui/consts/const-err-multi.stderr b/src/test/ui/consts/const-err-multi.stderr index da6f31a3886..e77a31a9f5f 100644 --- a/src/test/ui/consts/const-err-multi.stderr +++ b/src/test/ui/consts/const-err-multi.stderr @@ -36,12 +36,5 @@ LL | pub const D: i8 = 50 - A; | | | referenced constant has errors -error[E0080]: erroneous constant used - --> $DIR/const-err-multi.rs:23:13 - | -LL | let _ = (A, B, C, D); - | ^^^^^^^^^^^^ referenced constant has errors +error: aborting due to 4 previous errors -error: aborting due to 5 previous errors - -For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/const-eval-overflow2.rs b/src/test/ui/consts/const-eval/const-eval-overflow2.rs index c61a1b3edb7..8e094a7f7dc 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow2.rs +++ b/src/test/ui/consts/const-eval/const-eval-overflow2.rs @@ -60,15 +60,15 @@ const VALS_U64: (u64,) = //~ ERROR any use of this value will cause an error ); fn main() { - foo(VALS_I8); //~ ERROR erroneous constant used - foo(VALS_I16); //~ ERROR erroneous constant used - foo(VALS_I32); //~ ERROR erroneous constant used - foo(VALS_I64); //~ ERROR erroneous constant used + foo(VALS_I8); + foo(VALS_I16); + foo(VALS_I32); + foo(VALS_I64); - foo(VALS_U8); //~ ERROR erroneous constant used - foo(VALS_U16); //~ ERROR erroneous constant used - foo(VALS_U32); //~ ERROR erroneous constant used - foo(VALS_U64); //~ ERROR erroneous constant used + foo(VALS_U8); + foo(VALS_U16); + foo(VALS_U32); + foo(VALS_U64); } fn foo(_: T) { diff --git a/src/test/ui/consts/const-eval/const-eval-overflow2.stderr b/src/test/ui/consts/const-eval/const-eval-overflow2.stderr index 0484335fd0c..596ba6bb223 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow2.stderr +++ b/src/test/ui/consts/const-eval/const-eval-overflow2.stderr @@ -82,54 +82,5 @@ LL | | u64::MIN - 1, LL | | ); | |_______^ -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2.rs:63:5 - | -LL | foo(VALS_I8); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^ referenced constant has errors +error: aborting due to 8 previous errors -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2.rs:64:5 - | -LL | foo(VALS_I16); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2.rs:65:5 - | -LL | foo(VALS_I32); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2.rs:66:5 - | -LL | foo(VALS_I64); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2.rs:68:5 - | -LL | foo(VALS_U8); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2.rs:69:5 - | -LL | foo(VALS_U16); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2.rs:70:5 - | -LL | foo(VALS_U32); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2.rs:71:5 - | -LL | foo(VALS_U64); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error: aborting due to 16 previous errors - -For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/const-eval-overflow2b.rs b/src/test/ui/consts/const-eval/const-eval-overflow2b.rs index 47b0977ec1d..c69d03071e7 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow2b.rs +++ b/src/test/ui/consts/const-eval/const-eval-overflow2b.rs @@ -60,15 +60,15 @@ const VALS_U64: (u64,) = //~ ERROR any use of this value will cause an error ); fn main() { - foo(VALS_I8); //~ ERROR erroneous constant used - foo(VALS_I16); //~ ERROR erroneous constant used - foo(VALS_I32); //~ ERROR erroneous constant used - foo(VALS_I64); //~ ERROR erroneous constant used + foo(VALS_I8); + foo(VALS_I16); + foo(VALS_I32); + foo(VALS_I64); - foo(VALS_U8); //~ ERROR erroneous constant used - foo(VALS_U16); //~ ERROR erroneous constant used - foo(VALS_U32); //~ ERROR erroneous constant used - foo(VALS_U64); //~ ERROR erroneous constant used + foo(VALS_U8); + foo(VALS_U16); + foo(VALS_U32); + foo(VALS_U64); } fn foo(_: T) { diff --git a/src/test/ui/consts/const-eval/const-eval-overflow2b.stderr b/src/test/ui/consts/const-eval/const-eval-overflow2b.stderr index 8922b35a0b2..82f245eaee8 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow2b.stderr +++ b/src/test/ui/consts/const-eval/const-eval-overflow2b.stderr @@ -82,54 +82,5 @@ LL | | u64::MAX + 1, LL | | ); | |_______^ -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2b.rs:63:5 - | -LL | foo(VALS_I8); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^ referenced constant has errors +error: aborting due to 8 previous errors -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2b.rs:64:5 - | -LL | foo(VALS_I16); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2b.rs:65:5 - | -LL | foo(VALS_I32); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2b.rs:66:5 - | -LL | foo(VALS_I64); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2b.rs:68:5 - | -LL | foo(VALS_U8); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2b.rs:69:5 - | -LL | foo(VALS_U16); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2b.rs:70:5 - | -LL | foo(VALS_U32); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2b.rs:71:5 - | -LL | foo(VALS_U64); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error: aborting due to 16 previous errors - -For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/const-eval-overflow2c.rs b/src/test/ui/consts/const-eval/const-eval-overflow2c.rs index b4e1a0bc099..f442661ec63 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow2c.rs +++ b/src/test/ui/consts/const-eval/const-eval-overflow2c.rs @@ -60,15 +60,15 @@ const VALS_U64: (u64,) = //~ ERROR any use of this value will cause an error ); fn main() { - foo(VALS_I8); //~ ERROR erroneous constant used - foo(VALS_I16); //~ ERROR erroneous constant used - foo(VALS_I32); //~ ERROR erroneous constant used - foo(VALS_I64); //~ ERROR erroneous constant used + foo(VALS_I8); + foo(VALS_I16); + foo(VALS_I32); + foo(VALS_I64); - foo(VALS_U8); //~ ERROR erroneous constant used - foo(VALS_U16); //~ ERROR erroneous constant used - foo(VALS_U32); //~ ERROR erroneous constant used - foo(VALS_U64); //~ ERROR erroneous constant used + foo(VALS_U8); + foo(VALS_U16); + foo(VALS_U32); + foo(VALS_U64); } fn foo(_: T) { diff --git a/src/test/ui/consts/const-eval/const-eval-overflow2c.stderr b/src/test/ui/consts/const-eval/const-eval-overflow2c.stderr index 023156a40dd..91064eb867d 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow2c.stderr +++ b/src/test/ui/consts/const-eval/const-eval-overflow2c.stderr @@ -82,54 +82,5 @@ LL | | u64::MAX * 2, LL | | ); | |_______^ -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2c.rs:63:5 - | -LL | foo(VALS_I8); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^ referenced constant has errors +error: aborting due to 8 previous errors -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2c.rs:64:5 - | -LL | foo(VALS_I16); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2c.rs:65:5 - | -LL | foo(VALS_I32); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2c.rs:66:5 - | -LL | foo(VALS_I64); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2c.rs:68:5 - | -LL | foo(VALS_U8); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2c.rs:69:5 - | -LL | foo(VALS_U16); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2c.rs:70:5 - | -LL | foo(VALS_U32); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error[E0080]: erroneous constant used - --> $DIR/const-eval-overflow2c.rs:71:5 - | -LL | foo(VALS_U64); //~ ERROR erroneous constant used - | ^^^^^^^^^^^^^ referenced constant has errors - -error: aborting due to 16 previous errors - -For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/pub_const_err.rs b/src/test/ui/consts/const-eval/pub_const_err.rs index 48c172b5e31..41cf844a8e2 100644 --- a/src/test/ui/consts/const-eval/pub_const_err.rs +++ b/src/test/ui/consts/const-eval/pub_const_err.rs @@ -17,5 +17,3 @@ pub const Z: u32 = 0 - 1; //~^ WARN any use of this value will cause an error pub type Foo = [i32; 0 - 1]; -//~^ WARN attempt to subtract with overflow -//~| WARN this array length cannot be used diff --git a/src/test/ui/consts/const-eval/pub_const_err_bin.rs b/src/test/ui/consts/const-eval/pub_const_err_bin.rs index 849d40cf107..0ee7d603e31 100644 --- a/src/test/ui/consts/const-eval/pub_const_err_bin.rs +++ b/src/test/ui/consts/const-eval/pub_const_err_bin.rs @@ -15,7 +15,5 @@ pub const Z: u32 = 0 - 1; //~^ WARN any use of this value will cause an error pub type Foo = [i32; 0 - 1]; -//~^ WARN attempt to subtract with overflow -//~| WARN this array length cannot be used fn main() {} diff --git a/src/test/ui/consts/const-eval/union-const-eval-field.rs b/src/test/ui/consts/const-eval/union-const-eval-field.rs index 759dab6c256..c0bfbc17629 100644 --- a/src/test/ui/consts/const-eval/union-const-eval-field.rs +++ b/src/test/ui/consts/const-eval/union-const-eval-field.rs @@ -36,12 +36,10 @@ const fn read_field2() -> Field2 { const fn read_field3() -> Field3 { const FIELD3: Field3 = unsafe { UNION.field3 }; //~ ERROR any use of this value FIELD3 - //~^ erroneous constant used } fn main() { assert_eq!(read_field1(), FLOAT1_AS_I32); assert_eq!(read_field2(), 1.0); assert_eq!(read_field3(), unsafe { UNION.field3 }); - //~^ ERROR evaluation of constant expression failed } diff --git a/src/test/ui/consts/const-eval/union-const-eval-field.stderr b/src/test/ui/consts/const-eval/union-const-eval-field.stderr index 6a64f0c3671..565cd916ffc 100644 --- a/src/test/ui/consts/const-eval/union-const-eval-field.stderr +++ b/src/test/ui/consts/const-eval/union-const-eval-field.stderr @@ -6,25 +6,5 @@ LL | const FIELD3: Field3 = unsafe { UNION.field3 }; //~ ERROR any use of th | = note: #[deny(const_err)] on by default -error[E0080]: erroneous constant used - --> $DIR/union-const-eval-field.rs:38:5 - | -LL | FIELD3 - | ^^^^^^ referenced constant has errors +error: aborting due to previous error -error[E0080]: evaluation of constant expression failed - --> $DIR/union-const-eval-field.rs:45:5 - | -LL | FIELD3 - | ------ referenced constant has errors -... -LL | assert_eq!(read_field3(), unsafe { UNION.field3 }); - | ^^^^^^^^^^^-------------^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | inside call to `read_field3` - | - = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/unused-broken-const.rs b/src/test/ui/consts/const-eval/unused-broken-const.rs new file mode 100644 index 00000000000..53ce82f8e87 --- /dev/null +++ b/src/test/ui/consts/const-eval/unused-broken-const.rs @@ -0,0 +1,18 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// make sure that an *unused* broken const triggers an error even in a check build + +// compile-flags: --emit=dep-info,metadata + +const FOO: i32 = [][0]; +//~^ ERROR any use of this value will cause an error + +fn main() {} diff --git a/src/test/ui/consts/const-eval/unused-broken-const.stderr b/src/test/ui/consts/const-eval/unused-broken-const.stderr new file mode 100644 index 00000000000..5fb2a3722e2 --- /dev/null +++ b/src/test/ui/consts/const-eval/unused-broken-const.stderr @@ -0,0 +1,14 @@ +warning: due to multiple output types requested, the explicitly specified output file name will be adapted for each output type + +error: any use of this value will cause an error + --> $DIR/unused-broken-const.rs:15:1 + | +LL | const FOO: i32 = [][0]; + | ^^^^^^^^^^^^^^^^^-----^ + | | + | index out of bounds: the len is 0 but the index is 0 + | + = note: #[deny(const_err)] on by default + +error: aborting due to previous error + diff --git a/src/test/ui/consts/const-slice-oob.rs b/src/test/ui/consts/const-slice-oob.rs index cc7f86f97a1..04d9b01633b 100644 --- a/src/test/ui/consts/const-slice-oob.rs +++ b/src/test/ui/consts/const-slice-oob.rs @@ -17,5 +17,4 @@ const BAR: u32 = FOO[5]; fn main() { let _ = BAR; - //~^ ERROR erroneous constant used } diff --git a/src/test/ui/consts/const-slice-oob.stderr b/src/test/ui/consts/const-slice-oob.stderr index 763afae62ea..4a8ad5ed6ca 100644 --- a/src/test/ui/consts/const-slice-oob.stderr +++ b/src/test/ui/consts/const-slice-oob.stderr @@ -8,12 +8,5 @@ LL | const BAR: u32 = FOO[5]; | = note: #[deny(const_err)] on by default -error[E0080]: erroneous constant used - --> $DIR/const-slice-oob.rs:19:13 - | -LL | let _ = BAR; - | ^^^ referenced constant has errors +error: aborting due to previous error -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0080`.