diff options
| author | Amanieu d'Antras <amanieu@gmail.com> | 2021-02-27 14:25:19 +0000 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-27 14:25:19 +0000 | 
| commit | b4023b1ffec6aab3c4f686bbddce796291a901d8 (patch) | |
| tree | 55f18f78915e183425afd304ddf546646a5112a4 /library/stdarch/crates/assert-instr-macro | |
| parent | 5728faf0f76582f7b9c3fd39f8aa2cb4717df4b9 (diff) | |
| download | rust-b4023b1ffec6aab3c4f686bbddce796291a901d8.tar.gz rust-b4023b1ffec6aab3c4f686bbddce796291a901d8.zip | |
Initial conversion to const generics (#1018)
Diffstat (limited to 'library/stdarch/crates/assert-instr-macro')
| -rw-r--r-- | library/stdarch/crates/assert-instr-macro/src/lib.rs | 17 | 
1 files changed, 16 insertions, 1 deletions
| diff --git a/library/stdarch/crates/assert-instr-macro/src/lib.rs b/library/stdarch/crates/assert-instr-macro/src/lib.rs index 7f2c9902e2d..b475ec8bc4b 100644 --- a/library/stdarch/crates/assert-instr-macro/src/lib.rs +++ b/library/stdarch/crates/assert-instr-macro/src/lib.rs @@ -62,6 +62,7 @@ pub fn assert_instr( ); let mut inputs = Vec::new(); let mut input_vals = Vec::new(); + let mut const_vals = Vec::new(); let ret = &func.sig.output; for arg in func.sig.inputs.iter() { let capture = match *arg { @@ -82,6 +83,20 @@ pub fn assert_instr( input_vals.push(quote! { #ident }); } } + for arg in func.sig.generics.params.iter() { + let c = match *arg { + syn::GenericParam::Const(ref c) => c, + ref v => panic!( + "only const generics are allowed: `{:?}`", + v.clone().into_token_stream() + ), + }; + if let Some(&(_, ref tokens)) = invoc.args.iter().find(|a| c.ident == a.0) { + const_vals.push(quote! { #tokens }); + } else { + panic!("const generics must have a value for tests"); + } + } let attrs = func .attrs @@ -133,7 +148,7 @@ pub fn assert_instr( std::mem::transmute(#shim_name_str.as_bytes().as_ptr()), std::sync::atomic::Ordering::Relaxed, ); - #name(#(#input_vals),*) + #name::<#(#const_vals),*>(#(#input_vals),*) } }; | 
