add the lint back to the list, and fix tests

This commit is contained in:
Ralf Jung 2018-09-19 17:22:03 +02:00 committed by Oliver Scherer
parent 94586bc133
commit 7ed7fc881e
24 changed files with 74 additions and 296 deletions

View File

@ -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
),
_ => {},
}
}

View File

@ -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(),

View File

@ -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;
}

View File

@ -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`.

View File

@ -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;
}

View File

@ -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`.

View File

@ -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];
}

View File

@ -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`.

View File

@ -21,5 +21,4 @@ pub const D: i8 = 50 - A;
fn main() {
let _ = (A, B, C, D);
//~^ ERROR erroneous constant used
}

View File

@ -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`.

View File

@ -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>(_: T) {

View File

@ -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`.

View File

@ -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>(_: T) {

View File

@ -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`.

View File

@ -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>(_: T) {

View File

@ -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`.

View File

@ -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

View File

@ -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() {}

View File

@ -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
}

View File

@ -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`.

View File

@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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() {}

View File

@ -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

View File

@ -17,5 +17,4 @@ const BAR: u32 = FOO[5];
fn main() {
let _ = BAR;
//~^ ERROR erroneous constant used
}

View File

@ -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`.