File tree 5 files changed +40
-3
lines changed
5 files changed +40
-3
lines changed Original file line number Diff line number Diff line change @@ -402,7 +402,15 @@ fn check_api_type_alias(cx: &mut Check, alias: &TypeAlias) {
402
402
}
403
403
404
404
fn check_api_impl ( cx : & mut Check , imp : & Impl ) {
405
- if let Type :: UniquePtr ( ty) | Type :: CxxVector ( ty) = & imp. ty {
405
+ let ty = & imp. ty ;
406
+
407
+ if let Some ( negative) = imp. negative_token {
408
+ let span = quote ! ( #negative #ty) ;
409
+ cx. error ( span, "negative impl is not supported yet" ) ;
410
+ return ;
411
+ }
412
+
413
+ if let Type :: UniquePtr ( ty) | Type :: CxxVector ( ty) = ty {
406
414
if let Type :: Ident ( inner) = & ty. inner {
407
415
if Atom :: from ( & inner. rust ) . is_none ( ) {
408
416
return ;
Original file line number Diff line number Diff line change @@ -342,9 +342,14 @@ impl Hash for Impl {
342
342
fn hash < H : Hasher > ( & self , state : & mut H ) {
343
343
let Impl {
344
344
impl_token : _,
345
+ negative,
345
346
ty,
346
347
brace_token : _,
348
+ negative_token : _,
347
349
} = self ;
350
+ if * negative {
351
+ negative. hash ( state) ;
352
+ }
348
353
ty. hash ( state) ;
349
354
}
350
355
}
@@ -355,15 +360,19 @@ impl PartialEq for Impl {
355
360
fn eq ( & self , other : & Impl ) -> bool {
356
361
let Impl {
357
362
impl_token : _,
363
+ negative,
358
364
ty,
359
365
brace_token : _,
366
+ negative_token : _,
360
367
} = self ;
361
368
let Impl {
362
369
impl_token : _,
370
+ negative : negative2,
363
371
ty : ty2,
364
372
brace_token : _,
373
+ negative_token : _,
365
374
} = other;
366
- ty == ty2
375
+ negative == negative2 && ty == ty2
367
376
}
368
377
}
369
378
Original file line number Diff line number Diff line change @@ -120,8 +120,10 @@ pub struct TypeAlias {
120
120
121
121
pub struct Impl {
122
122
pub impl_token : Token ! [ impl ] ,
123
+ pub negative : bool ,
123
124
pub ty : Type ,
124
125
pub brace_token : Brace ,
126
+ pub negative_token : Option < Token ! [ !] > ,
125
127
}
126
128
127
129
pub struct Signature {
Original file line number Diff line number Diff line change @@ -673,8 +673,8 @@ fn parse_impl(imp: ItemImpl) -> Result<Api> {
673
673
return Err ( Error :: new_spanned ( span, "expected an empty impl block" ) ) ;
674
674
}
675
675
676
- let self_ty = & imp. self_ty ;
677
676
if let Some ( ( bang, path, for_token) ) = & imp. trait_ {
677
+ let self_ty = & imp. self_ty ;
678
678
let span = quote ! ( #bang #path #for_token #self_ty) ;
679
679
return Err ( Error :: new_spanned (
680
680
span,
@@ -690,10 +690,27 @@ fn parse_impl(imp: ItemImpl) -> Result<Api> {
690
690
) ) ;
691
691
}
692
692
693
+ let mut negative_token = None ;
694
+ let mut self_ty = * imp. self_ty ;
695
+ if let RustType :: Verbatim ( ty) = & self_ty {
696
+ let mut iter = ty. clone ( ) . into_iter ( ) ;
697
+ if let Some ( TokenTree :: Punct ( punct) ) = iter. next ( ) {
698
+ if punct. as_char ( ) == '!' {
699
+ let ty = iter. collect :: < TokenStream > ( ) ;
700
+ if !ty. is_empty ( ) {
701
+ negative_token = Some ( Token ! [ !] ( punct. span ( ) ) ) ;
702
+ self_ty = syn:: parse2 ( ty) ?;
703
+ }
704
+ }
705
+ }
706
+ }
707
+
693
708
Ok ( Api :: Impl ( Impl {
694
709
impl_token : imp. impl_token ,
710
+ negative : negative_token. is_some ( ) ,
695
711
ty : parse_type ( & self_ty) ?,
696
712
brace_token : imp. brace_token ,
713
+ negative_token,
697
714
} ) )
698
715
}
699
716
Original file line number Diff line number Diff line change @@ -148,6 +148,7 @@ impl ToTokens for ExternFn {
148
148
impl ToTokens for Impl {
149
149
fn to_tokens ( & self , tokens : & mut TokenStream ) {
150
150
self . impl_token . to_tokens ( tokens) ;
151
+ self . negative_token . to_tokens ( tokens) ;
151
152
self . ty . to_tokens ( tokens) ;
152
153
self . brace_token . surround ( tokens, |_tokens| { } ) ;
153
154
}
You can’t perform that action at this time.
0 commit comments