Touch up PR 1830

This commit is contained in:
David Tolnay
2021-01-24 22:32:08 -08:00
parent 7cec99c7fd
commit 033114a4ae
+5 -28
View File
@@ -1,12 +1,9 @@
use super::respan::respan; use super::respan::respan;
use proc_macro2::Span; use proc_macro2::Span;
use std::mem; use std::mem;
use syn::{ use syn::punctuated::Punctuated;
parse_quote, use syn::visit_mut::{self, VisitMut};
punctuated::Punctuated, use syn::{parse_quote, DeriveInput, ExprPath, Path, PathArguments, QSelf, Type, TypePath};
visit_mut::{self, VisitMut},
DeriveInput, ExprPath, Path, PathArguments, QSelf, Type, TypePath,
};
pub fn replace_receiver(input: &mut DeriveInput) { pub fn replace_receiver(input: &mut DeriveInput) {
let self_ty = { let self_ty = {
@@ -27,18 +24,10 @@ impl ReplaceReceiver<'_> {
} }
fn self_to_qself(&self, qself: &mut Option<QSelf>, path: &mut Path) { 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; return;
} }
// Make borrow checker happy
{
let first = &path.segments[0];
if first.ident != "Self" || !first.arguments.is_empty() {
return;
}
}
if path.segments.len() == 1 { if path.segments.len() == 1 {
self.self_to_expr_path(path); self.self_to_expr_path(path);
return; return;
@@ -47,7 +36,7 @@ impl ReplaceReceiver<'_> {
let span = path.segments[0].ident.span(); let span = path.segments[0].ident.span();
*qself = Some(QSelf { *qself = Some(QSelf {
lt_token: Token![<](span), lt_token: Token![<](span),
ty: Box::new(self.self_ty(span).into()), ty: Box::new(Type::Path(self.self_ty(span))),
position: 0, position: 0,
as_token: None, as_token: None,
gt_token: Token![>](span), gt_token: Token![>](span),
@@ -60,18 +49,6 @@ impl ReplaceReceiver<'_> {
} }
fn self_to_expr_path(&self, path: &mut Path) { 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 self_ty = self.self_ty(path.segments[0].ident.span());
let variant = mem::replace(path, self_ty.path); let variant = mem::replace(path, self_ty.path);
for segment in &mut path.segments { for segment in &mut path.segments {