Skip to content

Potential false positive for let_and_return #1322

Closed
@Keats

Description

@Keats

I have the following macro:

#[macro_export]
macro_rules! try_get_value {
    ($filter_name:expr, $var_name:expr, $ty:ty, $val:expr) => {{
        let v: $ty = match ::serde_json::value::from_value($val.clone()) {
            Ok(s) => s,
            Err(_) => {
                return Err(::errors::TeraError::FilterIncorrectArgType(
                    $filter_name.to_string(),
                    $var_name.to_string(),
                    $val,
                    stringify!($ty).to_string())
                );
            }
        };
        v
    }};
}

And running clippy, it complains that I can directly return the match but doing so fails since it doesn't know the type ($ty can f32, String, etc).
Afaik there is no other way to cast the s variable other than that syntax (as $ty doesn't work). Am I missing a way to do it or is it a real false positive?

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.L-styleLint: Belongs in the style lint group

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions