Improve error position when cause is wrong type

This commit is contained in:
David Tolnay 2019-10-09 07:30:46 -07:00
parent cc4af147f3
commit bb13f4b07a
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82

View file

@ -1,6 +1,7 @@
use crate::attr;
use proc_macro2::TokenStream;
use quote::quote;
use quote::{quote, quote_spanned};
use syn::spanned::Spanned;
use syn::{
Data, DataEnum, DataStruct, DeriveInput, Error, Field, Fields, Ident, Index, Member, Result,
Type,
@ -34,9 +35,10 @@ fn struct_error(input: &DeriveInput, data: &DataStruct) -> Result<TokenStream> {
};
let source_method = source.map(|source| {
let member = quote_spanned!(source.span()=> &self.#source);
quote! {
fn source(&self) -> std::option::Option<&(dyn std::error::Error + 'static)> {
std::option::Option::Some(&self.#source)
std::option::Option::Some(#member)
}
}
});