Eliminate workaround for pre-1.17 rustc in serde_derive

The oldest compiler supported by serde_derive by this point is 1.56.
This commit is contained in:
David Tolnay 2023-07-27 19:05:47 -07:00
parent 91ec1c290f
commit db8f06467b
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -1,4 +1,4 @@
use proc_macro2::{Punct, Spacing, TokenStream}; use proc_macro2::TokenStream;
use quote::quote; use quote::quote;
// None of our generated code requires the `From::from` error conversion // None of our generated code requires the `From::from` error conversion
@ -6,14 +6,11 @@ use quote::quote;
// we see a significant improvement in type checking and borrow checking time of // we see a significant improvement in type checking and borrow checking time of
// the generated code and a slight improvement in binary size. // the generated code and a slight improvement in binary size.
pub fn replacement() -> TokenStream { pub fn replacement() -> TokenStream {
// Cannot pass `$expr` to `quote!` prior to Rust 1.17.0 so interpolate it.
let dollar = Punct::new('$', Spacing::Alone);
quote! { quote! {
#[allow(unused_macros)] #[allow(unused_macros)]
macro_rules! try { macro_rules! try {
(#dollar __expr:expr) => { ($__expr:expr) => {
match #dollar __expr { match $__expr {
_serde::__private::Ok(__val) => __val, _serde::__private::Ok(__val) => __val,
_serde::__private::Err(__err) => { _serde::__private::Err(__err) => {
return _serde::__private::Err(__err); return _serde::__private::Err(__err);