From 12c24ea28a51c28bc912d970483409c9a25eea9a Mon Sep 17 00:00:00 2001 From: Wong Heung Sang <35202375+whs-dot-hk@users.noreply.github.com> Date: Sat, 9 Nov 2024 19:01:48 +0000 Subject: [PATCH] Fix a lang nix with function edge case (#56) --- src/fmt/formatter.rs | 4 ++-- src/lang/nix.rs | 13 ++++++++----- src/tokens/format_into.rs | 12 ++++++------ src/tokens/item_str.rs | 2 +- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/fmt/formatter.rs b/src/fmt/formatter.rs index 8306cd7..2ad9552 100644 --- a/src/fmt/formatter.rs +++ b/src/fmt/formatter.rs @@ -305,7 +305,7 @@ impl<'a> Formatter<'a> { } } -impl<'a> std::fmt::Write for Formatter<'a> { +impl std::fmt::Write for Formatter<'_> { fn write_str(&mut self, s: &str) -> fmt::Result { if !s.is_empty() { Formatter::write_str(self, s)?; @@ -315,7 +315,7 @@ impl<'a> std::fmt::Write for Formatter<'a> { } } -impl<'a> std::fmt::Debug for Formatter<'a> { +impl std::fmt::Debug for Formatter<'_> { fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fmt.debug_struct("Formatter") .field("line", &self.line) diff --git a/src/lang/nix.rs b/src/lang/nix.rs index cf48058..045073d 100644 --- a/src/lang/nix.rs +++ b/src/lang/nix.rs @@ -146,7 +146,10 @@ impl Nix { } } Import::With(with) => { - arguments.insert(with.argument.to_string()); + let argument = with.argument.split('.').next(); + if let Some(a) = argument { + arguments.insert(a.to_string()); + } } } } @@ -356,8 +359,8 @@ where /// ``` /// use genco::prelude::*; /// -/// let concat_map = nix::with("lib", "concatMap"); -/// let list_to_attrs = nix::with("lib", "listToAttrs"); +/// let concat_map = nix::with("inputs.nixpkgs.lib", "concatMap"); +/// let list_to_attrs = nix::with("inputs.nixpkgs.lib", "listToAttrs"); /// /// let toks = quote! { /// $list_to_attrs $concat_map @@ -366,11 +369,11 @@ where /// assert_eq!( /// vec![ /// "{", -/// " lib,", +/// " inputs,", /// " ...", /// "}:", /// "", -/// "with lib;", +/// "with inputs.nixpkgs.lib;", /// "", /// "listToAttrs concatMap", /// ], diff --git a/src/tokens/format_into.rs b/src/tokens/format_into.rs index 36871f5..b398fcb 100644 --- a/src/tokens/format_into.rs +++ b/src/tokens/format_into.rs @@ -70,7 +70,7 @@ where /// assert_eq!("foo bar baz", result.to_string()?); /// # Ok::<_, genco::fmt::Error>(()) /// ``` -impl<'a, L> FormatInto for &'a Tokens +impl FormatInto for &Tokens where L: Lang, { @@ -126,7 +126,7 @@ where /// assert_eq!("foo bar baz", result.to_string()?); /// # Ok::<_, genco::fmt::Error>(()) /// ``` -impl<'a, L, T> FormatInto for &'a [T] +impl FormatInto for &[T] where L: Lang, T: Clone + FormatInto, @@ -153,7 +153,7 @@ where /// assert_eq!("foo bar baz", result.to_string()?); /// # Ok::<_, genco::fmt::Error>(()) /// ``` -impl<'a, L> FormatInto for &'a str +impl FormatInto for &str where L: Lang, { @@ -177,7 +177,7 @@ where /// assert_eq!("foo bar baz", result.to_string()?); /// # Ok::<_, genco::fmt::Error>(()) /// ``` -impl<'a, L> FormatInto for &'a String +impl FormatInto for &String where L: Lang, { @@ -253,7 +253,7 @@ where /// assert_eq!("foo bar baz", result.to_string()?); /// # Ok::<_, genco::fmt::Error>(()) /// ``` -impl<'a, L> FormatInto for &'a Rc +impl FormatInto for &Rc where L: Lang, { @@ -276,7 +276,7 @@ where /// assert_eq!("Hello John", result.to_string()?); /// # Ok::<_, genco::fmt::Error>(()) /// ``` -impl<'a, L> FormatInto for Arguments<'a> +impl FormatInto for Arguments<'_> where L: Lang, { diff --git a/src/tokens/item_str.rs b/src/tokens/item_str.rs index 751a305..acc325a 100644 --- a/src/tokens/item_str.rs +++ b/src/tokens/item_str.rs @@ -26,7 +26,7 @@ where } } -impl<'a, L> FormatInto for &'a ItemStr +impl FormatInto for &ItemStr where L: Lang, {