File tree Expand file tree Collapse file tree 3 files changed +43
-0
lines changed
Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ #![warn(clippy::needless_path_new)]
2+
3+ use std::fs;
4+ use std::path::Path;
5+
6+ // fn foo() -> Option<&'static Path> {
7+ // // Some(...) is `ExprKind::Call`, but we don't consider it
8+ // Some(Path::new("foo.txt"))
9+ // }
10+ //
11+ fn main() {
12+ // let _: Option<&Path> = Some(Path::new("foo"));
13+ fn foo() -> Option<impl AsRef<Path>> {
14+ Some("bar.txt") //~ needless_path_new
15+ }
16+ }
Original file line number Diff line number Diff line change 1+ #![ warn( clippy:: needless_path_new) ]
2+
3+ use std:: fs;
4+ use std:: path:: Path ;
5+
6+ fn foo ( ) -> Option < & ' static Path > {
7+ // Some(...) is `ExprKind::Call`, but we don't consider it
8+ Some ( Path :: new ( "foo.txt" ) )
9+ }
10+
11+ fn main ( ) {
12+ let _: Option < & Path > = Some ( Path :: new ( "foo" ) ) ;
13+ fn foo ( ) -> Option < impl AsRef < Path > > {
14+ Some ( Path :: new ( "bar.txt" ) ) //~ needless_path_new
15+ }
16+ }
Original file line number Diff line number Diff line change 1+ error: the expression enclosed in `Path::new` implements `AsRef<Path>`
2+ --> tests/ui/needless_path_new_some.rs:14:14
3+ |
4+ LL | Some(Path::new("bar.txt"))
5+ | ^^^^^^^^^^^^^^^^^^^^ help: remove the enclosing `Path::new`: `"bar.txt"`
6+ |
7+ = note: `-D clippy::needless-path-new` implied by `-D warnings`
8+ = help: to override `-D warnings` add `#[allow(clippy::needless_path_new)]`
9+
10+ error: aborting due to 1 previous error
11+
You can’t perform that action at this time.
0 commit comments