mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 19:58:32 +00:00
Rebase fallout
This commit is contained in:
parent
d2e682afed
commit
1c5ff292fc
@ -1547,49 +1547,6 @@ impl LintPass for UnusedBrokenConst {
|
|||||||
lint_array!()
|
lint_array!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn validate_const<'a, 'tcx>(
|
|
||||||
tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
|
|
||||||
constant: &ty::Const<'tcx>,
|
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
|
||||||
gid: ::rustc::mir::interpret::GlobalId<'tcx>,
|
|
||||||
what: &str,
|
|
||||||
) {
|
|
||||||
let ecx = ::rustc_mir::const_eval::mk_eval_cx(tcx, gid.instance, param_env).unwrap();
|
|
||||||
let result = (|| {
|
|
||||||
let op = ecx.const_to_op(constant)?;
|
|
||||||
let mut ref_tracking = ::rustc_mir::interpret::RefTracking::new(op);
|
|
||||||
while let Some((op, mut path)) = ref_tracking.todo.pop() {
|
|
||||||
ecx.validate_operand(
|
|
||||||
op,
|
|
||||||
&mut path,
|
|
||||||
Some(&mut ref_tracking),
|
|
||||||
/* const_mode */ true,
|
|
||||||
)?;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
})();
|
|
||||||
if let Err(err) = result {
|
|
||||||
let (trace, span) = ecx.generate_stacktrace(None);
|
|
||||||
let err = ::rustc::mir::interpret::ConstEvalErr {
|
|
||||||
error: err,
|
|
||||||
stacktrace: trace,
|
|
||||||
span,
|
|
||||||
};
|
|
||||||
let err = err.struct_error(
|
|
||||||
tcx.at(span),
|
|
||||||
&format!("this {} likely exhibits undefined behavior", what),
|
|
||||||
);
|
|
||||||
if let Some(mut err) = err {
|
|
||||||
err.note("The rules on what exactly is undefined behavior aren't clear, \
|
|
||||||
so this check might be overzealous. Please open an issue on the rust compiler \
|
|
||||||
repository if you believe it should not be considered undefined behavior",
|
|
||||||
);
|
|
||||||
err.emit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn check_const(cx: &LateContext, body_id: hir::BodyId) {
|
fn check_const(cx: &LateContext, body_id: hir::BodyId) {
|
||||||
let def_id = cx.tcx.hir.body_owner_def_id(body_id);
|
let def_id = cx.tcx.hir.body_owner_def_id(body_id);
|
||||||
let is_static = cx.tcx.is_static(def_id).is_some();
|
let is_static = cx.tcx.is_static(def_id).is_some();
|
||||||
|
@ -24,7 +24,6 @@ use rustc::ty::{self, Ty, TyCtxt, Instance, query::TyCtxtAt};
|
|||||||
use rustc::ty::layout::{self, Size, LayoutOf, TyLayout};
|
use rustc::ty::layout::{self, Size, LayoutOf, TyLayout};
|
||||||
use rustc::ty::subst::Subst;
|
use rustc::ty::subst::Subst;
|
||||||
use rustc::traits::Reveal;
|
use rustc::traits::Reveal;
|
||||||
use rustc::util::nodemap::FxHashSet;
|
|
||||||
use rustc_data_structures::indexed_vec::IndexVec;
|
use rustc_data_structures::indexed_vec::IndexVec;
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc::util::common::ErrorReported;
|
use rustc::util::common::ErrorReported;
|
||||||
@ -36,7 +35,7 @@ use interpret::{self,
|
|||||||
PlaceTy, MemPlace, OpTy, Operand, Value, Pointer, Scalar, ConstValue,
|
PlaceTy, MemPlace, OpTy, Operand, Value, Pointer, Scalar, ConstValue,
|
||||||
EvalResult, EvalError, EvalErrorKind, GlobalId, EvalContext, StackPopCleanup,
|
EvalResult, EvalError, EvalErrorKind, GlobalId, EvalContext, StackPopCleanup,
|
||||||
Allocation, AllocId, MemoryKind,
|
Allocation, AllocId, MemoryKind,
|
||||||
snapshot,
|
snapshot, RefTracking,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Number of steps until the detector even starts doing anything.
|
/// Number of steps until the detector even starts doing anything.
|
||||||
@ -542,15 +541,13 @@ fn validate_const<'a, 'tcx>(
|
|||||||
let ecx = mk_eval_cx(tcx, cid.instance, key.param_env).unwrap();
|
let ecx = mk_eval_cx(tcx, cid.instance, key.param_env).unwrap();
|
||||||
let val = (|| {
|
let val = (|| {
|
||||||
let op = ecx.const_to_op(constant)?;
|
let op = ecx.const_to_op(constant)?;
|
||||||
let mut todo = vec![(op, Vec::new())];
|
let mut ref_tracking = RefTracking::new(op);
|
||||||
let mut seen = FxHashSet();
|
while let Some((op, mut path)) = ref_tracking.todo.pop() {
|
||||||
seen.insert(op);
|
|
||||||
while let Some((op, mut path)) = todo.pop() {
|
|
||||||
ecx.validate_operand(
|
ecx.validate_operand(
|
||||||
op,
|
op,
|
||||||
&mut path,
|
&mut path,
|
||||||
&mut seen,
|
Some(&mut ref_tracking),
|
||||||
&mut todo,
|
/* const_mode */ true,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
Ok(constant)
|
Ok(constant)
|
||||||
|
@ -16,7 +16,7 @@ const fn f(x: usize) -> usize {
|
|||||||
let mut sum = 0;
|
let mut sum = 0;
|
||||||
//~^ let bindings in constant functions are unstable
|
//~^ let bindings in constant functions are unstable
|
||||||
//~| statements in constant functions are unstable
|
//~| statements in constant functions are unstable
|
||||||
for i in 0..x { //~ ERROR E0080
|
for i in 0..x {
|
||||||
//~^ ERROR E0015
|
//~^ ERROR E0015
|
||||||
//~| ERROR E0019
|
//~| ERROR E0019
|
||||||
sum += i;
|
sum += i;
|
||||||
|
@ -14,5 +14,4 @@ fn main() {
|
|||||||
[(); {while true {break}; 0}]; //~ ERROR constant contains unimplemented expression type
|
[(); {while true {break}; 0}]; //~ ERROR constant contains unimplemented expression type
|
||||||
[(); { for _ in 0usize.. {}; 0}]; //~ ERROR calls in constants are limited to constant functions
|
[(); { for _ in 0usize.. {}; 0}]; //~ ERROR calls in constants are limited to constant functions
|
||||||
//~^ ERROR constant contains unimplemented expression type
|
//~^ ERROR constant contains unimplemented expression type
|
||||||
//~| ERROR evaluation of constant value failed
|
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,6 @@ error[E0015]: calls in constants are limited to constant functions, tuple struct
|
|||||||
LL | let _ = [0; f(2)];
|
LL | let _ = [0; f(2)];
|
||||||
| ^^^^
|
| ^^^^
|
||||||
|
|
||||||
error[E0080]: evaluation of constant value failed
|
error: aborting due to previous error
|
||||||
--> $DIR/const-call.rs:16:17
|
|
||||||
|
|
|
||||||
LL | let _ = [0; f(2)];
|
|
||||||
| ^^^^ calling non-const fn `f`
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0015`.
|
For more information about this error, try `rustc --explain E0015`.
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
warning: any use of this value will cause an error
|
|
||||||
--> $DIR/conditional_array_execution.rs:15:1
|
|
||||||
|
|
|
||||||
LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
|
|
||||||
| ^^^^^^^^^^^^^^^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
| |
|
|
||||||
| attempt to subtract with overflow
|
|
||||||
|
|
|
||||||
note: lint level defined here
|
|
||||||
--> $DIR/conditional_array_execution.rs:11:9
|
|
||||||
|
|
|
||||||
LL | #![warn(const_err)]
|
|
||||||
| ^^^^^^^^^
|
|
||||||
|
|
||||||
error[E0080]: evaluation of constant expression failed
|
|
||||||
--> $DIR/conditional_array_execution.rs:19:14
|
|
||||||
|
|
|
||||||
LL | println!("{}", FOO);
|
|
||||||
| ^^^^ --- referenced constant has errors
|
|
||||||
|
|
||||||
error[E0080]: evaluation of constant expression failed
|
|
||||||
--> $DIR/conditional_array_execution.rs:19:20
|
|
||||||
|
|
|
||||||
LL | println!("{}", FOO);
|
|
||||||
| ^^^ referenced constant has errors
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0080`.
|
|
@ -1,43 +0,0 @@
|
|||||||
warning: any use of this value will cause an error
|
|
||||||
--> $DIR/issue-43197.rs:20:5
|
|
||||||
|
|
|
||||||
LL | const X: u32 = 0-1;
|
|
||||||
| ^^^^^^^^^^^^^^^---^
|
|
||||||
| |
|
|
||||||
| attempt to subtract with overflow
|
|
||||||
|
|
|
||||||
note: lint level defined here
|
|
||||||
--> $DIR/issue-43197.rs:11:9
|
|
||||||
|
|
|
||||||
LL | #![warn(const_err)]
|
|
||||||
| ^^^^^^^^^
|
|
||||||
|
|
||||||
warning: any use of this value will cause an error
|
|
||||||
--> $DIR/issue-43197.rs:22:5
|
|
||||||
|
|
|
||||||
LL | const Y: u32 = foo(0-1);
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^---^^
|
|
||||||
| |
|
|
||||||
| attempt to subtract with overflow
|
|
||||||
|
|
||||||
error[E0080]: evaluation of constant expression failed
|
|
||||||
--> $DIR/issue-43197.rs:24:14
|
|
||||||
|
|
|
||||||
LL | println!("{} {}", X, Y);
|
|
||||||
| ^^^^^^^ - referenced constant has errors
|
|
||||||
|
|
||||||
error[E0080]: evaluation of constant expression failed
|
|
||||||
--> $DIR/issue-43197.rs:24:26
|
|
||||||
|
|
|
||||||
LL | println!("{} {}", X, Y);
|
|
||||||
| ^ referenced constant has errors
|
|
||||||
|
|
||||||
error[E0080]: evaluation of constant expression failed
|
|
||||||
--> $DIR/issue-43197.rs:24:23
|
|
||||||
|
|
|
||||||
LL | println!("{} {}", X, Y);
|
|
||||||
| ^ referenced constant has errors
|
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0080`.
|
|
@ -1,5 +1,5 @@
|
|||||||
warning: any use of this value will cause an error
|
warning: any use of this value will cause an error
|
||||||
--> $DIR/issue-43197.rs:20:5
|
--> $DIR/issue-43197.rs:18:5
|
||||||
|
|
|
|
||||||
LL | const X: u32 = 0-1;
|
LL | const X: u32 = 0-1;
|
||||||
| ^^^^^^^^^^^^^^^---^
|
| ^^^^^^^^^^^^^^^---^
|
||||||
@ -13,7 +13,7 @@ LL | #![warn(const_err)]
|
|||||||
| ^^^^^^^^^
|
| ^^^^^^^^^
|
||||||
|
|
||||||
warning: any use of this value will cause an error
|
warning: any use of this value will cause an error
|
||||||
--> $DIR/issue-43197.rs:22:5
|
--> $DIR/issue-43197.rs:20:5
|
||||||
|
|
|
|
||||||
LL | const Y: u32 = foo(0-1);
|
LL | const Y: u32 = foo(0-1);
|
||||||
| ^^^^^^^^^^^^^^^^^^^---^^
|
| ^^^^^^^^^^^^^^^^^^^---^^
|
||||||
@ -21,13 +21,13 @@ LL | const Y: u32 = foo(0-1);
|
|||||||
| attempt to subtract with overflow
|
| attempt to subtract with overflow
|
||||||
|
|
||||||
error[E0080]: evaluation of constant expression failed
|
error[E0080]: evaluation of constant expression failed
|
||||||
--> $DIR/issue-43197.rs:24:26
|
--> $DIR/issue-43197.rs:22:26
|
||||||
|
|
|
|
||||||
LL | println!("{} {}", X, Y);
|
LL | println!("{} {}", X, Y);
|
||||||
| ^ referenced constant has errors
|
| ^ referenced constant has errors
|
||||||
|
|
||||||
error[E0080]: evaluation of constant expression failed
|
error[E0080]: evaluation of constant expression failed
|
||||||
--> $DIR/issue-43197.rs:24:23
|
--> $DIR/issue-43197.rs:22:23
|
||||||
|
|
|
|
||||||
LL | println!("{} {}", X, Y);
|
LL | println!("{} {}", X, Y);
|
||||||
| ^ referenced constant has errors
|
| ^ referenced constant has errors
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
error[E0080]: evaluation of constant expression failed
|
|
||||||
--> $DIR/issue-44578.rs:35:14
|
|
||||||
|
|
|
||||||
LL | println!("{}", <Bar<u16, u8> as Foo>::AMT);
|
|
||||||
| ^^^^ -------------------------- referenced constant has errors
|
|
||||||
|
|
||||||
error[E0080]: evaluation of constant expression failed
|
|
||||||
--> $DIR/issue-44578.rs:35:20
|
|
||||||
|
|
|
||||||
LL | println!("{}", <Bar<u16, u8> as Foo>::AMT);
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0080`.
|
|
@ -8,7 +8,7 @@ error[E0080]: it is undefined behavior to use this value
|
|||||||
--> $DIR/issue-52442.rs:12:11
|
--> $DIR/issue-52442.rs:12:11
|
||||||
|
|
|
|
||||||
LL | [(); { &loop { break } as *const _ as usize } ]; //~ ERROR unimplemented expression type
|
LL | [(); { &loop { break } as *const _ as usize } ]; //~ ERROR unimplemented expression type
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected the type usize
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected initialized plain bits
|
||||||
|
|
|
|
||||||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
|
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
|
||||||
|
|
||||||
|
@ -1,49 +0,0 @@
|
|||||||
error[E0308]: mismatched types
|
|
||||||
--> $DIR/issue-52443.rs:12:10
|
|
||||||
|
|
|
||||||
LL | [(); & { loop { continue } } ]; //~ ERROR mismatched types
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
| |
|
|
||||||
| expected usize, found reference
|
|
||||||
| help: consider removing the borrow: `{ loop { continue } }`
|
|
||||||
|
|
|
||||||
= note: expected type `usize`
|
|
||||||
found type `&_`
|
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
|
||||||
--> $DIR/issue-52443.rs:13:17
|
|
||||||
|
|
|
||||||
LL | [(); loop { break }]; //~ ERROR mismatched types
|
|
||||||
| ^^^^^ expected (), found usize
|
|
||||||
|
|
|
||||||
= note: expected type `()`
|
|
||||||
found type `usize`
|
|
||||||
|
|
||||||
error[E0019]: constant contains unimplemented expression type
|
|
||||||
--> $DIR/issue-52443.rs:14:11
|
|
||||||
|
|
|
||||||
LL | [(); {while true {break}; 0}]; //~ ERROR constant contains unimplemented expression type
|
|
||||||
| ^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
|
|
||||||
--> $DIR/issue-52443.rs:15:21
|
|
||||||
|
|
|
||||||
LL | [(); { for _ in 0usize.. {}; 0}]; //~ ERROR calls in constants are limited to constant functions
|
|
||||||
| ^^^^^^^^
|
|
||||||
|
|
||||||
error[E0019]: constant contains unimplemented expression type
|
|
||||||
--> $DIR/issue-52443.rs:15:21
|
|
||||||
|
|
|
||||||
LL | [(); { for _ in 0usize.. {}; 0}]; //~ ERROR calls in constants are limited to constant functions
|
|
||||||
| ^^^^^^^^
|
|
||||||
|
|
||||||
error[E0080]: evaluation of constant value failed
|
|
||||||
--> $DIR/issue-52443.rs:15:21
|
|
||||||
|
|
|
||||||
LL | [(); { for _ in 0usize.. {}; 0}]; //~ ERROR calls in constants are limited to constant functions
|
|
||||||
| ^^^^^^^^ calling non-const fn `<I as std::iter::IntoIterator><std::ops::RangeFrom<usize>>::into_iter`
|
|
||||||
|
|
||||||
error: aborting due to 6 previous errors
|
|
||||||
|
|
||||||
Some errors occurred: E0015, E0019, E0080, E0308.
|
|
||||||
For more information about an error, try `rustc --explain E0015`.
|
|
@ -0,0 +1,14 @@
|
|||||||
|
error[E0716]: temporary value dropped while borrowed
|
||||||
|
--> $DIR/promoted_const_fn_fail_deny_const_err.rs:31:27
|
||||||
|
|
|
||||||
|
LL | let x: &'static u8 = &(bar() + 1);
|
||||||
|
| ----------- ^^^^^^^^^^^ creates a temporary which is freed while still in use
|
||||||
|
| |
|
||||||
|
| type annotation requires that borrow lasts for `'static`
|
||||||
|
...
|
||||||
|
LL | }
|
||||||
|
| - temporary value is freed at the end of this statement
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0716`.
|
@ -1,19 +1,14 @@
|
|||||||
error: reaching this expression at runtime will panic or abort
|
error[E0597]: borrowed value does not live long enough
|
||||||
--> $DIR/promoted_const_fn_fail_deny_const_err.rs:31:26
|
--> $DIR/promoted_const_fn_fail_deny_const_err.rs:31:27
|
||||||
|
|
|
|
||||||
LL | Bar { a: &42 }.b as u8
|
|
||||||
| ---------------------- a raw memory access tried to access part of a pointer value as raw bytes
|
|
||||||
...
|
|
||||||
LL | let x: &'static u8 = &(bar() + 1);
|
LL | let x: &'static u8 = &(bar() + 1);
|
||||||
| ^^-----^^^^^
|
| ^^^^^^^^^^^ temporary value does not live long enough
|
||||||
| |
|
...
|
||||||
| inside call to `bar`
|
LL | }
|
||||||
|
| - temporary value only lives until here
|
||||||
|
|
|
|
||||||
note: lint level defined here
|
= note: borrowed value must be valid for the static lifetime...
|
||||||
--> $DIR/promoted_const_fn_fail_deny_const_err.rs:13:9
|
|
||||||
|
|
|
||||||
LL | #![deny(const_err)]
|
|
||||||
| ^^^^^^^^^
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0597`.
|
||||||
|
@ -2,7 +2,7 @@ error[E0080]: it is undefined behavior to use this value
|
|||||||
--> $DIR/ref_to_int_match.rs:33:1
|
--> $DIR/ref_to_int_match.rs:33:1
|
||||||
|
|
|
|
||||||
LL | const BAR: Int = unsafe { Foo { r: &42 }.f }; //~ ERROR it is undefined behavior to use this value
|
LL | const BAR: Int = unsafe { Foo { r: &42 }.f }; //~ ERROR it is undefined behavior to use this value
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected the type u64
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected initialized plain bits
|
||||||
|
|
|
|
||||||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
|
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
|
||||||
|
|
||||||
|
@ -13,6 +13,6 @@
|
|||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
static FOO: bool = unsafe { mem::transmute(3u8) };
|
static FOO: bool = unsafe { mem::transmute(3u8) };
|
||||||
//~^ ERROR this static likely exhibits undefined behavior
|
//~^ ERROR it is undefined behavior to use this value
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
@ -15,11 +15,11 @@ use std::ptr::NonNull;
|
|||||||
use std::num::{NonZeroU8, NonZeroUsize};
|
use std::num::{NonZeroU8, NonZeroUsize};
|
||||||
|
|
||||||
const NULL_PTR: NonNull<u8> = unsafe { mem::transmute(0usize) };
|
const NULL_PTR: NonNull<u8> = unsafe { mem::transmute(0usize) };
|
||||||
//~^ ERROR this constant likely exhibits undefined behavior
|
//~^ ERROR it is undefined behavior to use this value
|
||||||
|
|
||||||
const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) };
|
const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) };
|
||||||
//~^ ERROR this constant likely exhibits undefined behavior
|
//~^ ERROR it is undefined behavior to use this value
|
||||||
const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };
|
const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };
|
||||||
//~^ ERROR this constant likely exhibits undefined behavior
|
//~^ ERROR it is undefined behavior to use this value
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
error[E0080]: this constant likely exhibits undefined behavior
|
error[E0080]: it is undefined behavior to use this value
|
||||||
--> $DIR/ub-nonnull.rs:17:1
|
--> $DIR/ub-nonnull.rs:17:1
|
||||||
|
|
|
|
||||||
LL | const NULL_PTR: NonNull<u8> = unsafe { mem::transmute(0usize) };
|
LL | const NULL_PTR: NonNull<u8> = unsafe { mem::transmute(0usize) };
|
||||||
@ -6,7 +6,7 @@ LL | const NULL_PTR: NonNull<u8> = unsafe { mem::transmute(0usize) };
|
|||||||
|
|
|
|
||||||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
|
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
|
||||||
|
|
||||||
error[E0080]: this constant likely exhibits undefined behavior
|
error[E0080]: it is undefined behavior to use this value
|
||||||
--> $DIR/ub-nonnull.rs:20:1
|
--> $DIR/ub-nonnull.rs:20:1
|
||||||
|
|
|
|
||||||
LL | const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) };
|
LL | const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) };
|
||||||
@ -14,7 +14,7 @@ LL | const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) };
|
|||||||
|
|
|
|
||||||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
|
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
|
||||||
|
|
||||||
error[E0080]: this constant likely exhibits undefined behavior
|
error[E0080]: it is undefined behavior to use this value
|
||||||
--> $DIR/ub-nonnull.rs:22:1
|
--> $DIR/ub-nonnull.rs:22:1
|
||||||
|
|
|
|
||||||
LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };
|
LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };
|
||||||
|
@ -13,18 +13,18 @@
|
|||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) };
|
const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) };
|
||||||
//~^ ERROR this constant likely exhibits undefined behavior
|
//~^ ERROR it is undefined behavior to use this value
|
||||||
|
|
||||||
const NULL: &u16 = unsafe { mem::transmute(0usize) };
|
const NULL: &u16 = unsafe { mem::transmute(0usize) };
|
||||||
//~^ ERROR this constant likely exhibits undefined behavior
|
//~^ ERROR it is undefined behavior to use this value
|
||||||
|
|
||||||
const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) };
|
const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) };
|
||||||
//~^ ERROR this constant likely exhibits undefined behavior
|
//~^ ERROR it is undefined behavior to use this value
|
||||||
|
|
||||||
const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
|
const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
|
||||||
//~^ ERROR this constant likely exhibits undefined behavior
|
//~^ ERROR it is undefined behavior to use this value
|
||||||
|
|
||||||
const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) };
|
const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) };
|
||||||
//~^ ERROR this constant likely exhibits undefined behavior
|
//~^ ERROR it is undefined behavior to use this value
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
error[E0080]: this constant likely exhibits undefined behavior
|
error[E0080]: it is undefined behavior to use this value
|
||||||
--> $DIR/ub-ref.rs:15:1
|
--> $DIR/ub-ref.rs:15:1
|
||||||
|
|
|
|
||||||
LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) };
|
LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) };
|
||||||
@ -6,7 +6,7 @@ LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) };
|
|||||||
|
|
|
|
||||||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
|
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
|
||||||
|
|
||||||
error[E0080]: this constant likely exhibits undefined behavior
|
error[E0080]: it is undefined behavior to use this value
|
||||||
--> $DIR/ub-ref.rs:18:1
|
--> $DIR/ub-ref.rs:18:1
|
||||||
|
|
|
|
||||||
LL | const NULL: &u16 = unsafe { mem::transmute(0usize) };
|
LL | const NULL: &u16 = unsafe { mem::transmute(0usize) };
|
||||||
@ -14,7 +14,7 @@ LL | const NULL: &u16 = unsafe { mem::transmute(0usize) };
|
|||||||
|
|
|
|
||||||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
|
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
|
||||||
|
|
||||||
error[E0080]: this constant likely exhibits undefined behavior
|
error[E0080]: it is undefined behavior to use this value
|
||||||
--> $DIR/ub-ref.rs:21:1
|
--> $DIR/ub-ref.rs:21:1
|
||||||
|
|
|
|
||||||
LL | const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) };
|
LL | const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) };
|
||||||
@ -22,7 +22,7 @@ LL | const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) };
|
|||||||
|
|
|
|
||||||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
|
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
|
||||||
|
|
||||||
error[E0080]: this constant likely exhibits undefined behavior
|
error[E0080]: it is undefined behavior to use this value
|
||||||
--> $DIR/ub-ref.rs:24:1
|
--> $DIR/ub-ref.rs:24:1
|
||||||
|
|
|
|
||||||
LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
|
LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
|
||||||
@ -30,7 +30,7 @@ LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
|
|||||||
|
|
|
|
||||||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
|
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
|
||||||
|
|
||||||
error[E0080]: this constant likely exhibits undefined behavior
|
error[E0080]: it is undefined behavior to use this value
|
||||||
--> $DIR/ub-ref.rs:27:1
|
--> $DIR/ub-ref.rs:27:1
|
||||||
|
|
|
|
||||||
LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) };
|
LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) };
|
||||||
|
@ -16,13 +16,13 @@ use std::mem;
|
|||||||
enum Bar {}
|
enum Bar {}
|
||||||
|
|
||||||
const BAD_BAD_BAD: Bar = unsafe { mem::transmute(()) };
|
const BAD_BAD_BAD: Bar = unsafe { mem::transmute(()) };
|
||||||
//~^ ERROR this constant likely exhibits undefined behavior
|
//~^ ERROR it is undefined behavior to use this value
|
||||||
|
|
||||||
const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) };
|
const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) };
|
||||||
//~^ ERROR this constant likely exhibits undefined behavior
|
//~^ ERROR it is undefined behavior to use this value
|
||||||
|
|
||||||
const BAD_BAD_ARRAY: [Bar; 1] = unsafe { mem::transmute(()) };
|
const BAD_BAD_ARRAY: [Bar; 1] = unsafe { mem::transmute(()) };
|
||||||
//~^ ERROR this constant likely exhibits undefined behavior
|
//~^ ERROR it is undefined behavior to use this value
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
error[E0080]: this constant likely exhibits undefined behavior
|
error[E0080]: it is undefined behavior to use this value
|
||||||
--> $DIR/ub-uninhabit.rs:18:1
|
--> $DIR/ub-uninhabit.rs:18:1
|
||||||
|
|
|
|
||||||
LL | const BAD_BAD_BAD: Bar = unsafe { mem::transmute(()) };
|
LL | const BAD_BAD_BAD: Bar = unsafe { mem::transmute(()) };
|
||||||
@ -6,7 +6,7 @@ LL | const BAD_BAD_BAD: Bar = unsafe { mem::transmute(()) };
|
|||||||
|
|
|
|
||||||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
|
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
|
||||||
|
|
||||||
error[E0080]: this constant likely exhibits undefined behavior
|
error[E0080]: it is undefined behavior to use this value
|
||||||
--> $DIR/ub-uninhabit.rs:21:1
|
--> $DIR/ub-uninhabit.rs:21:1
|
||||||
|
|
|
|
||||||
LL | const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) };
|
LL | const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) };
|
||||||
@ -14,7 +14,7 @@ LL | const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) };
|
|||||||
|
|
|
|
||||||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
|
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
|
||||||
|
|
||||||
error[E0080]: this constant likely exhibits undefined behavior
|
error[E0080]: it is undefined behavior to use this value
|
||||||
--> $DIR/ub-uninhabit.rs:24:1
|
--> $DIR/ub-uninhabit.rs:24:1
|
||||||
|
|
|
|
||||||
LL | const BAD_BAD_ARRAY: [Bar; 1] = unsafe { mem::transmute(()) };
|
LL | const BAD_BAD_ARRAY: [Bar; 1] = unsafe { mem::transmute(()) };
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
const BAD_UPVAR: &FnOnce() = &{ //~ ERROR this constant likely exhibits undefined behavior
|
const BAD_UPVAR: &FnOnce() = &{ //~ ERROR it is undefined behavior to use this value
|
||||||
let bad_ref: &'static u16 = unsafe { mem::transmute(0usize) };
|
let bad_ref: &'static u16 = unsafe { mem::transmute(0usize) };
|
||||||
let another_var = 13;
|
let another_var = 13;
|
||||||
move || { let _ = bad_ref; let _ = another_var; }
|
move || { let _ = bad_ref; let _ = another_var; }
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
error[E0080]: this constant likely exhibits undefined behavior
|
error[E0080]: it is undefined behavior to use this value
|
||||||
--> $DIR/ub-upvars.rs:15:1
|
--> $DIR/ub-upvars.rs:15:1
|
||||||
|
|
|
|
||||||
LL | / const BAD_UPVAR: &FnOnce() = &{ //~ ERROR this constant likely exhibits undefined behavior
|
LL | / const BAD_UPVAR: &FnOnce() = &{ //~ ERROR it is undefined behavior to use this value
|
||||||
LL | | let bad_ref: &'static u16 = unsafe { mem::transmute(0usize) };
|
LL | | let bad_ref: &'static u16 = unsafe { mem::transmute(0usize) };
|
||||||
LL | | let another_var = 13;
|
LL | | let another_var = 13;
|
||||||
LL | | move || { let _ = bad_ref; let _ = another_var; }
|
LL | | move || { let _ = bad_ref; let _ = another_var; }
|
||||||
|
@ -22,7 +22,7 @@ const UNION: DummyUnion = DummyUnion { field1: 1065353216 };
|
|||||||
|
|
||||||
const FIELD3: Field3 = unsafe { UNION.field3 }; //~ ERROR will cause an error
|
const FIELD3: Field3 = unsafe { UNION.field3 }; //~ ERROR will cause an error
|
||||||
|
|
||||||
const FIELD_PATH: Struct = Struct { //~ ERROR any use of this value will cause an error
|
const FIELD_PATH: Struct = Struct { //~ ERROR it is undefined behavior to use this value
|
||||||
a: 42,
|
a: 42,
|
||||||
b: unsafe { UNION.field3 },
|
b: unsafe { UNION.field3 },
|
||||||
};
|
};
|
||||||
|
@ -6,10 +6,10 @@ LL | const FIELD3: Field3 = unsafe { UNION.field3 }; //~ ERROR will cause an err
|
|||||||
|
|
|
|
||||||
= note: #[deny(const_err)] on by default
|
= note: #[deny(const_err)] on by default
|
||||||
|
|
||||||
error: any use of this value will cause an error
|
error[E0080]: it is undefined behavior to use this value
|
||||||
--> $DIR/union-ice.rs:25:1
|
--> $DIR/union-ice.rs:25:1
|
||||||
|
|
|
|
||||||
LL | / const FIELD_PATH: Struct = Struct { //~ ERROR any use of this value will cause an error
|
LL | / const FIELD_PATH: Struct = Struct { //~ ERROR it is undefined behavior to use this value
|
||||||
LL | | a: 42,
|
LL | | a: 42,
|
||||||
LL | | b: unsafe { UNION.field3 },
|
LL | | b: unsafe { UNION.field3 },
|
||||||
LL | | };
|
LL | | };
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
error[E0658]: let bindings in constant functions are unstable (see issue #48821)
|
|
||||||
--> $DIR/const-fn-error.rs:16:19
|
|
||||||
|
|
|
||||||
LL | let mut sum = 0;
|
|
||||||
| ^
|
|
||||||
|
|
|
||||||
= help: add #![feature(const_let)] to the crate attributes to enable
|
|
||||||
|
|
||||||
error[E0658]: statements in constant functions are unstable (see issue #48821)
|
|
||||||
--> $DIR/const-fn-error.rs:16:19
|
|
||||||
|
|
|
||||||
LL | let mut sum = 0;
|
|
||||||
| ^
|
|
||||||
|
|
|
||||||
= help: add #![feature(const_let)] to the crate attributes to enable
|
|
||||||
|
|
||||||
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
|
||||||
--> $DIR/const-fn-error.rs:19:14
|
|
||||||
|
|
|
||||||
LL | for i in 0..x { //~ ERROR E0080
|
|
||||||
| ^^^^
|
|
||||||
|
|
||||||
error[E0019]: constant function contains unimplemented expression type
|
|
||||||
--> $DIR/const-fn-error.rs:19:14
|
|
||||||
|
|
|
||||||
LL | for i in 0..x { //~ ERROR E0080
|
|
||||||
| ^^^^
|
|
||||||
|
|
||||||
error[E0080]: evaluation of constant value failed
|
|
||||||
--> $DIR/const-fn-error.rs:19:14
|
|
||||||
|
|
|
||||||
LL | for i in 0..x { //~ ERROR E0080
|
|
||||||
| ^^^^ calling non-const fn `<I as std::iter::IntoIterator><std::ops::Range<usize>>::into_iter`
|
|
||||||
...
|
|
||||||
LL | let a : [i32; f(X)];
|
|
||||||
| ---- inside call to `f`
|
|
||||||
|
|
||||||
error: aborting due to 5 previous errors
|
|
||||||
|
|
||||||
Some errors occurred: E0015, E0019, E0080, E0658.
|
|
||||||
For more information about an error, try `rustc --explain E0015`.
|
|
@ -1,5 +1,5 @@
|
|||||||
error[E0080]: evaluation of constant value failed
|
error[E0080]: evaluation of constant value failed
|
||||||
--> $DIR/infinite-recursion-const-fn.rs:14:25
|
--> $DIR/infinite-recursion-const-fn.rs:13:25
|
||||||
|
|
|
|
||||||
LL | const fn a() -> usize { b() } //~ ERROR evaluation of constant value failed
|
LL | const fn a() -> usize { b() } //~ ERROR evaluation of constant value failed
|
||||||
| ^^^
|
| ^^^
|
||||||
|
@ -4,24 +4,12 @@ error[E0015]: calls in constants are limited to constant functions, tuple struct
|
|||||||
LL | let array: [usize; Dim3::dim()]
|
LL | let array: [usize; Dim3::dim()]
|
||||||
| ^^^^^^^^^^^
|
| ^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0080]: evaluation of constant value failed
|
|
||||||
--> $DIR/issue-39559-2.rs:24:24
|
|
||||||
|
|
|
||||||
LL | let array: [usize; Dim3::dim()]
|
|
||||||
| ^^^^^^^^^^^ calling non-const fn `<Dim3 as Dim>::dim`
|
|
||||||
|
|
||||||
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
|
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
|
||||||
--> $DIR/issue-39559-2.rs:26:15
|
--> $DIR/issue-39559-2.rs:26:15
|
||||||
|
|
|
|
||||||
LL | = [0; Dim3::dim()];
|
LL | = [0; Dim3::dim()];
|
||||||
| ^^^^^^^^^^^
|
| ^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0080]: evaluation of constant value failed
|
error: aborting due to 2 previous errors
|
||||||
--> $DIR/issue-39559-2.rs:27:15
|
|
||||||
|
|
|
||||||
LL | = [0; Dim3::dim()];
|
|
||||||
| ^^^^^^^^^^^ calling non-const fn `<Dim3 as Dim>::dim`
|
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0015`.
|
For more information about this error, try `rustc --explain E0015`.
|
||||||
|
@ -12,11 +12,10 @@ fn xyz() -> u8 { 42 }
|
|||||||
|
|
||||||
const NUM: u8 = xyz();
|
const NUM: u8 = xyz();
|
||||||
//~^ ERROR calls in constants are limited to constant functions, tuple structs and tuple variants
|
//~^ ERROR calls in constants are limited to constant functions, tuple structs and tuple variants
|
||||||
//~| ERROR any use of this value will cause an error
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
match 1 {
|
match 1 {
|
||||||
NUM => unimplemented!(), //~ ERROR could not evaluate constant pattern
|
NUM => unimplemented!(),
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,22 +4,6 @@ error[E0015]: calls in constants are limited to constant functions, tuple struct
|
|||||||
LL | const NUM: u8 = xyz();
|
LL | const NUM: u8 = xyz();
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
|
|
||||||
error: any use of this value will cause an error
|
error: aborting due to previous error
|
||||||
--> $DIR/issue-43105.rs:13:1
|
|
||||||
|
|
|
||||||
LL | const NUM: u8 = xyz();
|
|
||||||
| ^^^^^^^^^^^^^^^^-----^
|
|
||||||
| |
|
|
||||||
| calling non-const fn `xyz`
|
|
||||||
|
|
|
||||||
= note: #[deny(const_err)] on by default
|
|
||||||
|
|
||||||
error: could not evaluate constant pattern
|
|
||||||
--> $DIR/issue-43105.rs:19:9
|
|
||||||
|
|
|
||||||
LL | NUM => unimplemented!(), //~ ERROR could not evaluate constant pattern
|
|
||||||
| ^^^
|
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0015`.
|
For more information about this error, try `rustc --explain E0015`.
|
||||||
|
@ -10,7 +10,7 @@ error[E0080]: it is undefined behavior to use this value
|
|||||||
--> $DIR/issue-52023-array-size-pointer-cast.rs:12:17
|
--> $DIR/issue-52023-array-size-pointer-cast.rs:12:17
|
||||||
|
|
|
|
||||||
LL | let _ = [0; (&0 as *const i32) as usize]; //~ ERROR casting pointers to integers in constants
|
LL | let _ = [0; (&0 as *const i32) as usize]; //~ ERROR casting pointers to integers in constants
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected the type usize
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected initialized plain bits
|
||||||
|
|
|
|
||||||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
|
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user