File tree 2 files changed +25
-1
lines changed 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
31
31
- Bumped ` xtensa-lx ` and add ` xtensa_lx::interrupt::InterruptNumber ` implementation.
32
32
- Don't use a mask when the width of the mask is the same as the width of the parent register.
33
33
- Improved error handling
34
+ - Registers with single fields that span the entire register now generate safe ` bits ` writers.
34
35
35
36
## [ v0.19.0] - 2021-05-26
36
37
Original file line number Diff line number Diff line change @@ -168,10 +168,33 @@ pub fn render(
168
168
169
169
mod_items. extend ( w_impl_items) ;
170
170
171
+ // the writer can be safe if:
172
+ // * there is a single field that covers the entire register
173
+ // * that field can represent all values
174
+ let unsafefn: Option < Ident > = register
175
+ . fields
176
+ . as_ref ( )
177
+ . map ( |fields| fields. iter ( ) . next ( ) )
178
+ . flatten ( )
179
+ . map ( |field| field. write_constraint )
180
+ . flatten ( )
181
+ . map ( |constraint| match constraint {
182
+ WriteConstraint :: Range ( range) => {
183
+ if range. min == 0 && range. max == 2_u64 . pow ( rsize) - 1 {
184
+ None
185
+ } else {
186
+ Some ( ( ) )
187
+ }
188
+ }
189
+ _ => Some ( ( ) ) ,
190
+ } )
191
+ . flatten ( )
192
+ . map ( |_| Ident :: new ( "unsafe" , span) ) ;
193
+
171
194
mod_items. extend ( quote ! {
172
195
#[ doc = "Writes raw bits to the register." ]
173
196
#[ inline( always) ]
174
- pub unsafe fn bits( & mut self , bits: #rty) -> & mut Self {
197
+ pub #unsafefn fn bits( & mut self , bits: #rty) -> & mut Self {
175
198
self . 0 . bits( bits) ;
176
199
self
177
200
}
You can’t perform that action at this time.
0 commit comments