From a990de90fe41456a23e58bd087d2f107d321f3a1 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Fri, 19 Jul 2024 16:37:58 +0400 Subject: Deleted vendor folder --- vendor/miette-derive/src/code.rs | 80 ---------------------------------------- 1 file changed, 80 deletions(-) delete mode 100644 vendor/miette-derive/src/code.rs (limited to 'vendor/miette-derive/src/code.rs') diff --git a/vendor/miette-derive/src/code.rs b/vendor/miette-derive/src/code.rs deleted file mode 100644 index 22dc795..0000000 --- a/vendor/miette-derive/src/code.rs +++ /dev/null @@ -1,80 +0,0 @@ -use proc_macro2::TokenStream; -use quote::quote; -use syn::{ - parenthesized, - parse::{Parse, ParseStream}, - Token, -}; - -use crate::{ - diagnostic::{DiagnosticConcreteArgs, DiagnosticDef}, - forward::WhichFn, - utils::gen_all_variants_with, -}; - -#[derive(Debug)] -pub struct Code(pub String); - -impl Parse for Code { - fn parse(input: ParseStream) -> syn::Result { - let ident = input.parse::()?; - if ident == "code" { - let la = input.lookahead1(); - if la.peek(syn::token::Paren) { - let content; - parenthesized!(content in input); - let la = content.lookahead1(); - if la.peek(syn::LitStr) { - let str = content.parse::()?; - Ok(Code(str.value())) - } else { - let path = content.parse::()?; - Ok(Code( - path.segments - .iter() - .map(|s| s.ident.to_string()) - .collect::>() - .join("::"), - )) - } - } else { - input.parse::()?; - Ok(Code(input.parse::()?.value())) - } - } else { - Err(syn::Error::new(ident.span(), "diagnostic code is required. Use #[diagnostic(code = ...)] or #[diagnostic(code(...))] to define one.")) - } - } -} - -impl Code { - pub(crate) fn gen_enum(variants: &[DiagnosticDef]) -> Option { - gen_all_variants_with( - variants, - WhichFn::Code, - |ident, fields, DiagnosticConcreteArgs { code, .. }| { - let code = &code.as_ref()?.0; - Some(match fields { - syn::Fields::Named(_) => { - quote! { Self::#ident { .. } => std::option::Option::Some(std::boxed::Box::new(#code)), } - } - syn::Fields::Unnamed(_) => { - quote! { Self::#ident(..) => std::option::Option::Some(std::boxed::Box::new(#code)), } - } - syn::Fields::Unit => { - quote! { Self::#ident => std::option::Option::Some(std::boxed::Box::new(#code)), } - } - }) - }, - ) - } - - pub(crate) fn gen_struct(&self) -> Option { - let code = &self.0; - Some(quote! { - fn code(&self) -> std::option::Option> { - std::option::Option::Some(std::boxed::Box::new(#code)) - } - }) - } -} -- cgit v1.2.3