summaryrefslogtreecommitdiff
path: root/subprojects/thiserror/impl/src/unraw.rs
diff options
context:
space:
mode:
authorJohn Turner <jturner.usa@gmail.com>2025-12-21 04:20:53 +0000
committerJohn Turner <jturner.usa@gmail.com>2025-12-22 08:05:20 +0000
commit96708614ba46c42f87b23f2a957c510499d8811e (patch)
tree372dcf90f1a6fdf1b90f5d006ce7a32717f47166 /subprojects/thiserror/impl/src/unraw.rs
parent0ec856797256b5d9807929e1b32c03756eb43124 (diff)
downloadgentoo-utils-feature/port-to-meson-cargo.tar.gz
Use the new unstable meson cargo support. This simplifies the meson.build script and allows to use crates such as clap that require picking up features from Cargo.toml. This also allows us to not embed thiserror in subprojects, and instead use a wrap file with a custom meson.build and some patches to make it compile without running its build.rs script.
Diffstat (limited to 'subprojects/thiserror/impl/src/unraw.rs')
-rw-r--r--subprojects/thiserror/impl/src/unraw.rs142
1 files changed, 0 insertions, 142 deletions
diff --git a/subprojects/thiserror/impl/src/unraw.rs b/subprojects/thiserror/impl/src/unraw.rs
deleted file mode 100644
index 73b9970..0000000
--- a/subprojects/thiserror/impl/src/unraw.rs
+++ /dev/null
@@ -1,142 +0,0 @@
-use proc_macro2::{Ident, Span, TokenStream};
-use quote::ToTokens;
-use std::cmp::Ordering;
-use std::fmt::{self, Display};
-use std::hash::{Hash, Hasher};
-use syn::ext::IdentExt as _;
-use syn::parse::{Parse, ParseStream, Result};
-use syn::Index;
-
-#[derive(Clone)]
-#[repr(transparent)]
-pub struct IdentUnraw(Ident);
-
-impl IdentUnraw {
- pub fn new(ident: Ident) -> Self {
- IdentUnraw(ident)
- }
-
- pub fn to_local(&self) -> Ident {
- let unraw = self.0.unraw();
- let repr = unraw.to_string();
- if syn::parse_str::<Ident>(&repr).is_err() {
- if let "_" | "super" | "self" | "Self" | "crate" = repr.as_str() {
- // Some identifiers are never allowed to appear as raw, like r#self and r#_.
- } else {
- return Ident::new_raw(&repr, Span::call_site());
- }
- }
- unraw
- }
-
- pub fn set_span(&mut self, span: Span) {
- self.0.set_span(span);
- }
-}
-
-impl Display for IdentUnraw {
- fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
- Display::fmt(&self.0.unraw(), formatter)
- }
-}
-
-impl Eq for IdentUnraw {}
-
-impl PartialEq for IdentUnraw {
- fn eq(&self, other: &Self) -> bool {
- PartialEq::eq(&self.0.unraw(), &other.0.unraw())
- }
-}
-
-impl PartialEq<str> for IdentUnraw {
- fn eq(&self, other: &str) -> bool {
- self.0 == other
- }
-}
-
-impl Ord for IdentUnraw {
- fn cmp(&self, other: &Self) -> Ordering {
- Ord::cmp(&self.0.unraw(), &other.0.unraw())
- }
-}
-
-impl PartialOrd for IdentUnraw {
- fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
- Some(Self::cmp(self, other))
- }
-}
-
-impl Parse for IdentUnraw {
- fn parse(input: ParseStream) -> Result<Self> {
- input.call(Ident::parse_any).map(IdentUnraw::new)
- }
-}
-
-impl ToTokens for IdentUnraw {
- fn to_tokens(&self, tokens: &mut TokenStream) {
- self.0.unraw().to_tokens(tokens);
- }
-}
-
-#[derive(Clone)]
-pub enum MemberUnraw {
- Named(IdentUnraw),
- Unnamed(Index),
-}
-
-impl MemberUnraw {
- pub fn span(&self) -> Span {
- match self {
- MemberUnraw::Named(ident) => ident.0.span(),
- MemberUnraw::Unnamed(index) => index.span,
- }
- }
-}
-
-impl Display for MemberUnraw {
- fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
- match self {
- MemberUnraw::Named(this) => Display::fmt(this, formatter),
- MemberUnraw::Unnamed(this) => Display::fmt(&this.index, formatter),
- }
- }
-}
-
-impl Eq for MemberUnraw {}
-
-impl PartialEq for MemberUnraw {
- fn eq(&self, other: &Self) -> bool {
- match (self, other) {
- (MemberUnraw::Named(this), MemberUnraw::Named(other)) => this == other,
- (MemberUnraw::Unnamed(this), MemberUnraw::Unnamed(other)) => this == other,
- _ => false,
- }
- }
-}
-
-impl PartialEq<str> for MemberUnraw {
- fn eq(&self, other: &str) -> bool {
- match self {
- MemberUnraw::Named(this) => this == other,
- MemberUnraw::Unnamed(_) => false,
- }
- }
-}
-
-impl Hash for MemberUnraw {
- fn hash<H: Hasher>(&self, hasher: &mut H) {
- match self {
- MemberUnraw::Named(ident) => ident.0.unraw().hash(hasher),
- MemberUnraw::Unnamed(index) => index.hash(hasher),
- }
- }
-}
-
-impl ToTokens for MemberUnraw {
- fn to_tokens(&self, tokens: &mut TokenStream) {
- match self {
- MemberUnraw::Named(ident) => ident.to_local().to_tokens(tokens),
- MemberUnraw::Unnamed(index) => index.to_tokens(tokens),
- }
- }
-}