@@ -2227,6 +2227,33 @@ pub struct FnSig {
2227
2227
pub span : Span ,
2228
2228
}
2229
2229
2230
+ impl FnSig {
2231
+ /// Return a span encompassing the header, or where to insert it if empty.
2232
+ pub fn header_span ( & self ) -> Span {
2233
+ match self . header . ext {
2234
+ Extern :: Implicit ( span) | Extern :: Explicit ( _, span) => {
2235
+ return self . span . with_hi ( span. hi ( ) ) ;
2236
+ }
2237
+ Extern :: None => { }
2238
+ }
2239
+
2240
+ match self . header . safety {
2241
+ Safety :: Unsafe ( span) | Safety :: Safe ( span) => return self . span . with_hi ( span. hi ( ) ) ,
2242
+ Safety :: Default => { }
2243
+ } ;
2244
+
2245
+ if let Some ( coroutine_kind) = self . header . coroutine_kind {
2246
+ return self . span . with_hi ( coroutine_kind. span ( ) . hi ( ) ) ;
2247
+ }
2248
+
2249
+ if let Const :: Yes ( span) = self . header . constness {
2250
+ return self . span . with_hi ( span. hi ( ) ) ;
2251
+ }
2252
+
2253
+ self . span . shrink_to_lo ( )
2254
+ }
2255
+ }
2256
+
2230
2257
#[ derive( Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash , Debug ) ]
2231
2258
#[ derive( Encodable , Decodable , HashStable_Generic ) ]
2232
2259
pub enum FloatTy {
@@ -3571,12 +3598,12 @@ impl Extern {
3571
3598
/// included in this struct (e.g., `async unsafe fn` or `const extern "C" fn`).
3572
3599
#[ derive( Clone , Copy , Encodable , Decodable , Debug ) ]
3573
3600
pub struct FnHeader {
3574
- /// Whether this is `unsafe`, or has a default safety.
3575
- pub safety : Safety ,
3576
- /// Whether this is `async`, `gen`, or nothing.
3577
- pub coroutine_kind : Option < CoroutineKind > ,
3578
3601
/// The `const` keyword, if any
3579
3602
pub constness : Const ,
3603
+ /// Whether this is `async`, `gen`, or nothing.
3604
+ pub coroutine_kind : Option < CoroutineKind > ,
3605
+ /// Whether this is `unsafe`, or has a default safety.
3606
+ pub safety : Safety ,
3580
3607
/// The `extern` keyword and corresponding ABI string, if any.
3581
3608
pub ext : Extern ,
3582
3609
}
@@ -3590,38 +3617,6 @@ impl FnHeader {
3590
3617
|| matches ! ( constness, Const :: Yes ( _) )
3591
3618
|| !matches ! ( ext, Extern :: None )
3592
3619
}
3593
-
3594
- /// Return a span encompassing the header, or none if all options are default.
3595
- pub fn span ( & self ) -> Option < Span > {
3596
- fn append ( a : & mut Option < Span > , b : Span ) {
3597
- * a = match a {
3598
- None => Some ( b) ,
3599
- Some ( x) => Some ( x. to ( b) ) ,
3600
- }
3601
- }
3602
-
3603
- let mut full_span = None ;
3604
-
3605
- match self . safety {
3606
- Safety :: Unsafe ( span) | Safety :: Safe ( span) => append ( & mut full_span, span) ,
3607
- Safety :: Default => { }
3608
- } ;
3609
-
3610
- if let Some ( coroutine_kind) = self . coroutine_kind {
3611
- append ( & mut full_span, coroutine_kind. span ( ) ) ;
3612
- }
3613
-
3614
- if let Const :: Yes ( span) = self . constness {
3615
- append ( & mut full_span, span) ;
3616
- }
3617
-
3618
- match self . ext {
3619
- Extern :: Implicit ( span) | Extern :: Explicit ( _, span) => append ( & mut full_span, span) ,
3620
- Extern :: None => { }
3621
- }
3622
-
3623
- full_span
3624
- }
3625
3620
}
3626
3621
3627
3622
impl Default for FnHeader {
0 commit comments