@@ -2285,6 +2285,33 @@ pub struct FnSig {
2285
2285
pub span : Span ,
2286
2286
}
2287
2287
2288
+ impl FnSig {
2289
+ /// Return a span encompassing the header, or where to insert it if empty.
2290
+ pub fn header_span ( & self ) -> Span {
2291
+ match self . header . ext {
2292
+ Extern :: Implicit ( span) | Extern :: Explicit ( _, span) => {
2293
+ return self . span . with_hi ( span. hi ( ) ) ;
2294
+ }
2295
+ Extern :: None => { }
2296
+ }
2297
+
2298
+ match self . header . safety {
2299
+ Safety :: Unsafe ( span) | Safety :: Safe ( span) => return self . span . with_hi ( span. hi ( ) ) ,
2300
+ Safety :: Default => { }
2301
+ } ;
2302
+
2303
+ if let Some ( coroutine_kind) = self . header . coroutine_kind {
2304
+ return self . span . with_hi ( coroutine_kind. span ( ) . hi ( ) ) ;
2305
+ }
2306
+
2307
+ if let Const :: Yes ( span) = self . header . constness {
2308
+ return self . span . with_hi ( span. hi ( ) ) ;
2309
+ }
2310
+
2311
+ self . span . shrink_to_lo ( )
2312
+ }
2313
+ }
2314
+
2288
2315
#[ derive( Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash , Debug ) ]
2289
2316
#[ derive( Encodable , Decodable , HashStable_Generic ) ]
2290
2317
pub enum FloatTy {
@@ -3634,12 +3661,12 @@ impl Extern {
3634
3661
/// included in this struct (e.g., `async unsafe fn` or `const extern "C" fn`).
3635
3662
#[ derive( Clone , Copy , Encodable , Decodable , Debug , Walkable ) ]
3636
3663
pub struct FnHeader {
3637
- /// Whether this is `unsafe`, or has a default safety.
3638
- pub safety : Safety ,
3639
- /// Whether this is `async`, `gen`, or nothing.
3640
- pub coroutine_kind : Option < CoroutineKind > ,
3641
3664
/// The `const` keyword, if any
3642
3665
pub constness : Const ,
3666
+ /// Whether this is `async`, `gen`, or nothing.
3667
+ pub coroutine_kind : Option < CoroutineKind > ,
3668
+ /// Whether this is `unsafe`, or has a default safety.
3669
+ pub safety : Safety ,
3643
3670
/// The `extern` keyword and corresponding ABI string, if any.
3644
3671
pub ext : Extern ,
3645
3672
}
@@ -3653,38 +3680,6 @@ impl FnHeader {
3653
3680
|| matches ! ( constness, Const :: Yes ( _) )
3654
3681
|| !matches ! ( ext, Extern :: None )
3655
3682
}
3656
-
3657
- /// Return a span encompassing the header, or none if all options are default.
3658
- pub fn span ( & self ) -> Option < Span > {
3659
- fn append ( a : & mut Option < Span > , b : Span ) {
3660
- * a = match a {
3661
- None => Some ( b) ,
3662
- Some ( x) => Some ( x. to ( b) ) ,
3663
- }
3664
- }
3665
-
3666
- let mut full_span = None ;
3667
-
3668
- match self . safety {
3669
- Safety :: Unsafe ( span) | Safety :: Safe ( span) => append ( & mut full_span, span) ,
3670
- Safety :: Default => { }
3671
- } ;
3672
-
3673
- if let Some ( coroutine_kind) = self . coroutine_kind {
3674
- append ( & mut full_span, coroutine_kind. span ( ) ) ;
3675
- }
3676
-
3677
- if let Const :: Yes ( span) = self . constness {
3678
- append ( & mut full_span, span) ;
3679
- }
3680
-
3681
- match self . ext {
3682
- Extern :: Implicit ( span) | Extern :: Explicit ( _, span) => append ( & mut full_span, span) ,
3683
- Extern :: None => { }
3684
- }
3685
-
3686
- full_span
3687
- }
3688
3683
}
3689
3684
3690
3685
impl Default for FnHeader {
0 commit comments