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 lint could warn also with &PathBuf and &Path #6502

Closed
MarcoIeni opened this issue Dec 24, 2020 · 0 comments · Fixed by #6506
Closed

ptr_arg lint could warn also with &PathBuf and &Path #6502

MarcoIeni opened this issue Dec 24, 2020 · 0 comments · Fixed by #6506
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages

Comments

@MarcoIeni
Copy link
Member

What it does

The ptr_arg lint already warns you when you pass a &String to a function.

For example with this piece of code:

fn print(a: &String) {
    println!("{:?}", a);
}

fn main() {
    let a = "/home/marco".to_string();
    print(&a);
}

This warning is emitted:

image

It would be nice if it did the same for PathBuf and Path, because from my understanding, the same principle of String and str applies.

Example

use std::path::PathBuf;

fn print(a: &PathBuf) {
    println!("{:?}", a);
}

fn main() {
    let a: PathBuf = "/home/marco".into();
    print(&a);
}

Could be written as:

use std::path::{Path, PathBuf};

fn print(a: &Path) {
    println!("{:?}", a);
}

fn main() {
    let a: PathBuf = "/home/marco".into();
    print(&a);
}
@MarcoIeni MarcoIeni added the A-lint Area: New lints label Dec 24, 2020
@giraffate giraffate added C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages and removed A-lint Area: New lints labels Dec 24, 2020
@bors bors closed this as completed in 61a3ee7 Dec 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants