Skip to content

Commit 1c5ff29

Browse files
committed
Rebase fallout
1 parent d2e682a commit 1c5ff29

31 files changed

+69
-319
lines changed

src/librustc_lint/builtin.rs

-43
Original file line numberDiff line numberDiff line change
@@ -1547,49 +1547,6 @@ impl LintPass for UnusedBrokenConst {
15471547
lint_array!()
15481548
}
15491549
}
1550-
1551-
fn validate_const<'a, 'tcx>(
1552-
tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
1553-
constant: &ty::Const<'tcx>,
1554-
param_env: ty::ParamEnv<'tcx>,
1555-
gid: ::rustc::mir::interpret::GlobalId<'tcx>,
1556-
what: &str,
1557-
) {
1558-
let ecx = ::rustc_mir::const_eval::mk_eval_cx(tcx, gid.instance, param_env).unwrap();
1559-
let result = (|| {
1560-
let op = ecx.const_to_op(constant)?;
1561-
let mut ref_tracking = ::rustc_mir::interpret::RefTracking::new(op);
1562-
while let Some((op, mut path)) = ref_tracking.todo.pop() {
1563-
ecx.validate_operand(
1564-
op,
1565-
&mut path,
1566-
Some(&mut ref_tracking),
1567-
/* const_mode */ true,
1568-
)?;
1569-
}
1570-
Ok(())
1571-
})();
1572-
if let Err(err) = result {
1573-
let (trace, span) = ecx.generate_stacktrace(None);
1574-
let err = ::rustc::mir::interpret::ConstEvalErr {
1575-
error: err,
1576-
stacktrace: trace,
1577-
span,
1578-
};
1579-
let err = err.struct_error(
1580-
tcx.at(span),
1581-
&format!("this {} likely exhibits undefined behavior", what),
1582-
);
1583-
if let Some(mut err) = err {
1584-
err.note("The rules on what exactly is undefined behavior aren't clear, \
1585-
so this check might be overzealous. Please open an issue on the rust compiler \
1586-
repository if you believe it should not be considered undefined behavior",
1587-
);
1588-
err.emit();
1589-
}
1590-
}
1591-
}
1592-
15931550
fn check_const(cx: &LateContext, body_id: hir::BodyId) {
15941551
let def_id = cx.tcx.hir.body_owner_def_id(body_id);
15951552
let is_static = cx.tcx.is_static(def_id).is_some();

src/librustc_mir/const_eval.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use rustc::ty::{self, Ty, TyCtxt, Instance, query::TyCtxtAt};
2424
use rustc::ty::layout::{self, Size, LayoutOf, TyLayout};
2525
use rustc::ty::subst::Subst;
2626
use rustc::traits::Reveal;
27-
use rustc::util::nodemap::FxHashSet;
2827
use rustc_data_structures::indexed_vec::IndexVec;
2928
use rustc_data_structures::fx::FxHashMap;
3029
use rustc::util::common::ErrorReported;
@@ -36,7 +35,7 @@ use interpret::{self,
3635
PlaceTy, MemPlace, OpTy, Operand, Value, Pointer, Scalar, ConstValue,
3736
EvalResult, EvalError, EvalErrorKind, GlobalId, EvalContext, StackPopCleanup,
3837
Allocation, AllocId, MemoryKind,
39-
snapshot,
38+
snapshot, RefTracking,
4039
};
4140

4241
/// Number of steps until the detector even starts doing anything.
@@ -542,15 +541,13 @@ fn validate_const<'a, 'tcx>(
542541
let ecx = mk_eval_cx(tcx, cid.instance, key.param_env).unwrap();
543542
let val = (|| {
544543
let op = ecx.const_to_op(constant)?;
545-
let mut todo = vec![(op, Vec::new())];
546-
let mut seen = FxHashSet();
547-
seen.insert(op);
548-
while let Some((op, mut path)) = todo.pop() {
544+
let mut ref_tracking = RefTracking::new(op);
545+
while let Some((op, mut path)) = ref_tracking.todo.pop() {
549546
ecx.validate_operand(
550547
op,
551548
&mut path,
552-
&mut seen,
553-
&mut todo,
549+
Some(&mut ref_tracking),
550+
/* const_mode */ true,
554551
)?;
555552
}
556553
Ok(constant)

src/test/compile-fail/const-fn-error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const fn f(x: usize) -> usize {
1616
let mut sum = 0;
1717
//~^ let bindings in constant functions are unstable
1818
//~| statements in constant functions are unstable
19-
for i in 0..x { //~ ERROR E0080
19+
for i in 0..x {
2020
//~^ ERROR E0015
2121
//~| ERROR E0019
2222
sum += i;

src/test/compile-fail/issue-52443.rs

-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,4 @@ fn main() {
1414
[(); {while true {break}; 0}]; //~ ERROR constant contains unimplemented expression type
1515
[(); { for _ in 0usize.. {}; 0}]; //~ ERROR calls in constants are limited to constant functions
1616
//~^ ERROR constant contains unimplemented expression type
17-
//~| ERROR evaluation of constant value failed
1817
}

src/test/ui/consts/const-call.stderr

+1-7
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ error[E0015]: calls in constants are limited to constant functions, tuple struct
44
LL | let _ = [0; f(2)];
55
| ^^^^
66

7-
error[E0080]: evaluation of constant value failed
8-
--> $DIR/const-call.rs:16:17
9-
|
10-
LL | let _ = [0; f(2)];
11-
| ^^^^ calling non-const fn `f`
12-
13-
error: aborting due to 2 previous errors
7+
error: aborting due to previous error
148

159
For more information about this error, try `rustc --explain E0015`.

src/test/ui/consts/const-eval/conditional_array_execution.nll.stderr

-29
This file was deleted.

src/test/ui/consts/const-eval/issue-43197.nll.stderr

-43
This file was deleted.

src/test/ui/consts/const-eval/issue-43197.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: any use of this value will cause an error
2-
--> $DIR/issue-43197.rs:20:5
2+
--> $DIR/issue-43197.rs:18:5
33
|
44
LL | const X: u32 = 0-1;
55
| ^^^^^^^^^^^^^^^---^
@@ -13,21 +13,21 @@ LL | #![warn(const_err)]
1313
| ^^^^^^^^^
1414

1515
warning: any use of this value will cause an error
16-
--> $DIR/issue-43197.rs:22:5
16+
--> $DIR/issue-43197.rs:20:5
1717
|
1818
LL | const Y: u32 = foo(0-1);
1919
| ^^^^^^^^^^^^^^^^^^^---^^
2020
| |
2121
| attempt to subtract with overflow
2222

2323
error[E0080]: evaluation of constant expression failed
24-
--> $DIR/issue-43197.rs:24:26
24+
--> $DIR/issue-43197.rs:22:26
2525
|
2626
LL | println!("{} {}", X, Y);
2727
| ^ referenced constant has errors
2828

2929
error[E0080]: evaluation of constant expression failed
30-
--> $DIR/issue-43197.rs:24:23
30+
--> $DIR/issue-43197.rs:22:23
3131
|
3232
LL | println!("{} {}", X, Y);
3333
| ^ referenced constant has errors

src/test/ui/consts/const-eval/issue-44578.nll.stderr

-15
This file was deleted.

src/test/ui/consts/const-eval/issue-52442.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ error[E0080]: it is undefined behavior to use this value
88
--> $DIR/issue-52442.rs:12:11
99
|
1010
LL | [(); { &loop { break } as *const _ as usize } ]; //~ ERROR unimplemented expression type
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected the type usize
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected initialized plain bits
1212
|
1313
= 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
1414

src/test/ui/consts/const-eval/issue-52443.stderr

-49
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0716]: temporary value dropped while borrowed
2+
--> $DIR/promoted_const_fn_fail_deny_const_err.rs:31:27
3+
|
4+
LL | let x: &'static u8 = &(bar() + 1);
5+
| ----------- ^^^^^^^^^^^ creates a temporary which is freed while still in use
6+
| |
7+
| type annotation requires that borrow lasts for `'static`
8+
...
9+
LL | }
10+
| - temporary value is freed at the end of this statement
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0716`.
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1-
error: reaching this expression at runtime will panic or abort
2-
--> $DIR/promoted_const_fn_fail_deny_const_err.rs:31:26
1+
error[E0597]: borrowed value does not live long enough
2+
--> $DIR/promoted_const_fn_fail_deny_const_err.rs:31:27
33
|
4-
LL | Bar { a: &42 }.b as u8
5-
| ---------------------- a raw memory access tried to access part of a pointer value as raw bytes
6-
...
74
LL | let x: &'static u8 = &(bar() + 1);
8-
| ^^-----^^^^^
9-
| |
10-
| inside call to `bar`
11-
|
12-
note: lint level defined here
13-
--> $DIR/promoted_const_fn_fail_deny_const_err.rs:13:9
5+
| ^^^^^^^^^^^ temporary value does not live long enough
6+
...
7+
LL | }
8+
| - temporary value only lives until here
149
|
15-
LL | #![deny(const_err)]
16-
| ^^^^^^^^^
10+
= note: borrowed value must be valid for the static lifetime...
1711

1812
error: aborting due to previous error
1913

14+
For more information about this error, try `rustc --explain E0597`.

src/test/ui/consts/const-eval/ref_to_int_match.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0080]: it is undefined behavior to use this value
22
--> $DIR/ref_to_int_match.rs:33:1
33
|
44
LL | const BAR: Int = unsafe { Foo { r: &42 }.f }; //~ ERROR it is undefined behavior to use this value
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected the type u64
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected initialized plain bits
66
|
77
= 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
88

src/test/ui/consts/const-eval/transmute-const.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
use std::mem;
1414

1515
static FOO: bool = unsafe { mem::transmute(3u8) };
16-
//~^ ERROR this static likely exhibits undefined behavior
16+
//~^ ERROR it is undefined behavior to use this value
1717

1818
fn main() {}

src/test/ui/consts/const-eval/ub-nonnull.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ use std::ptr::NonNull;
1515
use std::num::{NonZeroU8, NonZeroUsize};
1616

1717
const NULL_PTR: NonNull<u8> = unsafe { mem::transmute(0usize) };
18-
//~^ ERROR this constant likely exhibits undefined behavior
18+
//~^ ERROR it is undefined behavior to use this value
1919

2020
const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) };
21-
//~^ ERROR this constant likely exhibits undefined behavior
21+
//~^ ERROR it is undefined behavior to use this value
2222
const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };
23-
//~^ ERROR this constant likely exhibits undefined behavior
23+
//~^ ERROR it is undefined behavior to use this value
2424

2525
fn main() {}

src/test/ui/consts/const-eval/ub-nonnull.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
error[E0080]: this constant likely exhibits undefined behavior
1+
error[E0080]: it is undefined behavior to use this value
22
--> $DIR/ub-nonnull.rs:17:1
33
|
44
LL | const NULL_PTR: NonNull<u8> = unsafe { mem::transmute(0usize) };
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0, but expected something greater or equal to 1
66
|
77
= 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
88

9-
error[E0080]: this constant likely exhibits undefined behavior
9+
error[E0080]: it is undefined behavior to use this value
1010
--> $DIR/ub-nonnull.rs:20:1
1111
|
1212
LL | const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) };
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0, but expected something greater or equal to 1
1414
|
1515
= 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
1616

17-
error[E0080]: this constant likely exhibits undefined behavior
17+
error[E0080]: it is undefined behavior to use this value
1818
--> $DIR/ub-nonnull.rs:22:1
1919
|
2020
LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };

0 commit comments

Comments
 (0)