diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index da31787450..3b418fe6e8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -163,10 +163,7 @@ jobs: timeout-minutes: 45 steps: - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@master - with: - toolchain: nightly-2025-05-16 # https://github.com/rust-lang/miri/issues/4323 - components: miri, rust-src + - uses: dtolnay/rust-toolchain@miri - run: cargo miri setup - run: cargo miri test --all-features ${{github.event_name == 'pull_request' && '--tests' || ''}} env: diff --git a/Cargo.toml b/Cargo.toml index e024848f39..65f5fb1d7e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "syn" -version = "2.0.104" +version = "2.0.105" authors = ["David Tolnay "] categories = ["development-tools::procedural-macro-helpers", "parser-implementations"] description = "Parser for Rust source code" diff --git a/benches/rust.rs b/benches/rust.rs index d0abce5c9e..b5edab1272 100644 --- a/benches/rust.rs +++ b/benches/rust.rs @@ -59,10 +59,9 @@ mod librustc_parse { extern crate rustc_span; use crate::repo; - use rustc_error_messages::FluentBundle; use rustc_errors::emitter::Emitter; use rustc_errors::registry::Registry; - use rustc_errors::translation::Translate; + use rustc_errors::translation::Translator; use rustc_errors::{DiagCtxt, DiagInner}; use rustc_session::parse::ParseSess; use rustc_span::source_map::{FilePathMapping, SourceMap}; @@ -78,13 +77,7 @@ mod librustc_parse { fn source_map(&self) -> Option<&SourceMap> { None } - } - - impl Translate for SilentEmitter { - fn fluent_bundle(&self) -> Option<&FluentBundle> { - None - } - fn fallback_fluent_bundle(&self) -> &FluentBundle { + fn translator(&self) -> &Translator { panic!("silent emitter attempted to translate a diagnostic"); } } diff --git a/codegen/Cargo.toml b/codegen/Cargo.toml index b31b126894..bf010b80d7 100644 --- a/codegen/Cargo.toml +++ b/codegen/Cargo.toml @@ -24,7 +24,7 @@ serde = "1.0.88" serde_json = "1.0.38" syn = { version = "2", features = ["derive", "full", "parsing", "printing"], default-features = false } syn-codegen = { path = "../json", default-features = false } -toml = { version = "0.8", default-features = false, features = ["parse"] } +toml = { version = "0.9", default-features = false, features = ["parse", "serde"] } [workspace] [patch.crates-io] diff --git a/codegen/src/parse.rs b/codegen/src/parse.rs index 06afd7ddc7..3d6ba4c8e8 100644 --- a/codegen/src/parse.rs +++ b/codegen/src/parse.rs @@ -185,7 +185,7 @@ fn introspect_type(item: &syn::Type, lookup: &Lookup) -> types::Type { if mac.path.segments.last().unwrap().ident == "Token" => { let content = mac.tokens.to_string(); - let ty = lookup.tokens.get(&content).unwrap().to_string(); + let ty = lookup.tokens.get(&content).unwrap().clone(); types::Type::Token(ty) } @@ -422,7 +422,7 @@ mod parsing { expansion.parse::()?; let path: Path = expansion.parse()?; let ty = path.segments.last().unwrap().ident.to_string(); - tokens.insert(token, ty.to_string()); + tokens.insert(token, ty.clone()); } Ok(tokens) } diff --git a/src/item.rs b/src/item.rs index a24623edb6..0b7707bf8c 100644 --- a/src/item.rs +++ b/src/item.rs @@ -2593,7 +2593,6 @@ pub(crate) mod parsing { input.parse::()?; } - let begin = input.fork(); let polarity = if input.peek(Token![!]) && !input.peek2(token::Brace) { Some(input.parse::()?) } else { @@ -2631,13 +2630,14 @@ pub(crate) mod parsing { trait_ = None; } self_ty = input.parse()?; + } else if let Some(polarity) = polarity { + return Err(Error::new( + polarity.span, + "inherent impls cannot be negative", + )); } else { trait_ = None; - self_ty = if polarity.is_none() { - first_ty - } else { - Type::Verbatim(verbatim::between(&begin, input)) - }; + self_ty = first_ty; } generics.where_clause = input.parse()?; diff --git a/src/lib.rs b/src/lib.rs index cdf4efbc19..1d2ccc310a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -249,7 +249,7 @@ //! dynamic library libproc_macro from rustc toolchain. // Syn types in rustdoc of other crates get linked to here. -#![doc(html_root_url = "https://docs.rs/syn/2.0.104")] +#![doc(html_root_url = "https://docs.rs/syn/2.0.105")] #![cfg_attr(docsrs, feature(doc_cfg))] #![deny(unsafe_op_in_unsafe_fn)] #![allow(non_camel_case_types)] diff --git a/syn.json b/syn.json index d955962a89..9263a62a39 100644 --- a/syn.json +++ b/syn.json @@ -1,5 +1,5 @@ { - "version": "2.0.104", + "version": "2.0.105", "types": [ { "ident": "Abi", diff --git a/tests/common/eq.rs b/tests/common/eq.rs index f8059a6e88..6df66de677 100644 --- a/tests/common/eq.rs +++ b/tests/common/eq.rs @@ -21,7 +21,6 @@ use rustc_ast::ast::AttrItem; use rustc_ast::ast::AttrKind; use rustc_ast::ast::AttrStyle; use rustc_ast::ast::Attribute; -use rustc_ast::ast::BareFnTy; use rustc_ast::ast::BinOpKind; use rustc_ast::ast::BindingMode; use rustc_ast::ast::Block; @@ -53,6 +52,7 @@ use rustc_ast::ast::Fn; use rustc_ast::ast::FnContract; use rustc_ast::ast::FnDecl; use rustc_ast::ast::FnHeader; +use rustc_ast::ast::FnPtrTy; use rustc_ast::ast::FnRetTy; use rustc_ast::ast::FnSig; use rustc_ast::ast::ForLoopKind; @@ -117,6 +117,7 @@ use rustc_ast::ast::Mutability; use rustc_ast::ast::NodeId; use rustc_ast::ast::NormalAttr; use rustc_ast::ast::Param; +use rustc_ast::ast::Parens; use rustc_ast::ast::ParenthesizedArgs; use rustc_ast::ast::Pat; use rustc_ast::ast::PatField; @@ -142,6 +143,7 @@ use rustc_ast::ast::StructRest; use rustc_ast::ast::Term; use rustc_ast::ast::Trait; use rustc_ast::ast::TraitBoundModifiers; +use rustc_ast::ast::TraitImplHeader; use rustc_ast::ast::TraitObjectSyntax; use rustc_ast::ast::TraitRef; use rustc_ast::ast::Ty; @@ -176,8 +178,8 @@ use rustc_ast::tokenstream::{ }; use rustc_data_structures::packed::Pu128; use rustc_span::source_map::Spanned; -use rustc_span::symbol::{sym, Ident}; -use rustc_span::{ErrorGuaranteed, Span, Symbol, SyntaxContext, DUMMY_SP}; +use rustc_span::symbol::{sym, ByteSymbol, Ident, Symbol}; +use rustc_span::{ErrorGuaranteed, Span, SyntaxContext, DUMMY_SP}; use std::borrow::Cow; use std::collections::HashMap; use std::hash::{BuildHasher, Hash}; @@ -318,6 +320,7 @@ spanless_eq_partial_eq!(str); spanless_eq_partial_eq!(String); spanless_eq_partial_eq!(Pu128); spanless_eq_partial_eq!(Symbol); +spanless_eq_partial_eq!(ByteSymbol); spanless_eq_partial_eq!(CommentKind); spanless_eq_partial_eq!(Delimiter); spanless_eq_partial_eq!(InlineAsmOptions); @@ -479,7 +482,6 @@ spanless_eq_struct!(AttrItem; unsafety path args tokens); spanless_eq_struct!(AttrTokenStream; 0); spanless_eq_struct!(Attribute; kind id style span); spanless_eq_struct!(AttrsTarget; attrs tokens); -spanless_eq_struct!(BareFnTy; safety ext generic_params decl decl_span); spanless_eq_struct!(BindingMode; 0 1); spanless_eq_struct!(Block; stmts id rules span tokens); spanless_eq_struct!(Closure; binder capture_clause constness coroutine_kind movability fn_decl body !fn_decl_span !fn_arg_span); @@ -497,16 +499,17 @@ spanless_eq_struct!(Fn; defaultness ident generics sig contract define_opaque bo spanless_eq_struct!(FnContract; requires ensures); spanless_eq_struct!(FnDecl; inputs output); spanless_eq_struct!(FnHeader; constness coroutine_kind safety ext); +spanless_eq_struct!(FnPtrTy; safety ext generic_params decl decl_span); spanless_eq_struct!(FnSig; header decl span); spanless_eq_struct!(ForeignMod; extern_span safety abi items); spanless_eq_struct!(FormatArgPosition; index kind span); -spanless_eq_struct!(FormatArgs; span template arguments uncooked_fmt_str); +spanless_eq_struct!(FormatArgs; span template arguments uncooked_fmt_str is_source_literal); spanless_eq_struct!(FormatArgument; kind expr); spanless_eq_struct!(FormatOptions; width precision alignment fill sign alternate zero_pad debug_hex); spanless_eq_struct!(FormatPlaceholder; argument span format_trait format_options); spanless_eq_struct!(GenericParam; id ident attrs bounds is_placeholder kind !colon_span); spanless_eq_struct!(Generics; params where_clause span); -spanless_eq_struct!(Impl; defaultness safety generics constness polarity of_trait self_ty items); +spanless_eq_struct!(Impl; generics of_trait self_ty items); spanless_eq_struct!(InlineAsm; asm_macro template template_strs operands clobber_abis options line_spans); spanless_eq_struct!(InlineAsmSym; id qself path); spanless_eq_struct!(Item; attrs id span vis kind !tokens); @@ -528,15 +531,16 @@ spanless_eq_struct!(Pat; id kind span tokens); spanless_eq_struct!(PatField; ident pat is_shorthand attrs id span is_placeholder); spanless_eq_struct!(Path; span segments tokens); spanless_eq_struct!(PathSegment; ident id args); -spanless_eq_struct!(PolyTraitRef; bound_generic_params modifiers trait_ref span); +spanless_eq_struct!(PolyTraitRef; bound_generic_params modifiers trait_ref span parens); spanless_eq_struct!(QSelf; ty path_span position); spanless_eq_struct!(StaticItem; ident ty safety mutability expr define_opaque); spanless_eq_struct!(Stmt; id kind span); spanless_eq_struct!(StrLit; symbol suffix symbol_unescaped style span); spanless_eq_struct!(StructExpr; qself path fields rest); spanless_eq_struct!(Token; kind span); -spanless_eq_struct!(Trait; safety is_auto ident generics bounds items); +spanless_eq_struct!(Trait; constness safety is_auto ident generics bounds items); spanless_eq_struct!(TraitBoundModifiers; constness asyncness polarity); +spanless_eq_struct!(TraitImplHeader; defaultness safety constness polarity trait_ref); spanless_eq_struct!(TraitRef; path ref_id); spanless_eq_struct!(Ty; id kind span tokens); spanless_eq_struct!(TyAlias; defaultness ident generics where_clauses bounds ty); @@ -561,7 +565,7 @@ spanless_eq_enum!(AttrStyle; Outer Inner); spanless_eq_enum!(AttrTokenTree; Token(0 1) Delimited(0 1 2 3) AttrsTarget(0)); spanless_eq_enum!(BinOpKind; Add Sub Mul Div Rem And Or BitXor BitAnd BitOr Shl Shr Eq Lt Le Ne Ge Gt); spanless_eq_enum!(BlockCheckMode; Default Unsafe(0)); -spanless_eq_enum!(BorrowKind; Ref Raw); +spanless_eq_enum!(BorrowKind; Ref Raw Pin); spanless_eq_enum!(BoundAsyncness; Normal Async(0)); spanless_eq_enum!(BoundConstness; Never Always(0) Maybe(0)); spanless_eq_enum!(BoundPolarity; Positive Negative(0) Maybe(0)); @@ -587,7 +591,7 @@ spanless_eq_enum!(GenBlockKind; Async Gen AsyncGen); spanless_eq_enum!(GenericArg; Lifetime(0) Type(0) Const(0)); spanless_eq_enum!(GenericArgs; AngleBracketed(0) Parenthesized(0) ParenthesizedElided(0)); spanless_eq_enum!(GenericBound; Trait(0) Outlives(0) Use(0 1)); -spanless_eq_enum!(GenericParamKind; Lifetime Type(default) Const(ty kw_span default)); +spanless_eq_enum!(GenericParamKind; Lifetime Type(default) Const(ty span default)); spanless_eq_enum!(ImplPolarity; Positive Negative(0)); spanless_eq_enum!(Inline; Yes No); spanless_eq_enum!(InlineAsmRegOrRegClass; Reg(0) RegClass(0)); @@ -604,6 +608,7 @@ spanless_eq_enum!(MetaItemInner; MetaItem(0) Lit(0)); spanless_eq_enum!(ModKind; Loaded(0 1 2 3) Unloaded); spanless_eq_enum!(Movability; Static Movable); spanless_eq_enum!(Mutability; Mut Not); +spanless_eq_enum!(Parens; Yes No); spanless_eq_enum!(PatFieldsRest; Rest Recovered(0) None); spanless_eq_enum!(PreciseCapturingArg; Lifetime(0) Arg(0 1)); spanless_eq_enum!(RangeEnd; Included(0) Excluded); @@ -615,7 +620,7 @@ spanless_eq_enum!(StrStyle; Cooked Raw(0)); spanless_eq_enum!(StructRest; Base(0) Rest(0) None); spanless_eq_enum!(Term; Ty(0) Const(0)); spanless_eq_enum!(TokenTree; Token(0 1) Delimited(0 1 2 3)); -spanless_eq_enum!(TraitObjectSyntax; Dyn DynStar None); +spanless_eq_enum!(TraitObjectSyntax; Dyn None); spanless_eq_enum!(TyPatKind; Range(0 1 2) Or(0) Err(0)); spanless_eq_enum!(UintTy; Usize U8 U16 U32 U64 U128); spanless_eq_enum!(UnOp; Deref Not Neg); @@ -653,7 +658,7 @@ spanless_eq_enum!(PatKind; Missing Wild Ident(0 1 2) Struct(0 1 2 3) TupleStruct(0 1 2) Or(0) Path(0 1) Tuple(0) Box(0) Deref(0) Ref(0 1) Expr(0) Range(0 1 2) Slice(0) Rest Never Guard(0 1) Paren(0) MacCall(0) Err(0)); spanless_eq_enum!(TyKind; Slice(0) Array(0 1) Ptr(0) Ref(0 1) PinnedRef(0 1) - BareFn(0) UnsafeBinder(0) Never Tup(0) Path(0 1) TraitObject(0 1) + FnPtr(0) UnsafeBinder(0) Never Tup(0) Path(0 1) TraitObject(0 1) ImplTrait(0 1) Paren(0) Typeof(0) Infer ImplicitSelf MacCall(0) CVarArgs Pat(0 1) Dummy Err(0)); diff --git a/tests/macros/mod.rs b/tests/macros/mod.rs index 024075c046..9c9a957f71 100644 --- a/tests/macros/mod.rs +++ b/tests/macros/mod.rs @@ -1,11 +1,3 @@ -#![allow(unused_macros, unused_macro_rules)] - -#[path = "../debug/mod.rs"] -pub mod debug; - -use std::str::FromStr; -use syn::parse::Result; - macro_rules! errorf { ($($tt:tt)*) => {{ use ::std::io::Write; @@ -13,81 +5,3 @@ macro_rules! errorf { write!(stderr.lock(), $($tt)*).unwrap(); }}; } - -macro_rules! punctuated { - ($($e:expr,)+) => {{ - let mut seq = ::syn::punctuated::Punctuated::new(); - $( - seq.push($e); - )+ - seq - }}; - - ($($e:expr),+) => { - punctuated!($($e,)+) - }; -} - -macro_rules! snapshot { - ($($args:tt)*) => { - snapshot_impl!(() $($args)*) - }; -} - -macro_rules! snapshot_impl { - (($expr:ident) as $t:ty, @$snapshot:literal) => { - let tokens = crate::macros::TryIntoTokens::try_into_tokens($expr).unwrap(); - let $expr: $t = syn::parse_quote!(#tokens); - let debug = crate::macros::debug::Lite(&$expr); - if !cfg!(miri) { - #[allow(clippy::needless_raw_string_hashes)] // https://github.com/mitsuhiko/insta/issues/389 - { - insta::assert_debug_snapshot!(debug, @$snapshot); - } - } - }; - (($($expr:tt)*) as $t:ty, @$snapshot:literal) => {{ - let tokens = crate::macros::TryIntoTokens::try_into_tokens($($expr)*).unwrap(); - let syntax_tree: $t = syn::parse_quote!(#tokens); - let debug = crate::macros::debug::Lite(&syntax_tree); - if !cfg!(miri) { - #[allow(clippy::needless_raw_string_hashes)] - { - insta::assert_debug_snapshot!(debug, @$snapshot); - } - } - syntax_tree - }}; - (($($expr:tt)*) , @$snapshot:literal) => {{ - let syntax_tree = $($expr)*; - let debug = crate::macros::debug::Lite(&syntax_tree); - if !cfg!(miri) { - #[allow(clippy::needless_raw_string_hashes)] - { - insta::assert_debug_snapshot!(debug, @$snapshot); - } - } - syntax_tree - }}; - (($($expr:tt)*) $next:tt $($rest:tt)*) => { - snapshot_impl!(($($expr)* $next) $($rest)*) - }; -} - -pub trait TryIntoTokens { - #[allow(dead_code)] - fn try_into_tokens(self) -> Result; -} - -impl TryIntoTokens for &str { - fn try_into_tokens(self) -> Result { - let tokens = proc_macro2::TokenStream::from_str(self)?; - Ok(tokens) - } -} - -impl TryIntoTokens for proc_macro2::TokenStream { - fn try_into_tokens(self) -> Result { - Ok(self) - } -} diff --git a/tests/repo/mod.rs b/tests/repo/mod.rs index 81b29e2a0c..81573456cd 100644 --- a/tests/repo/mod.rs +++ b/tests/repo/mod.rs @@ -222,7 +222,11 @@ static EXCLUDE_FILES: &[&str] = &[ // Rustc bug: https://github.com/rust-lang/rust/issues/132080 "src/tools/rust-analyzer/crates/parser/test_data/parser/ok/0073_safe_declarations_in_extern_blocks.rs", - // Compile-fail expr parameter in const generic position: f::<1 + 2>() + // Negative inherent impl: `impl !Box {}` + "src/tools/rustfmt/tests/source/negative-impl.rs", + "src/tools/rustfmt/tests/target/negative-impl.rs", + + // Compile-fail expr parameter in const generic position: `f::<1 + 2>()` "tests/ui/const-generics/early/closing-args-token.rs", "tests/ui/const-generics/early/const-expression-parameter.rs", diff --git a/tests/snapshot/mod.rs b/tests/snapshot/mod.rs new file mode 100644 index 0000000000..98d2aebc9d --- /dev/null +++ b/tests/snapshot/mod.rs @@ -0,0 +1,68 @@ +#![allow(unused_macros, unused_macro_rules)] + +use std::str::FromStr; +use syn::parse::Result; + +macro_rules! snapshot { + ($($args:tt)*) => { + snapshot_impl!(() $($args)*) + }; +} + +macro_rules! snapshot_impl { + (($expr:ident) as $t:ty, @$snapshot:literal) => { + let tokens = crate::snapshot::TryIntoTokens::try_into_tokens($expr).unwrap(); + let $expr: $t = syn::parse_quote!(#tokens); + let debug = crate::debug::Lite(&$expr); + if !cfg!(miri) { + #[allow(clippy::needless_raw_string_hashes)] // https://github.com/mitsuhiko/insta/issues/389 + { + insta::assert_debug_snapshot!(debug, @$snapshot); + } + } + }; + (($($expr:tt)*) as $t:ty, @$snapshot:literal) => {{ + let tokens = crate::snapshot::TryIntoTokens::try_into_tokens($($expr)*).unwrap(); + let syntax_tree: $t = syn::parse_quote!(#tokens); + let debug = crate::debug::Lite(&syntax_tree); + if !cfg!(miri) { + #[allow(clippy::needless_raw_string_hashes)] + { + insta::assert_debug_snapshot!(debug, @$snapshot); + } + } + syntax_tree + }}; + (($($expr:tt)*) , @$snapshot:literal) => {{ + let syntax_tree = $($expr)*; + let debug = crate::debug::Lite(&syntax_tree); + if !cfg!(miri) { + #[allow(clippy::needless_raw_string_hashes)] + { + insta::assert_debug_snapshot!(debug, @$snapshot); + } + } + syntax_tree + }}; + (($($expr:tt)*) $next:tt $($rest:tt)*) => { + snapshot_impl!(($($expr)* $next) $($rest)*) + }; +} + +pub trait TryIntoTokens { + #[allow(dead_code)] + fn try_into_tokens(self) -> Result; +} + +impl TryIntoTokens for &str { + fn try_into_tokens(self) -> Result { + let tokens = proc_macro2::TokenStream::from_str(self)?; + Ok(tokens) + } +} + +impl TryIntoTokens for proc_macro2::TokenStream { + fn try_into_tokens(self) -> Result { + Ok(self) + } +} diff --git a/tests/test_asyncness.rs b/tests/test_asyncness.rs index 09dbfc582c..c7aee3285b 100644 --- a/tests/test_asyncness.rs +++ b/tests/test_asyncness.rs @@ -5,7 +5,9 @@ )] #[macro_use] -mod macros; +mod snapshot; + +mod debug; use syn::{Expr, Item}; diff --git a/tests/test_attribute.rs b/tests/test_attribute.rs index a19dd0b38f..81c485e6b2 100644 --- a/tests/test_attribute.rs +++ b/tests/test_attribute.rs @@ -5,7 +5,9 @@ )] #[macro_use] -mod macros; +mod snapshot; + +mod debug; use syn::parse::Parser; use syn::{Attribute, Meta}; diff --git a/tests/test_derive_input.rs b/tests/test_derive_input.rs index 11467c7155..790e2792ad 100644 --- a/tests/test_derive_input.rs +++ b/tests/test_derive_input.rs @@ -8,7 +8,9 @@ )] #[macro_use] -mod macros; +mod snapshot; + +mod debug; use quote::quote; use syn::{Data, DeriveInput}; diff --git a/tests/test_expr.rs b/tests/test_expr.rs index e23d0bd905..e21373cf96 100644 --- a/tests/test_expr.rs +++ b/tests/test_expr.rs @@ -13,8 +13,11 @@ #[macro_use] mod macros; +#[macro_use] +mod snapshot; mod common; +mod debug; use crate::common::visit::{AsIfPrinted, FlattenParens}; use proc_macro2::{Delimiter, Group, Ident, Span, TokenStream}; @@ -900,9 +903,9 @@ fn test_fixup() { original == reconstructed, "original: {}\n{:#?}\nreconstructed: {}\n{:#?}", original.to_token_stream(), - crate::macros::debug::Lite(&original), + crate::debug::Lite(&original), reconstructed.to_token_stream(), - crate::macros::debug::Lite(&reconstructed), + crate::debug::Lite(&reconstructed), ); } } @@ -1663,7 +1666,7 @@ fn test_permutations() -> ExitCode { fail!( "failed to parse: {}\n{:#?}", tokens, - crate::macros::debug::Lite(&original), + crate::debug::Lite(&original), ); }; AsIfPrinted.visit_expr_mut(&mut original); @@ -1672,9 +1675,9 @@ fn test_permutations() -> ExitCode { fail!( "before: {}\n{:#?}\nafter: {}\n{:#?}", tokens, - crate::macros::debug::Lite(&original), + crate::debug::Lite(&original), parsed.to_token_stream(), - crate::macros::debug::Lite(&parsed), + crate::debug::Lite(&parsed), ); } let mut tokens_no_paren = tokens.clone(); diff --git a/tests/test_generics.rs b/tests/test_generics.rs index 4dc183c00c..c96a786644 100644 --- a/tests/test_generics.rs +++ b/tests/test_generics.rs @@ -7,7 +7,9 @@ )] #[macro_use] -mod macros; +mod snapshot; + +mod debug; use quote::quote; use syn::{DeriveInput, ItemFn, TypeParamBound, WhereClause, WherePredicate}; diff --git a/tests/test_grouping.rs b/tests/test_grouping.rs index 5d4b62914d..b466c7e721 100644 --- a/tests/test_grouping.rs +++ b/tests/test_grouping.rs @@ -5,7 +5,9 @@ )] #[macro_use] -mod macros; +mod snapshot; + +mod debug; use proc_macro2::{Delimiter, Group, Literal, Punct, Spacing, TokenStream, TokenTree}; use syn::Expr; diff --git a/tests/test_item.rs b/tests/test_item.rs index 0a12b7aadc..d9a7b5b6b0 100644 --- a/tests/test_item.rs +++ b/tests/test_item.rs @@ -5,7 +5,9 @@ )] #[macro_use] -mod macros; +mod snapshot; + +mod debug; use proc_macro2::{Delimiter, Group, Ident, Span, TokenStream, TokenTree}; use quote::quote; @@ -51,8 +53,6 @@ fn test_macro_variable_attr() { #[test] fn test_negative_impl() { - // Rustc parses all of the following. - #[cfg(any())] impl ! {} let tokens = quote! { @@ -65,18 +65,11 @@ fn test_negative_impl() { } "#); - #[cfg(any())] - #[rustfmt::skip] - impl !Trait {} let tokens = quote! { impl !Trait {} }; - snapshot!(tokens as Item, @r#" - Item::Impl { - generics: Generics, - self_ty: Type::Verbatim(`! Trait`), - } - "#); + let err = syn::parse2::(tokens).unwrap_err(); + assert_eq!(err.to_string(), "inherent impls cannot be negative"); #[cfg(any())] impl !Trait for T {} @@ -107,19 +100,6 @@ fn test_negative_impl() { }, } "#); - - #[cfg(any())] - #[rustfmt::skip] - impl !! {} - let tokens = quote! { - impl !! {} - }; - snapshot!(tokens as Item, @r#" - Item::Impl { - generics: Generics, - self_ty: Type::Verbatim(`! !`), - } - "#); } #[test] diff --git a/tests/test_iterators.rs b/tests/test_iterators.rs index 525d77b1f3..57c21bf9f4 100644 --- a/tests/test_iterators.rs +++ b/tests/test_iterators.rs @@ -8,8 +8,19 @@ use syn::punctuated::{Pair, Punctuated}; use syn::{parse_quote, GenericParam, Generics, Lifetime, LifetimeParam, Token}; -#[macro_use] -mod macros; +macro_rules! punctuated { + ($($e:expr,)+) => {{ + let mut seq = ::syn::punctuated::Punctuated::new(); + $( + seq.push($e); + )+ + seq + }}; + + ($($e:expr),+) => { + punctuated!($($e,)+) + }; +} macro_rules! check_exact_size_iterator { ($iter:expr) => {{ diff --git a/tests/test_lit.rs b/tests/test_lit.rs index 6a7208a239..f2367b4416 100644 --- a/tests/test_lit.rs +++ b/tests/test_lit.rs @@ -9,7 +9,9 @@ )] #[macro_use] -mod macros; +mod snapshot; + +mod debug; use proc_macro2::{Delimiter, Group, Literal, Span, TokenStream, TokenTree}; use quote::ToTokens; diff --git a/tests/test_meta.rs b/tests/test_meta.rs index 519b3ecf43..30d393c153 100644 --- a/tests/test_meta.rs +++ b/tests/test_meta.rs @@ -7,7 +7,9 @@ )] #[macro_use] -mod macros; +mod snapshot; + +mod debug; use syn::{Meta, MetaList, MetaNameValue}; diff --git a/tests/test_parse_quote.rs b/tests/test_parse_quote.rs index 33665e068a..600870bab5 100644 --- a/tests/test_parse_quote.rs +++ b/tests/test_parse_quote.rs @@ -5,7 +5,9 @@ )] #[macro_use] -mod macros; +mod snapshot; + +mod debug; use syn::punctuated::Punctuated; use syn::{parse_quote, Attribute, Field, Lit, Pat, Stmt, Token}; diff --git a/tests/test_pat.rs b/tests/test_pat.rs index 615de6a14b..f778928bc9 100644 --- a/tests/test_pat.rs +++ b/tests/test_pat.rs @@ -5,7 +5,9 @@ )] #[macro_use] -mod macros; +mod snapshot; + +mod debug; use proc_macro2::{Delimiter, Group, TokenStream, TokenTree}; use quote::{quote, ToTokens as _}; diff --git a/tests/test_path.rs b/tests/test_path.rs index 39aa91c08c..7f9e515d26 100644 --- a/tests/test_path.rs +++ b/tests/test_path.rs @@ -5,7 +5,9 @@ )] #[macro_use] -mod macros; +mod snapshot; + +mod debug; use proc_macro2::{Delimiter, Group, Ident, Punct, Spacing, Span, TokenStream, TokenTree}; use quote::{quote, ToTokens}; diff --git a/tests/test_precedence.rs b/tests/test_precedence.rs index 58d3a9891d..33af2746a9 100644 --- a/tests/test_precedence.rs +++ b/tests/test_precedence.rs @@ -264,7 +264,9 @@ fn librustc_parenthesize(mut librustc_expr: Box) -> Box { fields, rest, } = expr.deref_mut(); - vis.visit_qself(qself); + if let Some(qself) = qself { + vis.visit_qself(qself); + } vis.visit_path(path); fields.flat_map_in_place(|field| flat_map_field(field, vis)); if let StructRest::Base(rest) = rest { diff --git a/tests/test_receiver.rs b/tests/test_receiver.rs index b0e2a91fa2..98194101fd 100644 --- a/tests/test_receiver.rs +++ b/tests/test_receiver.rs @@ -5,7 +5,9 @@ )] #[macro_use] -mod macros; +mod snapshot; + +mod debug; use syn::{parse_quote, TraitItemFn}; diff --git a/tests/test_shebang.rs b/tests/test_shebang.rs index 20450b74e5..3b55ddfdd5 100644 --- a/tests/test_shebang.rs +++ b/tests/test_shebang.rs @@ -5,7 +5,9 @@ )] #[macro_use] -mod macros; +mod snapshot; + +mod debug; #[test] fn test_basic() { diff --git a/tests/test_stmt.rs b/tests/test_stmt.rs index ba1e63af7c..101c1b1c90 100644 --- a/tests/test_stmt.rs +++ b/tests/test_stmt.rs @@ -7,7 +7,9 @@ )] #[macro_use] -mod macros; +mod snapshot; + +mod debug; use proc_macro2::{Delimiter, Group, Ident, Span, TokenStream, TokenTree}; use quote::{quote, ToTokens as _}; diff --git a/tests/test_token_trees.rs b/tests/test_token_trees.rs index 3dc3734cbc..1b473858cd 100644 --- a/tests/test_token_trees.rs +++ b/tests/test_token_trees.rs @@ -5,7 +5,9 @@ )] #[macro_use] -mod macros; +mod snapshot; + +mod debug; use proc_macro2::TokenStream; use quote::quote; diff --git a/tests/test_ty.rs b/tests/test_ty.rs index c85f592add..5f29220114 100644 --- a/tests/test_ty.rs +++ b/tests/test_ty.rs @@ -5,7 +5,9 @@ )] #[macro_use] -mod macros; +mod snapshot; + +mod debug; use proc_macro2::{Delimiter, Group, Ident, Punct, Spacing, Span, TokenStream, TokenTree}; use quote::{quote, ToTokens as _}; diff --git a/tests/test_visibility.rs b/tests/test_visibility.rs index 0bc98b15f8..cf15574b51 100644 --- a/tests/test_visibility.rs +++ b/tests/test_visibility.rs @@ -5,7 +5,9 @@ )] #[macro_use] -mod macros; +mod snapshot; + +mod debug; use proc_macro2::{Delimiter, Group, Ident, Punct, Spacing, Span, TokenStream, TokenTree}; use quote::quote;