Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clone_on_ref_ptr and macros #2076

Closed
RazrFalcon opened this issue Sep 19, 2017 · 0 comments · Fixed by #5951
Closed

clone_on_ref_ptr and macros #2076

RazrFalcon opened this issue Sep 19, 2017 · 0 comments · Fixed by #5951
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied L-suggestion Lint: Improving, adding or fixing lint suggestions T-macros Type: Issues with macros and macro expansion

Comments

@RazrFalcon
Copy link

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.

@phansch phansch added C-bug Category: Clippy is not doing the correct thing L-suggestion Lint: Improving, adding or fixing lint suggestions labels Dec 11, 2018
@phansch phansch added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Jan 4, 2019
@phansch phansch added the T-macros Type: Issues with macros and macro expansion label Sep 23, 2019
bors added a commit that referenced this issue Aug 25, 2020
Fix incorrect suggestion when `clone_on_ref_ptr` is triggered in macros

In the lint `clone_on_ref_ptr`, if the `span` is in a macro, don't expand it for suggestion.

Fixes: #2076

changelog: none

r? @ebroto
@bors bors closed this as completed in ad7a03c Aug 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied L-suggestion Lint: Improving, adding or fixing lint suggestions T-macros Type: Issues with macros and macro expansion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants