1
0
mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git synced 2026-01-11 17:10:13 +00:00
Miguel Ojeda ddfa1b279d rust: quote: add SPDX License Identifiers
Originally, when the Rust upstream `alloc` standard library crate was
vendored in commit 057b8d257107 ("rust: adapt `alloc` crate to the
kernel"), the SPDX License Identifiers were added to every file so that
the license on those was clear.

Thus do the same for the `quote` crate.

This makes `scripts/spdxcheck.py` pass.

Reviewed-by: Gary Guo <gary@garyguo.net>
Tested-by: Gary Guo <gary@garyguo.net>
Tested-by: Jesung Yang <y.j3ms.n@gmail.com>
Link: https://patch.msgid.link/20251124151837.2184382-13-ojeda@kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2025-11-24 17:15:42 +01:00

53 lines
1.1 KiB
Rust

// SPDX-License-Identifier: Apache-2.0 OR MIT
use crate::ToTokens;
use proc_macro2::extra::DelimSpan;
use proc_macro2::{Span, TokenStream};
// Not public API other than via the syn crate. Use syn::spanned::Spanned.
pub trait Spanned: private::Sealed {
fn __span(&self) -> Span;
}
impl Spanned for Span {
fn __span(&self) -> Span {
*self
}
}
impl Spanned for DelimSpan {
fn __span(&self) -> Span {
self.join()
}
}
impl<T: ?Sized + ToTokens> Spanned for T {
fn __span(&self) -> Span {
join_spans(self.into_token_stream())
}
}
fn join_spans(tokens: TokenStream) -> Span {
let mut iter = tokens.into_iter().map(|tt| tt.span());
let first = match iter.next() {
Some(span) => span,
None => return Span::call_site(),
};
iter.fold(None, |_prev, next| Some(next))
.and_then(|last| first.join(last))
.unwrap_or(first)
}
mod private {
use crate::ToTokens;
use proc_macro2::extra::DelimSpan;
use proc_macro2::Span;
pub trait Sealed {}
impl Sealed for Span {}
impl Sealed for DelimSpan {}
impl<T: ?Sized + ToTokens> Sealed for T {}
}