diff options
| author | Folkert de Vries <folkert@folkertdev.nl> | 2025-05-07 20:02:29 +0200 |
|---|---|---|
| committer | Folkert de Vries <folkert@folkertdev.nl> | 2025-06-12 20:27:10 +0200 |
| commit | 5f73ce2b7ebfc0234a4bc736217110a2af1e2380 (patch) | |
| tree | ebc007a2643f2ab9d875026e22478682735f908f /compiler/rustc_ast/src/ast.rs | |
| parent | 0a39445252ac076ef573bcacee63bbdc59497b52 (diff) | |
| download | rust-5f73ce2b7ebfc0234a4bc736217110a2af1e2380.tar.gz rust-5f73ce2b7ebfc0234a4bc736217110a2af1e2380.zip | |
add `extern "custom"` functions
Diffstat (limited to 'compiler/rustc_ast/src/ast.rs')
| -rw-r--r-- | compiler/rustc_ast/src/ast.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index cf40c3f7f6f..e50d30e25f0 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -3520,6 +3520,38 @@ impl FnHeader { || matches!(constness, Const::Yes(_)) || !matches!(ext, Extern::None) } + + /// Return a span encompassing the header, or none if all options are default. + pub fn span(&self) -> Option<Span> { + fn append(a: &mut Option<Span>, b: Span) { + *a = match a { + None => Some(b), + Some(x) => Some(x.to(b)), + } + } + + let mut full_span = None; + + match self.safety { + Safety::Unsafe(span) | Safety::Safe(span) => append(&mut full_span, span), + Safety::Default => {} + }; + + if let Some(coroutine_kind) = self.coroutine_kind { + append(&mut full_span, coroutine_kind.span()); + } + + if let Const::Yes(span) = self.constness { + append(&mut full_span, span); + } + + match self.ext { + Extern::Implicit(span) | Extern::Explicit(_, span) => append(&mut full_span, span), + Extern::None => {} + } + + full_span + } } impl Default for FnHeader { |
