Skip to content

ptr_arg: clarify about original type when newtype is just a Vec<_> #3381

@matthiaskrgr

Description

@matthiaskrgr

clippy 0.0.212 (b1d0343 2018-10-19)

fn main() {}

type SomeType = Vec<String>;

pub fn do_not_eat(a: &SomeType) -> SomeType {
	for i in a {
		println!("{}", i);
	}
	a.to_vec()
}

clippy warns

warning: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices.
 --> src/main.rs:5:22
  |
5 | pub fn do_not_eat(a: &SomeType) -> SomeType {
  |                      ^^^^^^^^^
  |
  = note: #[warn(clippy::ptr_arg)] on by default

but I think the message looks like a false positive if we don't see (as in this example) that the type SomeType is actually just a Vec<_> in disguise.

Can we perhaps print some detail on what the actual type is in case of newtypes to make this slightly more clear?

I found similar code in rls where syntax::ast::GenericBounds is actually just type GenericBounds = Vec<GenericBound>;

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesL-suggestionLint: Improving, adding or fixing lint suggestions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions