Skip to content

Commit

Permalink
Touch up PR 1830
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jan 25, 2021
1 parent 7cec99c commit 033114a
Showing 1 changed file with 5 additions and 28 deletions.
33 changes: 5 additions & 28 deletions serde_derive/src/internals/receiver.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use super::respan::respan;
use proc_macro2::Span;
use std::mem;
use syn::{
parse_quote,
punctuated::Punctuated,
visit_mut::{self, VisitMut},
DeriveInput, ExprPath, Path, PathArguments, QSelf, Type, TypePath,
};
use syn::punctuated::Punctuated;
use syn::visit_mut::{self, VisitMut};
use syn::{parse_quote, DeriveInput, ExprPath, Path, PathArguments, QSelf, Type, TypePath};

pub fn replace_receiver(input: &mut DeriveInput) {
let self_ty = {
Expand All @@ -27,18 +24,10 @@ impl ReplaceReceiver<'_> {
}

fn self_to_qself(&self, qself: &mut Option<QSelf>, path: &mut Path) {
if path.leading_colon.is_some() {
if path.leading_colon.is_some() || path.segments[0].ident != "Self" {
return;
}

// Make borrow checker happy
{
let first = &path.segments[0];
if first.ident != "Self" || !first.arguments.is_empty() {
return;
}
}

if path.segments.len() == 1 {
self.self_to_expr_path(path);
return;
Expand All @@ -47,7 +36,7 @@ impl ReplaceReceiver<'_> {
let span = path.segments[0].ident.span();
*qself = Some(QSelf {
lt_token: Token![<](span),
ty: Box::new(self.self_ty(span).into()),
ty: Box::new(Type::Path(self.self_ty(span))),
position: 0,
as_token: None,
gt_token: Token![>](span),
Expand All @@ -60,18 +49,6 @@ impl ReplaceReceiver<'_> {
}

fn self_to_expr_path(&self, path: &mut Path) {
if path.leading_colon.is_some() {
return;
}

// Make borrow checker happy
{
let first = &path.segments[0];
if first.ident != "Self" || !first.arguments.is_empty() {
return;
}
}

let self_ty = self.self_ty(path.segments[0].ident.span());
let variant = mem::replace(path, self_ty.path);
for segment in &mut path.segments {
Expand Down

0 comments on commit 033114a

Please sign in to comment.