From f9e1ba2c1e11dd7c46f12c39479657c4dc92bda1 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 6 Sep 2022 06:55:43 -0500 Subject: [PATCH] fix(derive): Improve the default span --- clap_derive/src/item.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/clap_derive/src/item.rs b/clap_derive/src/item.rs index f0d029d6..2f0bdcda 100644 --- a/clap_derive/src/item.rs +++ b/clap_derive/src/item.rs @@ -54,28 +54,28 @@ pub struct Item { impl Item { pub fn from_args_struct(input: &DeriveInput, name: Name) -> Self { - let span = Span::call_site(); + let span = input.ident.span(); let attrs = &input.attrs; - let argument_casing = Sp::call_site(DEFAULT_CASING); - let env_casing = Sp::call_site(DEFAULT_ENV_CASING); + let argument_casing = Sp::new(DEFAULT_CASING, span); + let env_casing = Sp::new(DEFAULT_ENV_CASING, span); let kind = Sp::new(Kind::Command(Sp::new(Ty::Other, span)), span); Self::from_struct(attrs, name, argument_casing, env_casing, kind) } pub fn from_subcommand_enum(input: &DeriveInput, name: Name) -> Self { - let span = Span::call_site(); + let span = input.ident.span(); let attrs = &input.attrs; - let argument_casing = Sp::call_site(DEFAULT_CASING); - let env_casing = Sp::call_site(DEFAULT_ENV_CASING); + let argument_casing = Sp::new(DEFAULT_CASING, span); + let env_casing = Sp::new(DEFAULT_ENV_CASING, span); let kind = Sp::new(Kind::Command(Sp::new(Ty::Other, span)), span); Self::from_struct(attrs, name, argument_casing, env_casing, kind) } pub fn from_value_enum(input: &DeriveInput, name: Name) -> Self { - let span = Span::call_site(); + let span = input.ident.span(); let attrs = &input.attrs; - let argument_casing = Sp::call_site(DEFAULT_CASING); - let env_casing = Sp::call_site(DEFAULT_ENV_CASING); + let argument_casing = Sp::new(DEFAULT_CASING, span); + let env_casing = Sp::new(DEFAULT_ENV_CASING, span); let kind = Sp::new(Kind::Value, span); Self::from_struct(attrs, name, argument_casing, env_casing, kind) }