Skip to content

clone_on_ref_ptr and macros #2076

Closed
@RazrFalcon

Description

@RazrFalcon

I have a code that looks like this:

macro_rules! try_opt {
    ($expr: expr) => {
        match $expr {
            Some(value) => value,
            None => return None
        }
    }
}

Some(Node(try_opt!(self.0.borrow().first_child.as_ref()).clone()))

Clippy suggestion:

   --> src/dom/node.rs:194:19
    |
194 |         Some(Node(try_opt!(self.0.borrow().first_child.as_ref()).clone()))
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.162/index.html#clone_on_ref_ptr  
help: try this
    |
194 |         Some(Node(Rc::clone(&match $expr {
195 |             Some(value) => value,
196 |             None => return None
197 |         })))

So it's trying to expand a macro, but badly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedL-suggestionLint: Improving, adding or fixing lint suggestionsT-macrosType: Issues with macros and macro expansion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions