Skip to content

or-fun-call macro suggestion bug #1018

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
lrbalt opened this issue Jun 16, 2016 · 6 comments · Fixed by #4023
Closed

or-fun-call macro suggestion bug #1018

lrbalt opened this issue Jun 16, 2016 · 6 comments · Fixed by #4023
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages T-macros Type: Issues with macros and macro expansion

Comments

@lrbalt
Copy link

lrbalt commented Jun 16, 2016

I have this code:

r.view_args
     .get(name)
     .ok_or(format!("{} not given", name))

Clippy reports:

src/app/app_server.rs:259:5: 261:43 warning: use of `ok_or` followed by a function call, #[warn(or_fun_call)] on by default
src/app/app_server.rs:259     r.view_args
                              ^
src/app/app_server.rs:259:5: 261:43 help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#or_fun_call
src/app/app_server.rs:259:5: 261:43 help: try this
src/app/app_server.rs:        r.view_args
src/app/app_server.rs:         .get(name).ok_or_else(|| $ crate :: fmt :: format ( format_args ! ( $ ( $ arg ) * ) ))

Perhaps Clippy should ignore .ok_or(macro!()) constructs?

@mcarton
Copy link
Member

mcarton commented Jun 16, 2016

The suggestion is badly formatted but ok_or_else would still be a better choice here.

@mcarton mcarton added the C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages label Jun 16, 2016
@llogiq
Copy link
Contributor

llogiq commented Jun 16, 2016

Is this a problem with snippet(..)?

@mcarton
Copy link
Member

mcarton commented Jun 16, 2016

Yes, it's been there since #944 with some macro spans.

@lrbalt
Copy link
Author

lrbalt commented Jun 16, 2016

Do you mean that

.view_args
     .get(name)
     .ok_or_else(format!("{} not given", name))

is better here?

@mcarton
Copy link
Member

mcarton commented Jun 16, 2016

     .ok_or_else(|| format!("{} not given", name))

It avoids building the string when it is not necessary.

@lrbalt
Copy link
Author

lrbalt commented Jun 16, 2016

ok, thanks

@phansch phansch added C-bug Category: Clippy is not doing the correct thing T-macros Type: Issues with macros and macro expansion labels Apr 23, 2019
@phansch phansch self-assigned this Apr 23, 2019
@Manishearth Manishearth changed the title or-fun-call false positive or-fun-call macro suggestion bug Apr 23, 2019
phansch added a commit to phansch/rust-clippy that referenced this issue Apr 24, 2019
bors added a commit that referenced this issue Apr 24, 2019
Add test for or_fun_call macro suggestion

changelog: none

Closes #1018
bors added a commit that referenced this issue Apr 24, 2019
Add test for or_fun_call macro suggestion

changelog: none

Closes #1018
bors added a commit that referenced this issue Apr 24, 2019
Add test for or_fun_call macro suggestion

changelog: none

Closes #1018
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 C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages T-macros Type: Issues with macros and macro expansion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants