diff options
author | Greg Brown <gmb60@cam.ac.uk> | 2021-01-19 22:48:36 +0000 |
---|---|---|
committer | Greg Brown <gmb60@cam.ac.uk> | 2021-01-19 22:48:36 +0000 |
commit | faa3f30deb32d0a1fd7cb196559762635b22ecfd (patch) | |
tree | 6ab8bc07c32f51811929c03320f0a87b4ca8ae3c /src/chomp/ast | |
parent | 8f7a17e0f48e3586fae619be08351c6761b07596 (diff) |
Remove usage of feature of proc_macro2.
Diffstat (limited to 'src/chomp/ast')
-rw-r--r-- | src/chomp/ast/error.rs | 61 |
1 files changed, 38 insertions, 23 deletions
diff --git a/src/chomp/ast/error.rs b/src/chomp/ast/error.rs index 7be5354..12d7b90 100644 --- a/src/chomp/ast/error.rs +++ b/src/chomp/ast/error.rs @@ -1,4 +1,7 @@ -use std::{error::Error, fmt::{self, Display}}; +use std::{ + error::Error, + fmt::{self, Display}, +}; use proc_macro2::Span; @@ -8,26 +11,27 @@ use super::{Call, Parameter}; #[derive(Debug)] pub enum SubstituteError { - FreeParameter { param: Parameter, span: Option<Span>, name: Option<Name> }, - WrongArgCount { call: Call, expected: usize, span: Option<Span> }, + FreeParameter { + param: Parameter, + span: Option<Span>, + name: Option<Name>, + }, + WrongArgCount { + call: Call, + expected: usize, + span: Option<Span>, + }, } impl From<SubstituteError> for syn::Error { fn from(e: SubstituteError) -> Self { - match e { - SubstituteError::FreeParameter { span, .. } => { - Self::new(span.unwrap_or_else(Span::call_site), "unbound parameter") - } - SubstituteError::WrongArgCount { call, expected, span } => { - let msg = if call.args.len() == 1 { - format!("this function takes {} arguments but 1 was supplied", expected) - } else { - format!("this function takes {} arguments but {} were supplied", expected, call.args.len()) - }; + let msg = e.to_string(); + let span = match e { + SubstituteError::FreeParameter { span, .. } => span, + SubstituteError::WrongArgCount { span, .. } => span, + }; - Self::new(span.unwrap_or_else(Span::call_site), msg) - } - } + Self::new(span.unwrap_or_else(Span::call_site), msg) } } @@ -35,19 +39,30 @@ impl Display for SubstituteError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::FreeParameter { param, span, name } => { - let start = span.unwrap_or_else(Span::call_site).start(); if let Some(name) = name { - write!(f, "{}:{}: unbound parameter `{}`", start.line, start.column, name) + write!(f, "unbound parameter: `{}`", name) } else { - write!(f, "{}:{}: unbound parameter '{}", start.line, start.column, param.index) + write!(f, "unbound parameter: '{}", param.index) } } - Self::WrongArgCount { call, expected, span } => { - let start = span.unwrap_or_else(Span::call_site).start(); + Self::WrongArgCount { + call, + expected, + span, + } => { if call.args.len() == 1 { - write!(f, "{}:{}: this function takes {} arguments but 1 was supplied", start.line, start.column, expected) + write!( + f, + "this function takes {} arguments but 1 was supplied", + expected + ) } else { - write!(f, "{}:{}: this function takes {} arguments but {} were supplied", start.line, start.column, expected, call.args.len()) + write!( + f, + "this function takes {} arguments but {} were supplied", + expected, + call.args.len() + ) } } } |