Skip to content

clippy::unnecessary_wraps triggered for simple custom filters defined inside modules #651

@ymelois

Description

@ymelois

Describe the bug
Simple filters that doesn't return errors trigger the clippy::unnecessary_wraps when defined inside a module. When the filter is at the root level of the crate, it doesn't.

error: this function's return value is unnecessarily wrapped by `Result`
 --> src/main.rs:8:5
  |
8 |     #[askama::filter_fn]
  |     ^^^^^^^^^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#unnecessary_wraps
note: the lint level is defined here
 --> src/main.rs:1:9
  |
1 | #![deny(clippy::unnecessary_wraps)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^
  = note: this error originates in the attribute macro `askama::filter_fn` (in Nightly builds, run with -Z macro-backtrace for more info)

To Reproduce

#![deny(clippy::unnecessary_wraps)]

use askama::Template;

mod filters {
    use std::fmt::Display;

    #[askama::filter_fn]
    pub fn simple(value: impl Display, _env: &dyn askama::Values) -> askama::Result<String> {
        Ok(value.to_string())
    }
}

#[derive(Template)]
#[template(source = r#"{{ "foo" | simple }}"#, ext = "txt")]
struct Foo<'a> {
    _bar: &'a (),
}

fn main() {}

The following doesn't trigger the clippy lint :

#![deny(clippy::unnecessary_wraps)]

use askama::Template;

use std::fmt::Display;

#[askama::filter_fn]
pub fn simple(value: impl Display, _env: &dyn askama::Values) -> askama::Result<String> {
    Ok(value.to_string())
}

#[derive(Template)]
#[template(source = r#"{{ "foo" | crate::simple }}"#, ext = "txt")]
struct Foo<'a> {
    _bar: &'a (),
}

fn main() {}

Askama version
0.15.1

Rust version

rustc 1.92.0 (ded5c06cf 2025-12-08)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions