Skip to content

Commit a176e16

Browse files
committed
small fixes
1 parent 8421c73 commit a176e16

File tree

1 file changed

+7
-30
lines changed

1 file changed

+7
-30
lines changed

internal/src/dyn_init.rs

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
use std::mem;
2-
31
use proc_macro2::{Span, TokenStream};
42
use quote::{format_ident, quote};
53
use syn::{
6-
parse::Nothing, parse_quote, spanned::Spanned, visit_mut::VisitMut, Block, FnArg, Pat,
7-
PatIdent, PatType, Result, ReturnType, Signature, Stmt, Token, TraitItemFn, Type,
8-
TypeImplTrait, TypePath, TypeTraitObject,
4+
parse::Nothing, parse_quote, spanned::Spanned, Block, FnArg, Pat, PatIdent, Result, ReturnType,
5+
Signature, Stmt, Token, TraitItemFn, Type, TypeImplTrait, TypePath, TypeTraitObject,
96
};
107

118
pub fn expand(args: TokenStream, item: TokenStream) -> Result<TokenStream> {
12-
let e: syn::Expr = parse_quote!(self);
13-
println!("{e:?}");
149
let mut fun: TraitItemFn = syn::parse2(item)?;
1510
let _: Nothing = syn::parse2(args)?;
1611
let normal = normal(fun.clone());
@@ -78,7 +73,7 @@ fn set_output(fun: &mut TraitItemFn) -> OutputSet {
7873
_ => todo!("expected `-> impl Trait`"),
7974
};
8075
let mut recv = None;
81-
let args = fun
76+
let mut args = fun
8277
.sig
8378
.inputs
8479
.iter()
@@ -92,8 +87,8 @@ fn set_output(fun: &mut TraitItemFn) -> OutputSet {
9287
})
9388
.collect::<Vec<_>>();
9489
let (raw_recv, real_recv, recv_span) = recv.unwrap();
95-
let error: Type = parse_quote!(::core::convert::Infallible);
96-
**ty = parse_quote!(::pin_init::DynInit<#dyn_, (#(#args),*)>);
90+
let this = args.remove(0);
91+
**ty = parse_quote!(::pin_init::DynInit<#dyn_, (#this, #(#args),*)>);
9792
OutputSet {
9893
raw_recv,
9994
real_recv,
@@ -123,7 +118,7 @@ fn is_self_ty(ty: &Type) -> bool {
123118

124119
fn set_body(
125120
body: &mut Block,
126-
(raw, real): (Type, Type),
121+
(raw, _real): (Type, Type),
127122
sig: &mut Signature,
128123
dyn_: Type,
129124
recv_span: Span,
@@ -165,7 +160,7 @@ fn set_body(
165160
slot: *mut (),
166161
(#this, #(#args),*): (#raw, #(#arg_types),*),
167162
| -> ::pin_init::InitOk<#dyn_> {
168-
let #this = unsafe { &*(#this as *const Baz) };
163+
let #this = unsafe { &*(#this as *const Self) };
169164
let mut ptr = ::core::ptr::null_mut();
170165
let value = Self::#name(#this, #(#args),*);
171166
if false {
@@ -198,21 +193,3 @@ fn set_body(
198193
None,
199194
));
200195
}
201-
202-
struct SelfReplacer(syn::Ident);
203-
204-
impl VisitMut for SelfReplacer {
205-
fn visit_expr_path_mut(&mut self, i: &mut syn::ExprPath) {
206-
if i.qself.is_none() && i.path.is_ident("self") {
207-
i.path = syn::PathSegment {
208-
ident: self.0.clone(),
209-
arguments: syn::PathArguments::None,
210-
}
211-
.into();
212-
}
213-
}
214-
215-
fn visit_item_mut(&mut self, _: &mut syn::Item) {
216-
// Do not descend into items, since items reset/change what `Self` refers to.
217-
}
218-
}

0 commit comments

Comments
 (0)