Skip to content

Commit 2a8ab3f

Browse files
refactor: fully-remove cfg-ignored items (#53)
Other refactors: * Fix name `GenFinalPubVistor` -> `GenFinalPubVisitor` * Unify handling of `#[cfg(stageleft_runtime)]` attribute * Unify handling of `pub` re-exports
1 parent 10f0b4a commit 2a8ab3f

File tree

7 files changed

+184
-170
lines changed

7 files changed

+184
-170
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

stageleft_test_no_entry/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ slotmap = "1.0.0"
1616

1717
[build-dependencies]
1818
stageleft_tool = { path = "../stageleft_tool", version = "^0.12.0" }
19+
20+
[dev-dependencies]
21+
insta = "1.39"

stageleft_test_no_entry/src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,14 @@ fn splitbrain(st: SplitbrainStruct) {
1616
pub struct SplitbrainStruct {
1717
/// This stays as regular `MyKey` (equiv. to `crate::MyKey`).
1818
my_key: MyKey,
19-
}
19+
}
20+
21+
#[cfg(stageleft_runtime)]
22+
#[expect(dead_code)]
23+
struct ThisShouldBeRemoved;
24+
25+
pub mod pub_mod {
26+
#[cfg(stageleft_runtime)]
27+
#[expect(dead_code)]
28+
struct ThisShouldAlsoBeRemoved;
29+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#[test]
2+
fn test_lib_pub() {
3+
insta::assert_snapshot!(include_str!(concat!(
4+
env!("OUT_DIR"),
5+
stageleft::PATH_SEPARATOR!(),
6+
"lib_pub.rs"
7+
)));
8+
}
9+
10+
#[test]
11+
fn test_staged_deps() {
12+
insta::assert_snapshot!(include_str!(concat!(
13+
env!("OUT_DIR"),
14+
stageleft::PATH_SEPARATOR!(),
15+
"staged_deps.rs"
16+
)));
17+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
source: stageleft_test_no_entry/tests/codegen_snapshot.rs
3+
expression: "include_str!(concat!(env!(\"OUT_DIR\"), stageleft::PATH_SEPARATOR!(),\n\"lib_pub.rs\"))"
4+
---
5+
pub use crate::MyKey;
6+
/// Test that `stageleft::export` prevents splitbrain of `MyKey` type.
7+
#[allow(dead_code)]
8+
pub fn splitbrain(st: SplitbrainStruct) {
9+
let _key: MyKey = st.my_key;
10+
}
11+
pub use crate::SplitbrainStruct;
12+
13+
pub mod pub_mod {
14+
15+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
source: stageleft_test_no_entry/tests/codegen_snapshot.rs
3+
assertion_line: 12
4+
expression: "include_str!(concat!(env!(\"OUT_DIR\"), stageleft::PATH_SEPARATOR!(),\n\"staged_deps.rs\"))"
5+
---
6+
pub mod __deps {
7+
pub use stageleft;
8+
pub use slotmap;
9+
#[stageleft::internal::ctor::ctor(crate_path = stageleft::internal::ctor)]
10+
fn __init() {
11+
stageleft::internal::add_deps_reexport(
12+
vec!["stageleft"],
13+
vec![
14+
option_env!("STAGELEFT_FINAL_CRATE_NAME")
15+
.unwrap_or(env!("CARGO_PKG_NAME"))
16+
.replace("-", "_"),
17+
"__staged".to_string(),
18+
"__deps".to_string(),
19+
"stageleft".to_string(),
20+
],
21+
);
22+
stageleft::internal::add_deps_reexport(
23+
vec!["slotmap"],
24+
vec![
25+
option_env!("STAGELEFT_FINAL_CRATE_NAME")
26+
.unwrap_or(env!("CARGO_PKG_NAME"))
27+
.replace("-", "_"),
28+
"__staged".to_string(),
29+
"__deps".to_string(),
30+
"slotmap".to_string(),
31+
],
32+
);
33+
stageleft::internal::add_crate_with_staged(
34+
env!("CARGO_PKG_NAME").replace("-", "_"),
35+
);
36+
}
37+
}

0 commit comments

Comments
 (0)