utkarshkukreti / markup.rs

A blazing fast, type-safe template engine for Rust.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Clippy warning "elided_lifetimes_in_paths"

friedemannsommer opened this issue · comments

The generated Display implementation doesn't explicitly add a lifetime parameter to std::fmt::Formatter, which is recommended by elided_lifetimes_in_paths (which is included in rust_2018_idioms).

Example code

markup::define! {
    Example {
        span {
            "it's an example"
        }
    }
}

Macro expansion:

pub struct Example {}

impl Example {
    #[inline]
    #[allow(clippy::inherent_to_string_shadow_display)]
    #[allow(unused)]
    pub fn to_string(&self) -> String {
        let mut string = String::with_capacity(34usize);
        let _ = ::markup::Render::render(self, &mut string);
        string
    }
}

impl ::markup::Render for Example {
    fn render(&self, __writer: &mut impl std::fmt::Write) -> std::fmt::Result {
        let Example {} = self;
        __writer.write_str("<span>it's an example</span>")?;
        Ok(())
    }
}

impl std::fmt::Display for Example {
    #[inline]
    fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
        //                  ^^^^^^^^^^^^^^^^^^^ clippy complains about a missing lifetime here
        ::markup::Render::render(self, fmt)
    }
}

Possible solutions:

Explicitly allow "elided_lifetimes_in_paths"
impl std::fmt::Display for Example {
    #[inline]
    #![allow(elided_lifetimes_in_paths)]
    fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
        ::markup::Render::render(self, fmt)
    }
}
Add the placeholder lifetime
impl std::fmt::Display for Example {
    #[inline]
    fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        ::markup::Render::render(self, fmt)
    }
}