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 {
hir::ItemKind::Static(_, _, body_id) => {
check_const(cx, body_id);
},
- hir::ItemKind::Ty(ref ty, _) => hir::intravisit::walk_ty(
- &mut UnusedBrokenConstVisitor(cx),
- ty
- ),
_ => {},
}
}
UnreachablePub: UnreachablePub,
UnnameableTestItems: UnnameableTestItems::new(),
TypeAliasBounds: TypeAliasBounds,
+ UnusedBrokenConst: UnusedBrokenConst,
TrivialConstraints: TrivialConstraints,
TypeLimits: TypeLimits::new(),
MissingDoc: MissingDoc::new(),
//~| ERROR any use of this value will cause an error
fn main() {
- let _ = B; //~ ERROR erroneous constant used
+ let _ = B;
}
|
= 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 2 previous errors
+error: aborting due to previous error
-For more information about this error, try `rustc --explain E0080`.
//~| ERROR any use of this value will cause an error
fn main() {
- let _ = B; //~ ERROR erroneous constant used
+ let _ = B;
}
|
= 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 2 previous errors
+error: aborting due to previous error
-For more information about this error, try `rustc --explain E0080`.
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];
}
| |
| 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[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
+error: aborting due to 5 previous errors
-For more information about this error, try `rustc --explain E0080`.
fn main() {
let _ = (A, B, C, D);
- //~^ ERROR erroneous constant used
}
| |
| 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 5 previous errors
+error: aborting due to 4 previous errors
-For more information about this error, try `rustc --explain E0080`.
);
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) {
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[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
+error: aborting due to 8 previous errors
-For more information about this error, try `rustc --explain E0080`.
);
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) {
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[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
+error: aborting due to 8 previous errors
-For more information about this error, try `rustc --explain E0080`.
);
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) {
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[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
+error: aborting due to 8 previous errors
-For more information about this error, try `rustc --explain E0080`.
//~^ 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
//~^ 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() {}
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
}
|
= 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[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
+error: aborting due to previous error
-For more information about this error, try `rustc --explain E0080`.
--- /dev/null
+// 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() {}
--- /dev/null
+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
+
fn main() {
let _ = BAR;
- //~^ ERROR erroneous constant used
}
|
= 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 2 previous errors
+error: aborting due to previous error
-For more information about this error, try `rustc --explain E0080`.