Closed
Description
clippy @ 601cc9d
This code comes from rls
impl ConcurrentJob {
pub fn new() -> (ConcurrentJob, JobToken) {
let (tx, rx) = bounded(0);
let job = ConcurrentJob { chan: rx };
let token = JobToken { _chan: tx };
(job, token)
}
fn is_completed(&self) -> bool {
is_closed(&self.chan)
}
}
It causes the following clippy warning:
warning: methods called `new` usually return `Self`
--> src/concurrency.rs:62:5
|
62 | / pub fn new() -> (ConcurrentJob, JobToken) {
63 | | let (tx, rx) = bounded(0);
64 | | let job = ConcurrentJob { chan: rx };
65 | | let token = JobToken { _chan: tx };
66 | | (job, token)
67 | | }
| |_____^
|
note: lint level defined here
--> src/main.rs:21:9
|
21 | #![warn(clippy::all, rust_2018_idioms)]
| ^^^^^^^^^^^
= note: #[warn(clippy::new_ret_no_self)] implied by #[warn(clippy::all)]
= help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.212/index.html#new_ret_no_self
I tried fixing this by making both ConcurrentJob
s be Self
however, ciippy kept warning, probably because it does not understand that the constructor actually returns a tuple of Self
and something else?
impl ConcurrentJob {
pub fn new() -> (Self, JobToken) {
let (tx, rx) = bounded(0);
let job = Self { chan: rx };
let token = JobToken { _chan: tx };
(job, token)
}
fn is_completed(&self) -> bool {
is_closed(&self.chan)
}
}
=>
warning: methods called `new` usually return `Self`
--> src/concurrency.rs:62:5
|
62 | / pub fn new() -> (Self, JobToken) {
63 | | let (tx, rx) = bounded(0);
64 | | let job = Self { chan: rx };
65 | | let token = JobToken { _chan: tx };
66 | | (job, token)
67 | | }
| |_____^
|
note: lint level defined here
--> src/main.rs:21:9
|
21 | #![warn(clippy::all, rust_2018_idioms)]
| ^^^^^^^^^^^
= note: #[warn(clippy::new_ret_no_self)] implied by #[warn(clippy::all)]
= help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.212/index.html#new_ret_no_self