Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

non_exhaustive peripheral #894

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ jobs:
- { rust: stable, vendor: Spansion, options: "--atomics" }
- { rust: stable, vendor: STMicro, options: "" }
- { rust: stable, vendor: STMicro, options: "--atomics" }
- { rust: stable, vendor: STM32-patched, options: "--strict -f enum_value::p: --max-cluster-size --atomics --atomics-feature atomics --impl-debug --impl-defmt defmt" }
- {
rust: stable,
vendor: STM32-patched,
options: "--strict -f enum_value::p: --max-cluster-size --atomics --atomics-feature atomics --impl-debug --impl-defmt defmt",
}
- { rust: stable, vendor: Toshiba, options: all }
- { rust: stable, vendor: Toshiba, options: "" }
# Test MSRV
Expand All @@ -92,8 +96,16 @@ jobs:
- { rust: nightly, vendor: MSP430, options: "--atomics" }
- { rust: nightly, vendor: MSP430, options: "" }
# Workaround for _1token0
- { rust: nightly-2024-09-25, vendor: Espressif, options: "--atomics --ident-formats-theme legacy" }
- { rust: nightly-2024-09-25, vendor: Espressif, options: "--ident-format register:::Reg" }
- {
rust: nightly-2024-09-25,
vendor: Espressif,
options: "--atomics --ident-formats-theme legacy",
}
- {
rust: nightly-2024-09-25,
vendor: Espressif,
options: "--ident-format register:::Reg",
}

steps:
- uses: actions/checkout@v4
Expand All @@ -107,7 +119,7 @@ jobs:

- name: Self install
run: |
cargo install svd2rust --path .
cargo install svd2rust --path . --force

- name: Run CI script for `${{ matrix.vendor }}` under rust `${{ matrix.rust }}` with options=`${{ matrix.options }}`
env:
Expand All @@ -132,7 +144,7 @@ jobs:

- name: Self install
run: |
cargo install svd2rust --path .
cargo install svd2rust --path . --force

- name: Run CI script
env:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).

## [Unreleased]

- Mark peripheral with `non_exhaustive`
- Force using rust edition 2021 in CI

## [v0.35.0] - 2024-11-12
Expand Down
5 changes: 2 additions & 3 deletions src/generate/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke

out.extend(quote! {
use core::ops::Deref;
use core::marker::PhantomData;
});

// Retaining the previous assumption
Expand Down Expand Up @@ -273,7 +272,7 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
#feature_attribute
pub #p_singleton: #p_ty,
});
exprs.extend(quote!(#feature_attribute #p_singleton: #p_ty::steal(),));
exprs.extend(quote!(#feature_attribute #p_singleton: #p_ty,));
}
Peripheral::Array(p, dim_element) => {
for p_name in names(p, dim_element) {
Expand All @@ -288,7 +287,7 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
#feature_attribute
pub #p_singleton: #p_ty,
});
exprs.extend(quote!(#feature_attribute #p_singleton: #p_ty::steal(),));
exprs.extend(quote!(#feature_attribute #p_singleton: #p_ty,));
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/generate/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
/// peripheral instance existing to ensure memory safety; ensure
/// no stolen instances are passed to such software.
pub unsafe fn steal() -> Self {
Self { _marker: PhantomData }
Self
}
};

Expand All @@ -97,7 +97,8 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
#phtml
#doc_alias
#feature_attribute
pub struct #p_ty { _marker: PhantomData<*const ()> }
#[non_exhaustive]
pub struct #p_ty;

#feature_attribute
unsafe impl Send for #p_ty {}
Expand Down
Loading