Rust-clippy: Please turn off opinionated lints by default

Created on 31 Oct 2018  路  10Comments  路  Source: rust-lang/rust-clippy

Example: https://rust-lang-nursery.github.io/rust-clippy/v0.0.212/index.html#new_ret_no_self

As a convention, new methods are used to make a new instance of a type.

I've never been discussing this convention neither signed to follow it. It's some convention of some people - I just don't care how they want to write their code. And in that particular case my code can't guarantee returning new instance all the time, errors are possible, so I use Result<>. Also I think lints like this one force people to write careless code in hope they will have no errors, never. And because of that later they add ugly "panic()" calls.

Most helpful comment

@e-oz These kinds of groups already exist. They are listed at the top of the README.

All 10 comments

We literally just had an RFC that let the community decide which lints were too opinionated to be on by default.

Turn off lints you don't like yourself with #[allow(..)]. Clippy is _supposed_ to be more opinionated than rustc.

Note that we fixed the result/self false positive already on master

Clippy is supposed to be more opinionated than rustc.

then would be great to have an option to turn on only lints from desired groups, something like

#![cfg_attr(feature = "cargo-clippy", allow(group-correctness,group-perf))]

@e-oz These kinds of groups already exist. They are listed at the top of the README.

So, what am I supposed to do when this lint is triggered because I return Result<Self>? fn new_try(...)? It seems to be not answered anywhere.

In perfect case, I would like clippy to detect the -> Result<Self, _> case and have a informative comment about what exactly is preferred way of handling such fail-able constructors.

In perfect case, I would like clippy to detect the -> Result<Self, _> case and have a informative comment about what exactly is preferred way of handling such fail-able constructors.

This is already the case. Can you share the exact code that is triggering the lint? I'm unable to reproduce this both on stable and nightly. Are you on an older toolchain?

@Manishearth

warning: methods called `new` usually return `Self`
  --> cargo-crev/src/crates_io.rs:58:5
   |
58 | /     pub fn new(local: &crev_lib::Local) -> Result<Self> {
59 | |         let cache_dir = local.get_root_cache_dir().join("crates_io");
60 | |         fs::create_dir_all(&cache_dir)?;
61 | |         Ok(Self {
...  |
64 | |         })
65 | |     }
   | |_____^
   |
   = note: #[warn(clippy::new_ret_no_self)] on by default
   = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/master/index.html#new_ret_no_self

    Finished dev [unoptimized + debuginfo] target(s) in 1.83s

clippy 0.0.212 (2e26fdc 2018-11-22)  
rls-preview 1.31.7 (da98b4d 2018-12-18)
rustc 1.31.1 (b6c32da9b 2018-12-18) 

The Result comes from common_failures-0.1.1

pub type Result<T> = result::Result<T, Error>;

Oh, I know what's going on, this was fixed relatively recently (two months ago) in https://github.com/rust-lang/rust-clippy/pull/3338/files , so it's not on stable yet.

@Manishearth Thanks! I will just wait for it and disable this lint or something.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vitorenesduarte picture vitorenesduarte  路  3Comments

matthiaskrgr picture matthiaskrgr  路  3Comments

phansch picture phansch  路  3Comments

spease picture spease  路  3Comments

Luro02 picture Luro02  路  3Comments