diff options
author | zzhu <zzhu@mozilla.com> | 2017-05-24 13:53:17 -0700 |
---|---|---|
committer | zzhu <zzhu@mozilla.com> | 2017-05-24 14:05:41 -0700 |
commit | 88342c9371f3384717f407751bde4848075a6aae (patch) | |
tree | 2f4f5f39fff4cad5ae883b5f072b424e6494aac5 /src/codegen/mod.rs | |
parent | 595b9a3861751a3364b0b98b5434527e5981f962 (diff) |
Fix bitfield generation bug with const function
Const function can't have variables or blocks.
Diffstat (limited to 'src/codegen/mod.rs')
-rw-r--r-- | src/codegen/mod.rs | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 2f8ad805..17738426 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1106,19 +1106,16 @@ impl Bitfield { quote_tokens!(ctx.ext_cx(), pub fn) }; + // Don't use variables or blocks because const function does not allow them. quote_item!( ctx.ext_cx(), impl XxxUnused { #[inline] $fn_prefix $ctor_name($params $param_name : $bitfield_ty) -> $unit_field_int_ty { - let bitfield_unit_val = $body; - let $param_name = $param_name - as $bitfield_int_ty - as $unit_field_int_ty; - let mask = $mask as $unit_field_int_ty; - let $param_name = ($param_name << $offset) & mask; - bitfield_unit_val | $param_name + ($body | + (($param_name as $bitfield_int_ty as $unit_field_int_ty) << $offset) & + ($mask as $unit_field_int_ty)) } } ).unwrap() |