Skip to content

or-fun-call macro suggestion bug #1018

@lrbalt

Description

@lrbalt

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?

Activity

mcarton

mcarton commented on Jun 16, 2016

@mcarton
Member

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

added
C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messages
on Jun 16, 2016
llogiq

llogiq commented on Jun 16, 2016

@llogiq
Contributor

Is this a problem with snippet(..)?

mcarton

mcarton commented on Jun 16, 2016

@mcarton
Member

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

lrbalt

lrbalt commented on Jun 16, 2016

@lrbalt
Author

Do you mean that

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

is better here?

mcarton

mcarton commented on Jun 16, 2016

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

It avoids building the string when it is not necessary.

lrbalt

lrbalt commented on Jun 16, 2016

@lrbalt
Author

ok, thanks

added
C-bugCategory: Clippy is not doing the correct thing
T-macrosType: Issues with macros and macro expansion
on Apr 23, 2019
self-assigned this
on Apr 23, 2019
changed the title [-]or-fun-call false positive[/-] [+]or-fun-call macro suggestion bug[/+] on Apr 23, 2019
added a commit that references this issue on Apr 24, 2019
de24a74
added 3 commits that reference this issue on Apr 24, 2019
e3b8e1b
bc4605b
111cf2a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingC-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesT-macrosType: Issues with macros and macro expansion

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @lrbalt@phansch@mcarton@llogiq

    Issue actions

      or-fun-call macro suggestion bug · Issue #1018 · rust-lang/rust-clippy