From 385171eb8178ce2e7d6d2d2849b78e0f09feb721 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Tue, 17 Aug 2021 19:29:45 -0700 Subject: [PATCH] feat(derive): Allow anything Clone + Into to be used as a Span Fixes: https://github.com/zkat/miette/issues/12 --- miette-derive/src/snippets.rs | 8 ++++---- tests/derive.rs | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/miette-derive/src/snippets.rs b/miette-derive/src/snippets.rs index 5e73ba3..053bd3c 100644 --- a/miette-derive/src/snippets.rs +++ b/miette-derive/src/snippets.rs @@ -200,14 +200,14 @@ impl Snippets { // Context let context = &snippet.snippet; let context = quote! { - context: self.#context.clone(), + context: self.#context.clone().into(), }; // Highlights let highlights = snippet.highlights.iter().map(|highlight| { let Highlight { highlight } = highlight; quote! { - self.#highlight.clone() + self.#highlight.clone().into() } }); let highlights = quote! { @@ -288,7 +288,7 @@ impl Snippets { } }; let context = quote! { - context: #context.clone(), + context: #context.clone().into(), }; // Highlights @@ -301,7 +301,7 @@ impl Snippets { } }; quote! { - #m.clone() + #m.clone().into() } }); let highlights = quote! { diff --git a/tests/derive.rs b/tests/derive.rs index b373326..95a37e6 100644 --- a/tests/derive.rs +++ b/tests/derive.rs @@ -193,9 +193,11 @@ fn test_snippet_named_struct() { // | | // | var 1 #[highlight(snip)] - var1: SourceSpan, // label from SourceSpan is used, if any. + // label from SourceSpan is used, if any. + var1: SourceSpan, #[highlight(snip)] - var2: SourceSpan, + // Anything that's Clone + Into can be used here. + var2: (String, usize, usize), // Now with member source names filename: String,