From 6f35af23ebd8967a9fa1be27434af57e92c7a49e Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sun, 6 Oct 2019 16:30:12 +0900 Subject: [PATCH 1/3] Update proc-macro2, syn, and quote to 1.0 --- crates/assert-instr-macro/Cargo.toml | 6 ++--- crates/assert-instr-macro/src/lib.rs | 27 ++++++++++----------- crates/simd-test-macro/Cargo.toml | 4 ++-- crates/stdarch-verify/Cargo.toml | 6 ++--- crates/stdarch-verify/src/lib.rs | 36 +++++++++++++--------------- 5 files changed, 37 insertions(+), 42 deletions(-) diff --git a/crates/assert-instr-macro/Cargo.toml b/crates/assert-instr-macro/Cargo.toml index 0bf8b5faa0..eeefca2540 100644 --- a/crates/assert-instr-macro/Cargo.toml +++ b/crates/assert-instr-macro/Cargo.toml @@ -8,6 +8,6 @@ proc-macro = true test = false [dependencies] -proc-macro2 = { version = "0.4", features = ["nightly"] } -quote = "0.6" -syn = { version = "0.15", features = ["full"] } +proc-macro2 = "1.0" +quote = "1.0" +syn = { version = "1.0", features = ["full"] } diff --git a/crates/assert-instr-macro/src/lib.rs b/crates/assert-instr-macro/src/lib.rs index 0e73960584..dfa73ce525 100644 --- a/crates/assert-instr-macro/src/lib.rs +++ b/crates/assert-instr-macro/src/lib.rs @@ -36,7 +36,7 @@ pub fn assert_instr( }; let instr = &invoc.instr; - let name = &func.ident; + let name = &func.sig.ident; // Disable assert_instr for x86 targets compiled with avx enabled, which // causes LLVM to generate different intrinsics that the ones we are @@ -62,21 +62,21 @@ pub fn assert_instr( ); let mut inputs = Vec::new(); let mut input_vals = Vec::new(); - let ret = &func.decl.output; - for arg in func.decl.inputs.iter() { + let ret = &func.sig.output; + for arg in func.sig.inputs.iter() { let capture = match *arg { - syn::FnArg::Captured(ref c) => c, + syn::FnArg::Typed(ref c) => c, ref v => panic!( "arguments must not have patterns: `{:?}`", v.clone().into_token_stream() ), }; - let ident = match capture.pat { + let ident = match *capture.pat { syn::Pat::Ident(ref i) => &i.ident, _ => panic!("must have bare arguments"), }; - if let Some(&(_, ref tts)) = invoc.args.iter().find(|a| *ident == a.0) { - input_vals.push(quote! { #tts }); + if let Some(&(_, ref tokens)) = invoc.args.iter().find(|a| *ident == a.0) { + input_vals.push(quote! { #tokens }); } else { inputs.push(capture); input_vals.push(quote! { #ident }); @@ -91,7 +91,6 @@ pub fn assert_instr( .segments .first() .expect("attr.path.segments.first() failed") - .value() .ident .to_string() .starts_with("target") @@ -131,7 +130,7 @@ pub fn assert_instr( } }; - let tts: TokenStream = quote! { + let tokens: TokenStream = quote! { #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] #[cfg_attr(not(target_arch = "wasm32"), test)] #[allow(non_snake_case)] @@ -148,13 +147,13 @@ pub fn assert_instr( } }; // why? necessary now to get tests to work? - let tts: TokenStream = tts.to_string().parse().expect("cannot parse tokenstream"); + let tokens: TokenStream = tokens.to_string().parse().expect("cannot parse tokenstream"); - let tts: TokenStream = quote! { + let tokens: TokenStream = quote! { #item - #tts + #tokens }; - tts.into() + tokens.into() } struct Invoc { @@ -163,7 +162,7 @@ struct Invoc { } impl syn::parse::Parse for Invoc { - fn parse(input: syn::parse::ParseStream) -> syn::parse::Result { + fn parse(input: syn::parse::ParseStream) -> syn::Result { use syn::{ext::IdentExt, Token}; let mut instr = String::new(); diff --git a/crates/simd-test-macro/Cargo.toml b/crates/simd-test-macro/Cargo.toml index 3373e3e289..039fe8c768 100644 --- a/crates/simd-test-macro/Cargo.toml +++ b/crates/simd-test-macro/Cargo.toml @@ -8,5 +8,5 @@ proc-macro = true test = false [dependencies] -proc-macro2 = { version = "0.4", features = ["nightly"] } -quote = "0.6" +proc-macro2 = "1.0" +quote = "1.0" diff --git a/crates/stdarch-verify/Cargo.toml b/crates/stdarch-verify/Cargo.toml index 1414b11007..6362e3d57f 100644 --- a/crates/stdarch-verify/Cargo.toml +++ b/crates/stdarch-verify/Cargo.toml @@ -5,9 +5,9 @@ authors = ["Alex Crichton "] edition = "2018" [dependencies] -proc-macro2 = "0.4" -quote = "0.6" -syn = { version = "0.15", features = ["full"] } +proc-macro2 = "1.0" +quote = "1.0" +syn = { version = "1.0", features = ["full"] } [lib] proc-macro = true diff --git a/crates/stdarch-verify/src/lib.rs b/crates/stdarch-verify/src/lib.rs index b7569fe5a2..89cb7df768 100644 --- a/crates/stdarch-verify/src/lib.rs +++ b/crates/stdarch-verify/src/lib.rs @@ -6,7 +6,6 @@ extern crate quote; extern crate syn; use proc_macro::TokenStream; -use proc_macro2::Span; use std::{fs::File, io::Read, path::Path}; use syn::ext::IdentExt; @@ -57,7 +56,7 @@ fn functions(input: TokenStream, dirs: &[&str]) -> TokenStream { let mut tests = std::collections::HashSet::::new(); for f in &functions { - let id = format!("{}", f.0.ident); + let id = format!("{}", f.0.sig.ident); if id.starts_with("test_") { tests.insert(id); } @@ -66,7 +65,7 @@ fn functions(input: TokenStream, dirs: &[&str]) -> TokenStream { functions.retain(|&(ref f, _)| { if let syn::Visibility::Public(_) = f.vis { - if f.unsafety.is_some() { + if f.sig.unsafety.is_some() { return true; } } @@ -79,17 +78,17 @@ fn functions(input: TokenStream, dirs: &[&str]) -> TokenStream { let functions = functions .iter() .map(|&(ref f, path)| { - let name = &f.ident; + let name = &f.sig.ident; // println!("{}", name); let mut arguments = Vec::new(); - for input in f.decl.inputs.iter() { + for input in f.sig.inputs.iter() { let ty = match *input { - syn::FnArg::Captured(ref c) => &c.ty, + syn::FnArg::Typed(ref c) => &c.ty, _ => panic!("invalid argument on {}", name), }; arguments.push(to_type(ty)); } - let ret = match f.decl.output { + let ret = match f.sig.output { syn::ReturnType::Default => quote! { None }, syn::ReturnType::Type(_, ref t) => { let ty = to_type(t); @@ -265,7 +264,6 @@ fn extract_path_ident(path: &syn::Path) -> syn::Ident { .segments .first() .expect("segment not found") - .value() .arguments { syn::PathArguments::None => {} @@ -274,7 +272,6 @@ fn extract_path_ident(path: &syn::Path) -> syn::Ident { path.segments .first() .expect("segment not found") - .value() .ident .clone() } @@ -318,7 +315,7 @@ fn find_instrs(attrs: &[syn::Attribute]) -> Vec { // TODO: should probably just reuse `Invoc` from the `assert-instr-macro` // crate. impl syn::parse::Parse for AssertInstr { - fn parse(content: syn::parse::ParseStream) -> syn::parse::Result { + fn parse(content: syn::parse::ParseStream) -> syn::Result { let input; parenthesized!(input in content); let _ = input.parse::()?; @@ -352,9 +349,9 @@ fn find_instrs(attrs: &[syn::Attribute]) -> Vec { attrs .iter() - .filter(|a| a.path == syn::Ident::new("cfg_attr", Span::call_site()).into()) + .filter(|a| a.path.is_ident("cfg_attr")) .filter_map(|a| { - syn::parse2::(a.tts.clone()) + syn::parse2::(a.tokens.clone()) .ok() .map(|a| a.instr) }) @@ -365,9 +362,9 @@ fn find_target_feature(attrs: &[syn::Attribute]) -> Option { attrs .iter() .flat_map(|a| { - if let Some(a) = a.interpret_meta() { + if let Ok(a) = a.parse_meta() { if let syn::Meta::List(i) = a { - if i.ident == "target_feature" { + if i.path.is_ident("target_feature") { return i.nested; } } @@ -376,10 +373,10 @@ fn find_target_feature(attrs: &[syn::Attribute]) -> Option { }) .filter_map(|nested| match nested { syn::NestedMeta::Meta(m) => Some(m), - syn::NestedMeta::Literal(_) => None, + syn::NestedMeta::Lit(_) => None, }) .find_map(|m| match m { - syn::Meta::NameValue(ref i) if i.ident == "enable" => Some(i.clone().lit), + syn::Meta::NameValue(ref i) if i.path.is_ident("enable") => Some(i.clone().lit), _ => None, }) } @@ -389,7 +386,7 @@ fn find_required_const(attrs: &[syn::Attribute]) -> Vec { .iter() .flat_map(|a| { if a.path.segments[0].ident == "rustc_args_required_const" { - syn::parse::(a.tts.clone().into()) + syn::parse::(a.tokens.clone().into()) .unwrap() .args } else { @@ -404,14 +401,13 @@ struct RustcArgsRequiredConst { } impl syn::parse::Parse for RustcArgsRequiredConst { - #[allow(clippy::cast_possible_truncation)] - fn parse(input: syn::parse::ParseStream) -> syn::parse::Result { + fn parse(input: syn::parse::ParseStream) -> syn::Result { let content; parenthesized!(content in input); let list = syn::punctuated::Punctuated::::parse_terminated(&content)?; Ok(Self { - args: list.into_iter().map(|a| a.value() as usize).collect(), + args: list.into_iter().map(|a| a.base10_parse::()).collect::>()?, }) } } From cdcc5cd5c7995a6f0cdb420df7ca25b4453c4a23 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Thu, 10 Oct 2019 20:15:50 +0900 Subject: [PATCH 2/3] Build documentation with '--edition=2018' --- ci/dox.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ci/dox.sh b/ci/dox.sh index 641e3717d7..e70a32b2db 100755 --- a/ci/dox.sh +++ b/ci/dox.sh @@ -30,11 +30,13 @@ dox() { rustdoc --verbose --target "${target}" \ -o "target/doc/${arch}" crates/core_arch/src/lib.rs \ + --edition=2018 \ --crate-name core_arch \ --library-path "target/${target}/debug/deps" \ --cfg core_arch_docs rustdoc --verbose --target "${target}" \ -o "target/doc/${arch}" crates/std_detect/src/lib.rs \ + --edition=2018 \ --crate-name std_detect \ --library-path "target/${target}/debug/deps" \ --extern cfg_if="$(ls target/"${target}"/debug/deps/libcfg_if-*.rlib)" \ From ac31f69d0e974e99a96a3796cbe93de2fb54aa42 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Thu, 17 Oct 2019 17:45:18 +0900 Subject: [PATCH 3/3] Format with rustfmt --- crates/assert-instr-macro/src/lib.rs | 5 ++++- crates/stdarch-verify/src/lib.rs | 12 +++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/crates/assert-instr-macro/src/lib.rs b/crates/assert-instr-macro/src/lib.rs index dfa73ce525..8198aebc20 100644 --- a/crates/assert-instr-macro/src/lib.rs +++ b/crates/assert-instr-macro/src/lib.rs @@ -147,7 +147,10 @@ pub fn assert_instr( } }; // why? necessary now to get tests to work? - let tokens: TokenStream = tokens.to_string().parse().expect("cannot parse tokenstream"); + let tokens: TokenStream = tokens + .to_string() + .parse() + .expect("cannot parse tokenstream"); let tokens: TokenStream = quote! { #item diff --git a/crates/stdarch-verify/src/lib.rs b/crates/stdarch-verify/src/lib.rs index 89cb7df768..d71623c7f3 100644 --- a/crates/stdarch-verify/src/lib.rs +++ b/crates/stdarch-verify/src/lib.rs @@ -260,12 +260,7 @@ fn extract_path_ident(path: &syn::Path) -> syn::Ident { if path.segments.len() != 1 { panic!("unsupported path that needs name resolution") } - match path - .segments - .first() - .expect("segment not found") - .arguments - { + match path.segments.first().expect("segment not found").arguments { syn::PathArguments::None => {} _ => panic!("unsupported path that has path arguments"), } @@ -407,7 +402,10 @@ impl syn::parse::Parse for RustcArgsRequiredConst { let list = syn::punctuated::Punctuated::::parse_terminated(&content)?; Ok(Self { - args: list.into_iter().map(|a| a.base10_parse::()).collect::>()?, + args: list + .into_iter() + .map(|a| a.base10_parse::()) + .collect::>()?, }) } }