Skip to content

Commit d272ee6

Browse files
committed
refactor: Add reorganize_assoc_item snapshot test
1 parent 80bb8c3 commit d272ee6

3 files changed

Lines changed: 131 additions & 0 deletions

File tree

c2rust-refactor/tests/snapshots.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,14 @@ fn test_reorganize_definitions() {
445445
.test();
446446
}
447447

448+
#[test]
449+
fn test_reorganize_assoc_items() {
450+
refactor("reorganize_definitions")
451+
.named("reorganize_assoc_items.rs")
452+
.new_expect_compile_error(true)
453+
.test();
454+
}
455+
448456
#[test]
449457
fn test_reorganize_foreign_types() {
450458
refactor("reorganize_definitions")
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#![feature(extern_types)]
2+
#![feature(rustc_private)]
3+
#![feature(register_tool)]
4+
#![register_tool(c2rust)]
5+
#![allow(non_upper_case_globals)]
6+
#![allow(non_camel_case_types)]
7+
#![allow(non_snake_case)]
8+
#![allow(dead_code)]
9+
#![allow(mutable_transmutes)]
10+
#![allow(unused_mut)]
11+
12+
pub mod bar {
13+
#[c2rust::header_src = "/home/user/some/workspace/foobar/bar.h:5"]
14+
pub mod bar_h {
15+
#[derive(Clone, Copy)]
16+
#[repr(transparent)]
17+
#[c2rust::src_loc = "14:0"]
18+
pub struct C2Rust_Unnamed_2(pub ::core::ffi::c_uint);
19+
20+
#[c2rust::src_loc = "14:0"]
21+
impl C2Rust_Unnamed_2 {
22+
#[c2rust::src_loc = "15:0"]
23+
pub const U: Self = Self(42);
24+
}
25+
26+
#[derive(Clone, Copy)]
27+
#[repr(transparent)]
28+
#[c2rust::src_loc = "11:0"]
29+
pub struct SomeEnum(pub ::core::ffi::c_uint);
30+
31+
#[c2rust::src_loc = "11:0"]
32+
impl SomeEnum {
33+
#[c2rust::src_loc = "12:0"]
34+
pub const A: Self = Self(0);
35+
#[c2rust::src_loc = "13:0"]
36+
pub const B: Self = Self(1);
37+
}
38+
}
39+
}
40+
41+
pub mod foo {
42+
#[c2rust::header_src = "/home/user/some/workspace/foobar/bar.h:5"]
43+
pub mod bar_h {
44+
#[derive(Clone, Copy)]
45+
#[repr(transparent)]
46+
#[c2rust::src_loc = "4:0"]
47+
pub struct C2Rust_Unnamed_3(pub ::core::ffi::c_uint);
48+
49+
#[c2rust::src_loc = "4:0"]
50+
impl C2Rust_Unnamed_3 {
51+
#[c2rust::src_loc = "5:0"]
52+
pub const V: Self = Self(42);
53+
}
54+
55+
#[derive(Clone, Copy)]
56+
#[repr(transparent)]
57+
#[c2rust::src_loc = "1:0"]
58+
pub struct SomeEnum(pub ::core::ffi::c_uint);
59+
60+
#[c2rust::src_loc = "1:0"]
61+
impl SomeEnum {
62+
#[c2rust::src_loc = "2:0"]
63+
pub const A: Self = Self(0);
64+
#[c2rust::src_loc = "3:0"]
65+
pub const B: Self = Self(1);
66+
}
67+
}
68+
69+
unsafe fn foo() {
70+
let e1 = super::foo::bar_h::SomeEnum::A;
71+
let e2 = super::bar::bar_h::SomeEnum::B;
72+
let e3 = super::bar::bar_h::C2Rust_Unnamed_2::U;
73+
let e4 = super::foo::bar_h::C2Rust_Unnamed_3::V;
74+
}
75+
}
76+
77+
fn main() {
78+
println!("hello!");
79+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
source: c2rust-refactor/tests/snapshots.rs
3+
expression: c2rust-refactor reorganize_definitions --rewrite-mode alongside -- tests/snapshots/reorganize_assoc_items.rs --edition 2021
4+
---
5+
#![feature(extern_types)]
6+
#![feature(rustc_private)]
7+
#![feature(register_tool)]
8+
#![register_tool(c2rust)]
9+
#![allow(non_upper_case_globals)]
10+
#![allow(non_camel_case_types)]
11+
#![allow(non_snake_case)]
12+
#![allow(dead_code)]
13+
#![allow(mutable_transmutes)]
14+
#![allow(unused_mut)]
15+
16+
pub mod bar_h {
17+
#[derive(Clone, Copy)]
18+
#[repr(transparent)]
19+
pub struct C2Rust_Unnamed_3(pub ::core::ffi::c_uint);
20+
21+
#[derive(Clone, Copy)]
22+
#[repr(transparent)]
23+
24+
pub struct SomeEnum(pub ::core::ffi::c_uint);
25+
26+
#[derive(Clone, Copy)]
27+
#[repr(transparent)]
28+
29+
pub struct C2Rust_Unnamed_2(pub ::core::ffi::c_uint);
30+
}
31+
32+
pub mod foo {
33+
34+
unsafe fn foo() {
35+
let e1 = crate::bar_h::SomeEnum::A;
36+
let e2 = crate::bar_h::SomeEnum::B;
37+
let e3 = crate::bar_h::C2Rust_Unnamed_2::U;
38+
let e4 = crate::bar_h::C2Rust_Unnamed_3::V;
39+
}
40+
}
41+
42+
fn main() {
43+
println!("hello!");
44+
}

0 commit comments

Comments
 (0)