@@ -49,7 +49,9 @@ macro_rules! define_handles {
49
49
#[ repr( C ) ]
50
50
pub ( crate ) struct $oty {
51
51
handle: handle:: Handle ,
52
- // Prevent Send and Sync impls
52
+ // Prevent Send and Sync impls. `!Send`/`!Sync` is the usual
53
+ // way of doing this, but that requires unstable features.
54
+ // rust-analyzer uses this code and avoids unstable features.
53
55
_marker: PhantomData <* mut ( ) >,
54
56
}
55
57
@@ -133,7 +135,9 @@ macro_rules! define_handles {
133
135
#[ derive( Copy , Clone , PartialEq , Eq , Hash ) ]
134
136
pub ( crate ) struct $ity {
135
137
handle: handle:: Handle ,
136
- // Prevent Send and Sync impls
138
+ // Prevent Send and Sync impls. `!Send`/`!Sync` is the usual
139
+ // way of doing this, but that requires unstable features.
140
+ // rust-analyzer uses this code and avoids unstable features.
137
141
_marker: PhantomData <* mut ( ) >,
138
142
}
139
143
@@ -191,7 +195,7 @@ define_handles! {
191
195
// FIXME(eddyb) generate these impls by pattern-matching on the
192
196
// names of methods - also could use the presence of `fn drop`
193
197
// to distinguish between 'owned and 'interned, above.
194
- // Alternatively, special ' modes" could be listed of types in with_api
198
+ // Alternatively, special " modes" could be listed of types in with_api
195
199
// instead of pattern matching on methods, here and in server decl.
196
200
197
201
impl Clone for TokenStream {
@@ -250,17 +254,17 @@ macro_rules! define_client_side {
250
254
$( impl $name {
251
255
$( pub ( crate ) fn $method( $( $arg: $arg_ty) ,* ) $( -> $ret_ty) * {
252
256
Bridge :: with( |bridge| {
253
- let mut b = bridge. cached_buffer. take( ) ;
257
+ let mut buf = bridge. cached_buffer. take( ) ;
254
258
255
- b . clear( ) ;
256
- api_tags:: Method :: $name( api_tags:: $name:: $method) . encode( & mut b , & mut ( ) ) ;
257
- reverse_encode!( b ; $( $arg) ,* ) ;
259
+ buf . clear( ) ;
260
+ api_tags:: Method :: $name( api_tags:: $name:: $method) . encode( & mut buf , & mut ( ) ) ;
261
+ reverse_encode!( buf ; $( $arg) ,* ) ;
258
262
259
- b = bridge. dispatch. call( b ) ;
263
+ buf = bridge. dispatch. call( buf ) ;
260
264
261
- let r = Result :: <_, PanicMessage >:: decode( & mut & b [ ..] , & mut ( ) ) ;
265
+ let r = Result :: <_, PanicMessage >:: decode( & mut & buf [ ..] , & mut ( ) ) ;
262
266
263
- bridge. cached_buffer = b ;
267
+ bridge. cached_buffer = buf ;
264
268
265
269
r. unwrap_or_else( |e| panic:: resume_unwind( e. into( ) ) )
266
270
} )
@@ -367,7 +371,7 @@ pub struct Client<F> {
367
371
// FIXME(eddyb) use a reference to the `static COUNTERS`, instead of
368
372
// a wrapper `fn` pointer, once `const fn` can reference `static`s.
369
373
pub ( super ) get_handle_counters : extern "C" fn ( ) -> & ' static HandleCounters ,
370
- pub ( super ) run : extern "C" fn ( Bridge < ' _ > , F ) -> Buffer < u8 > ,
374
+ pub ( super ) run : extern "C" fn ( Bridge < ' _ > , F ) -> Buffer ,
371
375
pub ( super ) f : F ,
372
376
}
373
377
@@ -377,22 +381,22 @@ pub struct Client<F> {
377
381
fn run_client < A : for < ' a , ' s > DecodeMut < ' a , ' s , ( ) > , R : Encode < ( ) > > (
378
382
mut bridge : Bridge < ' _ > ,
379
383
f : impl FnOnce ( A ) -> R ,
380
- ) -> Buffer < u8 > {
384
+ ) -> Buffer {
381
385
// The initial `cached_buffer` contains the input.
382
- let mut b = bridge. cached_buffer . take ( ) ;
386
+ let mut buf = bridge. cached_buffer . take ( ) ;
383
387
384
388
panic:: catch_unwind ( panic:: AssertUnwindSafe ( || {
385
389
bridge. enter ( || {
386
- let reader = & mut & b [ ..] ;
390
+ let reader = & mut & buf [ ..] ;
387
391
let input = A :: decode ( reader, & mut ( ) ) ;
388
392
389
393
// Put the `cached_buffer` back in the `Bridge`, for requests.
390
- Bridge :: with ( |bridge| bridge. cached_buffer = b . take ( ) ) ;
394
+ Bridge :: with ( |bridge| bridge. cached_buffer = buf . take ( ) ) ;
391
395
392
396
let output = f ( input) ;
393
397
394
398
// Take the `cached_buffer` back out, for the output value.
395
- b = Bridge :: with ( |bridge| bridge. cached_buffer . take ( ) ) ;
399
+ buf = Bridge :: with ( |bridge| bridge. cached_buffer . take ( ) ) ;
396
400
397
401
// HACK(eddyb) Separate encoding a success value (`Ok(output)`)
398
402
// from encoding a panic (`Err(e: PanicMessage)`) to avoid
@@ -403,24 +407,24 @@ fn run_client<A: for<'a, 's> DecodeMut<'a, 's, ()>, R: Encode<()>>(
403
407
// this is defensively trying to avoid any accidental panicking
404
408
// reaching the `extern "C"` (which should `abort` but might not
405
409
// at the moment, so this is also potentially preventing UB).
406
- b . clear ( ) ;
407
- Ok :: < _ , ( ) > ( output) . encode ( & mut b , & mut ( ) ) ;
410
+ buf . clear ( ) ;
411
+ Ok :: < _ , ( ) > ( output) . encode ( & mut buf , & mut ( ) ) ;
408
412
} )
409
413
} ) )
410
414
. map_err ( PanicMessage :: from)
411
415
. unwrap_or_else ( |e| {
412
- b . clear ( ) ;
413
- Err :: < ( ) , _ > ( e) . encode ( & mut b , & mut ( ) ) ;
416
+ buf . clear ( ) ;
417
+ Err :: < ( ) , _ > ( e) . encode ( & mut buf , & mut ( ) ) ;
414
418
} ) ;
415
- b
419
+ buf
416
420
}
417
421
418
422
impl Client < fn ( crate :: TokenStream ) -> crate :: TokenStream > {
419
423
pub const fn expand1 ( f : fn ( crate :: TokenStream ) -> crate :: TokenStream ) -> Self {
420
424
extern "C" fn run (
421
425
bridge : Bridge < ' _ > ,
422
426
f : impl FnOnce ( crate :: TokenStream ) -> crate :: TokenStream ,
423
- ) -> Buffer < u8 > {
427
+ ) -> Buffer {
424
428
run_client ( bridge, |input| f ( crate :: TokenStream ( input) ) . 0 )
425
429
}
426
430
Client { get_handle_counters : HandleCounters :: get, run, f }
@@ -434,7 +438,7 @@ impl Client<fn(crate::TokenStream, crate::TokenStream) -> crate::TokenStream> {
434
438
extern "C" fn run (
435
439
bridge : Bridge < ' _ > ,
436
440
f : impl FnOnce ( crate :: TokenStream , crate :: TokenStream ) -> crate :: TokenStream ,
437
- ) -> Buffer < u8 > {
441
+ ) -> Buffer {
438
442
run_client ( bridge, |( input, input2) | {
439
443
f ( crate :: TokenStream ( input) , crate :: TokenStream ( input2) ) . 0
440
444
} )
0 commit comments