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

ptr_arg warning should take user-defined types into account #4146

Closed
nirvdrum opened this issue May 26, 2019 · 1 comment
Closed

ptr_arg warning should take user-defined types into account #4146

nirvdrum opened this issue May 26, 2019 · 1 comment

Comments

@nirvdrum
Copy link

I have a user-defined type to make intent and usage clearer:

type BasicBlock = Vec<Statement>;

I do need/want the type to be a Vec. Unfortunately, the ptr_arg warning is issued on the resolved type, rather than taking the user-defined type into account. E.g., I have a function signature like the following:

fn enter_block(
    table: &SymbolTable<BasicBlock>,
    block: &BasicBlock
) -> SymbolTable<BasicBlock> {

Since this method doesn't really require a Vec and could get away using a slice, clippy issues the following warning:

warning: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices.
   --> src/canon.rs:123:20
    |
123 |             block: &BasicBlock,
    |                    ^^^^^^^^^^^
    |
    = note: #[warn(clippy::ptr_arg)] on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg

In this case, however, I really do want to specify the argument type as a BasicBlock, which means it is essentially a Vec. I could define it as &[Statement] to pacify the warning, but I would lose some of the clarity that the user-defined type provides. Perhaps the real answer is to rework the type entirely, but there are other contexts where I need it to work like a Vec so I'd be trading off something else.

Generally, the warning is quite is useful so I don't want to disable it as it may apply to other arguments in the function. If possible, though, I think it should silence itself when encountering a user-defined type.

@flip1995
Copy link
Member

Duplicate of #3381

We haven't found a nice solution for this problem yet, but at least there should be a help message noting, that the defined type is just a Vec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants