Skip to content

Commit 033114a

Browse files
committed
Touch up PR 1830
1 parent 7cec99c commit 033114a

1 file changed

Lines changed: 5 additions & 28 deletions

File tree

‎serde_derive/src/internals/receiver.rs‎

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
use super::respan::respan;
22
use proc_macro2::Span;
33
use std::mem;
4-
use syn::{
5-
parse_quote,
6-
punctuated::Punctuated,
7-
visit_mut::{self, VisitMut},
8-
DeriveInput, ExprPath, Path, PathArguments, QSelf, Type, TypePath,
9-
};
4+
use syn::punctuated::Punctuated;
5+
use syn::visit_mut::{self, VisitMut};
6+
use syn::{parse_quote, DeriveInput, ExprPath, Path, PathArguments, QSelf, Type, TypePath};
107

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

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

34-
// Make borrow checker happy
35-
{
36-
let first = &path.segments[0];
37-
if first.ident != "Self" || !first.arguments.is_empty() {
38-
return;
39-
}
40-
}
41-
4231
if path.segments.len() == 1 {
4332
self.self_to_expr_path(path);
4433
return;
@@ -47,7 +36,7 @@ impl ReplaceReceiver<'_> {
4736
let span = path.segments[0].ident.span();
4837
*qself = Some(QSelf {
4938
lt_token: Token![<](span),
50-
ty: Box::new(self.self_ty(span).into()),
39+
ty: Box::new(Type::Path(self.self_ty(span))),
5140
position: 0,
5241
as_token: None,
5342
gt_token: Token![>](span),
@@ -60,18 +49,6 @@ impl ReplaceReceiver<'_> {
6049
}
6150

6251
fn self_to_expr_path(&self, path: &mut Path) {
63-
if path.leading_colon.is_some() {
64-
return;
65-
}
66-
67-
// Make borrow checker happy
68-
{
69-
let first = &path.segments[0];
70-
if first.ident != "Self" || !first.arguments.is_empty() {
71-
return;
72-
}
73-
}
74-
7552
let self_ty = self.self_ty(path.segments[0].ident.span());
7653
let variant = mem::replace(path, self_ty.path);
7754
for segment in &mut path.segments {

0 commit comments

Comments
 (0)