Skip to content

deref_addrof expands macros before creating suggestions #6234

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

Closed
jyn514 opened this issue Oct 27, 2020 · 1 comment · Fixed by #6278
Closed

deref_addrof expands macros before creating suggestions #6234

jyn514 opened this issue Oct 27, 2020 · 1 comment · Fixed by #6278
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

Comments

@jyn514
Copy link
Member

jyn514 commented Oct 27, 2020

I tried this code:

macro_rules! m {
    ($visitor: expr) => (*&$visitor)
}

pub struct S;
impl S {
    pub fn f(&self) -> &Self {
        m!(self)
    }
}

I expected to see this happen: Clippy suggests turning *&$visitor to $visitor

Instead, this happened: Clippy suggests turning *&$visitor to self:

The following errors were reported:
error[E0424]: expected value, found module `self`
 --> src/lib.rs:2:26
  |
2 |       ($visitor: expr) => (self)
  |                            ^^^^ `self` value is a keyword only available in methods with a `self` parameter
...
7 | /     pub fn f(&self) -> &Self {
8 | |         m!(self)
  | |         -------- in this macro invocation
9 | |     }
  | |_____- this function has a `self` parameter, but a macro invocation can only access identifiers it receives from parameters
  |
  = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

For more information about this error, try `rustc --explain E0424`.
Original diagnostics will follow.

warning: immediately dereferencing a reference
 --> src/lib.rs:2:26
  |
2 |     ($visitor: expr) => (*&$visitor)
  |                          ^^^^^^^^^^ help: try this: `self`
...
8 |         m!(self)
  |         -------- in this macro invocation
  |
  = note: `#[warn(clippy::deref_addrof)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#deref_addrof
  = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

Meta

  • cargo clippy -V: clippy 0.0.212 (ffa2e7a 2020-10-24)
  • rustc -Vv:
rustc 1.49.0-nightly (ffa2e7ae8 2020-10-24)
binary: rustc
commit-hash: ffa2e7ae8fbf9badc035740db949b9dae271c29f
commit-date: 2020-10-24
host: x86_64-unknown-linux-gnu
release: 1.49.0-nightly
LLVM version: 11.0
@jyn514 jyn514 added the C-bug Category: Clippy is not doing the correct thing label Oct 27, 2020
@jyn514
Copy link
Member Author

jyn514 commented Oct 27, 2020

@rustbot modify labels: +L-suggestion-causes-error +A-suggestion

@rustbot rustbot added L-suggestion Lint: Improving, adding or fixing lint suggestions I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied labels Oct 27, 2020
@bors bors closed this as completed in d212c38 Nov 9, 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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants