@@ -2285,6 +2285,33 @@ pub struct FnSig {
22852285 pub span : Span ,
22862286}
22872287
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+
22882315#[ derive( Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash , Debug ) ]
22892316#[ derive( Encodable , Decodable , HashStable_Generic ) ]
22902317pub enum FloatTy {
@@ -3634,12 +3661,12 @@ impl Extern {
36343661/// included in this struct (e.g., `async unsafe fn` or `const extern "C" fn`).
36353662#[ derive( Clone , Copy , Encodable , Decodable , Debug , Walkable ) ]
36363663pub 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 > ,
36413664 /// The `const` keyword, if any
36423665 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 ,
36433670 /// The `extern` keyword and corresponding ABI string, if any.
36443671 pub ext : Extern ,
36453672}
@@ -3653,38 +3680,6 @@ impl FnHeader {
36533680 || matches ! ( constness, Const :: Yes ( _) )
36543681 || !matches ! ( ext, Extern :: None )
36553682 }
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- }
36883683}
36893684
36903685impl Default for FnHeader {
0 commit comments