Skip to content

Commit c768d6e

Browse files
authored
Rollup merge of #126577 - oli-obk:static_valtrees, r=RalfJung
const_refs_to_static test and cleanup r? ``@RalfJung`` test the existing behaviour of adt_const_params combined with const_refs_to_static. also remove a dead error variant about consts referring to statics
2 parents ba26af3 + 4e5dfb6 commit c768d6e

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

Diff for: compiler/rustc_const_eval/messages.ftl

-2
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,6 @@ const_eval_unwind_past_top =
399399
400400
## The `front_matter`s here refer to either `const_eval_front_matter_invalid_value` or `const_eval_front_matter_invalid_value_with_path`.
401401
## (We'd love to sort this differently to make that more clear but tidy won't let us...)
402-
const_eval_validation_box_to_static = {$front_matter}: encountered a box pointing to a static variable in a constant
403402
const_eval_validation_box_to_uninhabited = {$front_matter}: encountered a box pointing to uninhabited type {$ty}
404403
405404
const_eval_validation_const_ref_to_extern = {$front_matter}: encountered reference to `extern` static in `const`
@@ -454,7 +453,6 @@ const_eval_validation_out_of_range = {$front_matter}: encountered {$value}, but
454453
const_eval_validation_partial_pointer = {$front_matter}: encountered a partial pointer or a mix of pointers
455454
const_eval_validation_pointer_as_int = {$front_matter}: encountered a pointer, but {$expected}
456455
const_eval_validation_ptr_out_of_range = {$front_matter}: encountered a pointer, but expected something that cannot possibly fail to be {$in_range}
457-
const_eval_validation_ref_to_static = {$front_matter}: encountered a reference pointing to a static variable in a constant
458456
const_eval_validation_ref_to_uninhabited = {$front_matter}: encountered a reference pointing to uninhabited type {$ty}
459457
const_eval_validation_unaligned_box = {$front_matter}: encountered an unaligned box (required {$required_bytes} byte alignment but found {$found_bytes})
460458
const_eval_validation_unaligned_ref = {$front_matter}: encountered an unaligned reference (required {$required_bytes} byte alignment but found {$found_bytes})

Diff for: compiler/rustc_const_eval/src/errors.rs

-4
Original file line numberDiff line numberDiff line change
@@ -640,9 +640,6 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
640640
const_eval_validation_ref_to_uninhabited
641641
}
642642

643-
PtrToStatic { ptr_kind: PointerKind::Box } => const_eval_validation_box_to_static,
644-
PtrToStatic { ptr_kind: PointerKind::Ref(_) } => const_eval_validation_ref_to_static,
645-
646643
PointerAsInt { .. } => const_eval_validation_pointer_as_int,
647644
PartialPointer => const_eval_validation_partial_pointer,
648645
ConstRefToMutable => const_eval_validation_const_ref_to_mutable,
@@ -807,7 +804,6 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
807804
);
808805
}
809806
NullPtr { .. }
810-
| PtrToStatic { .. }
811807
| ConstRefToMutable
812808
| ConstRefToExtern
813809
| MutableRefToImmutable

Diff for: compiler/rustc_middle/src/mir/interpret/error.rs

-3
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,6 @@ pub enum ValidationErrorKind<'tcx> {
438438
ptr_kind: PointerKind,
439439
ty: Ty<'tcx>,
440440
},
441-
PtrToStatic {
442-
ptr_kind: PointerKind,
443-
},
444441
ConstRefToMutable,
445442
ConstRefToExtern,
446443
MutableRefToImmutable,

Diff for: tests/ui/statics/const_generics.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//! Check that we lose the information that `BAR` points to `FOO`
2+
//! when going through a const generic.
3+
//! This is not an intentional guarantee, it just describes the status quo.
4+
5+
//@ run-pass
6+
// With optimizations, LLVM will deduplicate the constant `X` whose
7+
// value is `&42` to just be a reference to the static. This is correct,
8+
// but obscures the issue we're trying to show.
9+
//@ revisions: opt noopt
10+
//@[noopt] compile-flags: -Copt-level=0
11+
//@[opt] compile-flags: -O
12+
13+
#![feature(const_refs_to_static)]
14+
#![feature(adt_const_params)]
15+
#![allow(incomplete_features)]
16+
17+
static FOO: usize = 42;
18+
const BAR: &usize = &FOO;
19+
fn foo<const X: &'static usize>() {
20+
// Without optimizations, `X` ends up pointing to a copy of `FOO` instead of `FOO` itself.
21+
assert_eq!(cfg!(opt), std::ptr::eq(X, &FOO));
22+
}
23+
24+
fn main() {
25+
foo::<BAR>();
26+
}

0 commit comments

Comments
 (0)