diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2024-02-26 18:03:06 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2024-03-12 05:53:46 +0000 |
| commit | d3514a036dc65c1d31ee5b1b4bd58b9be1edf5af (patch) | |
| tree | 95685bb9f89cc23836f86c958b346447e8fd5356 /tests | |
| parent | 92414ab25d5b9ddbee37d458e53e70ee4813d5ca (diff) | |
| download | rust-d3514a036dc65c1d31ee5b1b4bd58b9be1edf5af.tar.gz rust-d3514a036dc65c1d31ee5b1b4bd58b9be1edf5af.zip | |
Ensure nested allocations in statics do not get deduplicated
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/consts/const-mut-refs-crate.rs | 12 | ||||
| -rw-r--r-- | tests/ui/statics/nested_struct.rs | 24 |
2 files changed, 31 insertions, 5 deletions
diff --git a/tests/ui/consts/const-mut-refs-crate.rs b/tests/ui/consts/const-mut-refs-crate.rs index 96df2cefce2..dcc8ff370e1 100644 --- a/tests/ui/consts/const-mut-refs-crate.rs +++ b/tests/ui/consts/const-mut-refs-crate.rs @@ -4,8 +4,8 @@ #![feature(const_mut_refs)] //! Regression test for https://github.com/rust-lang/rust/issues/79738 -//! Show how we are duplicationg allocations, even though static items that -//! copy their value from another static should not also be duplicating +//! Show how we are not duplicating allocations anymore. Statics that +//! copy their value from another static used to also duplicate //! memory behind references. extern crate const_mut_refs_crate as other; @@ -21,15 +21,17 @@ pub static mut COPY_OF_REMOTE_FOO: &'static mut i32 = unsafe { FOO }; static DOUBLE_REF: &&i32 = &&99; static ONE_STEP_ABOVE: &i32 = *DOUBLE_REF; +static mut DOUBLE_REF_MUT: &mut &mut i32 = &mut &mut 99; +static mut ONE_STEP_ABOVE_MUT: &mut i32 = unsafe { *DOUBLE_REF_MUT }; pub fn main() { unsafe { - assert_ne!(FOO as *const i32, BAR as *const i32); + assert_eq!(FOO as *const i32, BAR as *const i32); assert_eq!(INNER_MOD_FOO as *const i32, INNER_MOD_BAR as *const i32); assert_eq!(LOCAL_FOO as *const i32, LOCAL_BAR as *const i32); assert_eq!(*DOUBLE_REF as *const i32, ONE_STEP_ABOVE as *const i32); + assert_eq!(*DOUBLE_REF_MUT as *mut i32, ONE_STEP_ABOVE_MUT as *mut i32); - // bug! - assert_ne!(FOO as *const i32, COPY_OF_REMOTE_FOO as *const i32); + assert_eq!(FOO as *const i32, COPY_OF_REMOTE_FOO as *const i32); } } diff --git a/tests/ui/statics/nested_struct.rs b/tests/ui/statics/nested_struct.rs new file mode 100644 index 00000000000..f5819f50789 --- /dev/null +++ b/tests/ui/statics/nested_struct.rs @@ -0,0 +1,24 @@ +//@ check-pass +/// oli-obk added this test after messing up the interner logic +/// around mutability of nested allocations. This was not caught +/// by the test suite, but by trying to build stage2 rustc. +/// There is no real explanation for this test, as it was just +/// a bug during a refactoring. + +pub struct Lint { + pub name: &'static str, + pub desc: &'static str, + pub report_in_external_macro: bool, + pub is_loaded: bool, + pub crate_level_only: bool, +} + +static FOO: &Lint = &Lint { + name: &"foo", + desc: "desc", + report_in_external_macro: false, + is_loaded: true, + crate_level_only: false, +}; + +fn main() {} |
