Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upUplift lints from clippy to rustc #53224
Comments
oli-obk
added
A-lint
T-compiler
labels
Aug 9, 2018
This comment has been minimized.
This comment has been minimized.
|
@rfcbot fcp merge please raise concerns about specific lints directly with rfcbot |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Aug 9, 2018
•
|
Team member @oli-obk has proposed to merge this. The next step is review by the rest of the tagged teams:
Concerns:
Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
rfcbot
added
proposed-final-comment-period
disposition-merge
labels
Aug 9, 2018
This comment has been minimized.
This comment has been minimized.
|
https://rust-lang-nursery.github.io/rust-clippy/master/index.html#unused_io_amount seems like it should be replaced with a |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@Mark-Simulacrum You should be able to do it without any special support on the method declaration in the trait, because that's what paths and method calls resolve to, but if you want to stick it on method definitions in impls, that's significantly harder. |
This comment has been minimized.
This comment has been minimized.
|
The problem is not that the return value is unused, it is usually used via |
This comment was marked as resolved.
This comment was marked as resolved.
I feel like classifying this as correctness is a bit of a stretch? It seems like type check ought to resolve most of the bugs that would occur here. We may still want to uplift it, though, I'm not sure. UPDATE: ok, my mistake, I didn't realize the meaning of the checked boxes. =) |
This comment has been minimized.
This comment has been minimized.
Related: #50842
IMO description is wrong, as the example shows creation of a zero-reference, not a reference to zeroed memory. @rfcbot concern tying compiler to stdlib implementation details Many of these lints are libstd specific (mostly pertaining to iterators). What mnemonic does clippy use to figure out what libstd items are what and whether the actual libstd is used at all and not e.g. @rfcbot concern the descriptions of lints are a little too concise for decision making. For example, it is unclear from description of |
rfcbot
added
proposed-final-comment-period
disposition-merge
labels
Aug 10, 2018
This comment has been minimized.
This comment has been minimized.
|
A good way to test your questions is to use https://play.rust-lang.org/. On the right hand side, there’s a “Tools” dropdown which has Clippy in it. @rfcbot concern some lints are opinionated on how the target platform ought to work For example, the // Gets a mutable reference to resource’s register bank
unsafe fn get_resource(x: &ResourceLock) -> &mut Resource {
// THE_RESOURCE is linked by the linker into well known hardware operated range of memory.
#[link_section="something_wellknown"]
static mut THE_RESOURCE: Resource;
take_resource_lock(x); // later released by the caller once they’re finished with the Resource
&mut THE_RESOURCE
}If it wasn’t for @japaric and WG-embedded, this is how I’d write my embedded code if I wasn’t really interested in exploring the design avenues that exact moment. One interesting idea that came to mind was an ability for rustc to use different default lint levels depending on the target platform. The code above, is infinitely unlikely to occur on hosted targets, so the lint can be enabled there, but not on bare-metal targets where the code might be entirely valid and is quite likely to show up. |
rfcbot
added
proposed-final-comment-period
disposition-merge
labels
Aug 10, 2018
This comment has been minimized.
This comment has been minimized.
Clippy doesn't try to solve this, anything found behind a The robust solution here is to add a
I feel like that's enough of a special case that you'll want to turn it off. Idk. |
This comment has been minimized.
This comment has been minimized.
|
@rfcbot concern naming conventions Lints in rustc follow some naming conventions. |
rfcbot
added
proposed-final-comment-period
disposition-merge
labels
Aug 12, 2018
This comment has been minimized.
This comment has been minimized.
|
I added renaming suggestions to all lints with a checkbox if the name didn't follow the rules |
This comment has been minimized.
This comment has been minimized.
Unless explicitly stated, all lints are as generic as possible. So in the The list is a suggestion by me, not reviewed by anyone else. I am absolutely fine with crossing items off the list if they are too opinionated. |
This comment has been minimized.
This comment has been minimized.
|
I feel vaguely uneasy about this because this is a lot of lints, being uplifted all at once, without very clear (to me) explanation of what rules determine if a lint belongs in the compiler or not. What I'd prefer to do is establish consensus on the guidelines and then entrust other people to make the call on whether individual lints fit those guidelines. |
This comment has been minimized.
This comment has been minimized.
|
The general guidelines suggested by the RFC are
This of course depends on the rules for correctness lints:
Yes this is a very short and general definition, but the space for correctness lints is just too big to create a guideline for them (as evidenced by the variance of the lints in the OP). |
This comment has been minimized.
This comment has been minimized.
|
What I'd prefer to do is establish consensus on the guidelines
We _did_, the clippy RFC outlines the correctness lints as potential
uplifts, they best match the degree of severity and accuracy of rustc lints.
But there are a *lot* of these, so we wanted the compiler team to pick out
the ones they really liked.
…On Tue, Aug 14, 2018 at 8:31 AM boats ***@***.***> wrote:
I feel vaguely uneasy about this because this is a *lot* of lints, being
uplifted all at once, without very clear (to me) explanation of what rules
determine if a lint belongs in the compiler or not.
What I'd prefer to do is establish consensus on the guidelines and then
entrust other people to make the call on whether individual lints fit those
guidelines.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#53224 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABivSBaYBDdF-Z8WngGyjBd0zlZEdxd3ks5uQu01gaJpZM4V15Oa>
.
|
This comment has been minimized.
This comment has been minimized.
I think (I'll take a better look at the others soon.) |
This comment has been minimized.
This comment has been minimized.
|
If I may contribute to the bikeshed a bit, these are the renames I would like to see:
The out_of_bounds_indexing lint should be deprecated now that const_err is warn by default. temporary_cstring_as_ptr seems fine as is. Many of these names were originally proposed by @clarcharr (rust-lang/rust-clippy#2845, rust-lang/rust-clippy#2846). They came up with some naming rules there too. |
This comment has been minimized.
This comment has been minimized.
|
Sorry again for the land grab, but... EDIT: Apparently rfcbot wasn't appreciative; I'll have to fix the bot first ^,- |
This comment has been minimized.
This comment has been minimized.
|
@rfcbot concern infinite_iter I think the |
rfcbot
added
proposed-final-comment-period
disposition-merge
labels
Sep 1, 2018
This comment has been minimized.
This comment has been minimized.
|
I guess you're talking about cases where you're iterating over a receiver? Yeah, that makes sense. @clarcharr Yeah, this sounds great! I don't think there needs to be a rush, and we can rename lints in clippy later too in a backwards compat way. |
This comment has been minimized.
This comment has been minimized.
|
I think |
This comment has been minimized.
This comment has been minimized.
leonardo-m
commented
Sep 2, 2018
|
Are some Clippy (or Rustc warnings) good to become errors (instead of warnings) in future Rust versions? |
This comment has been minimized.
This comment has been minimized.
|
I should add that |
This comment has been minimized.
This comment has been minimized.
leonardo-m
commented
Sep 2, 2018
|
Avoiding one panic caused by zero step sounds good. |
This comment has been minimized.
This comment has been minimized.
|
@nagisa are your concerns resolved? |
This comment has been minimized.
This comment has been minimized.
|
(Reposting a previous comment because rfcbot doesn't take edits into account.) @rfcbot concern overly-aggressive stylistic lints Some of the lints discourage patterns that seem reasonable in practice.
@rfcbot concern possible false positives With the current descriptions, some of the lints seem like they could behave incorrectly in some cases. If these are correct, the descriptions should be updated.
Some other comments, but not blocking concerns.
All the other suggested lints seem sensible to me. |
rfcbot
added
proposed-final-comment-period
disposition-merge
labels
Sep 4, 2018
Manishearth
referenced this issue
Sep 9, 2018
Closed
Lint for function call in `unwrap_or(..)` parameter #2536
This comment has been minimized.
This comment has been minimized.
leonardo-m
commented
Sep 10, 2018
|
Some lints could become errors in Rustc, like: wrong_transmute, |
This comment has been minimized.
This comment has been minimized.
I still think that this is not nearly enough. What I was really looking for is a well thought out list of corner cases (most of the lints’ descriptions neglect to mention even the obvious ones) & some sort of list if pros and cons we could amend as a part of decision making process. Most of the lints only specify the obvious case where they fire, but then there must exist samples of code which are not as clear-cut. Where exactly is the line drawn? I don’t want (and hardly have the attention span) to think about possible corner cases for 50 different lints at once. Since making a decision for this many lints at once is infeasible. Perhaps an issue for each lint or a small number of lints (grouped according to some criteria) would be better, so that discussion does not mix this much? I would be willing to mark my checkbox here provided that the purpose of this tracking issue is to select lints we want to consider for inclusion to rustc, each on their own merit.
There are multiple different approaches we could take, sure. Just like I elaborated above, I think this tracking issue is not a great location to come to a consensus on that. |
This comment has been minimized.
This comment has been minimized.
|
Did I miss a concise list somewhere of "here's why these but not the other are getting uplifted"? Part of me feels that, even where I agree with the lints, that a bunch of these ought to be generalized if they'd go into |
This comment has been minimized.
This comment has been minimized.
JeanMertz
commented
Oct 2, 2018
•
|
If there is an agreement on naming conventions, and the rules that are used to determine if a lint should be uplifted, wouldn't it make more sense to split this issue into one single issue per proposed lint uplift? That way, the discussion can stay focussed on that one lint, potential improvements can be discussed (and linked to PRs implementing that improvement), and when a specific lint is ready to be uplifted, it can be, without blocking on any discussion on other lints that are more debatable. It would also make it easier to link back to decisions in the past for specific lints when talking about them in the future. I'm a bystander here, but interested in this process, and having a hard time with all the different discussions crossing. I'm also concerned that it might leave some concerns unnoticed, because of the noise (although that's less of a concern with the rfcbot keeping track). The obvious downside is having to comment on multiple issues when discussing multiple lints. So this would only make sense if there is an agreement on the general way to move forward with all uplift proposals (so naming convention, level of documentation, and a general set of rules to determine if a lint can be uplifted or not). If there is no such agreement yet, then I would propose to postpone this issue, and figure that out first, in a separate issue, without the noise of talking about specific lint implementations. |
This comment has been minimized.
This comment has been minimized.
|
I very much agree with @JeanMertz and @nagisa here; going through such a large list of lints at once is a daunting task and delays reaching consensus by a lot. I'd much rather we split things up and consider each lint one by one. |
This comment has been minimized.
This comment has been minimized.
|
@rfcbot concern guidelines I agree that trying to filter through these lints in a single thread is unworkable, but I am also not thrilled by the idea of each lint being considered individually without establishing a clear consensus regarding guidelines; that would result in inconsistent decision making. When I brought this up in August, @oli-obk pointed out this guidance from the clippy 1.0 RFC:
This is good guidance, but my interpretation of this guidance would put quite a few of these lints out of the question, especially several of those highlighted in @varkor's previous comment. I'm not certain if this was an oversight or if I am applying the "very low false positive" standard more stringently than other users. My own experience with the compiler is that I essentially never have a false positive warning, and when I do I am doing something really exceptionally strange. For example, I have had to allow dead code for a field that is never accessed because I want its destructor to run when this object is dropped: this is about the only time I've ever had to permanently allow a lint. I would perceive a change to this situation as a real drawback: false positives make me feel (wrongly) less confident about my understanding of the code and whether or not it is correct. On the other hand, I have some objections outside of just the "low false positive" standard. Some of these lints are also indirect, highlighting that your code is probably wrong but without highlighting the problematic code. Take So I think overall the next step should be to determine what the guidelines for correctness lints in the compiler actually are. For me, the requirements I prefer are:
Once we have consensus on the guidelines, people can go through individual lints and make a decision following those guidelines. |
This comment has been minimized.
This comment has been minimized.
leonardo-m
commented
Oct 2, 2018
If it's a bug, then the compiler should raise a compilation error. If we talk about compiler warnings they are allowed to be about things that aren't bugs. |
This comment has been minimized.
This comment has been minimized.
|
Btw, clippy's relicense is going through, so uplifting lints into Rust will be easy now. |
Centril
referenced this issue
Oct 7, 2018
Closed
Take stock of and evaluate the lint situation. #1501
This comment has been minimized.
This comment has been minimized.
|
Would be possible to add #54905 as well? :) |
This comment has been minimized.
This comment has been minimized.
|
To get this unstuck... Perhaps we can "evolve" the guidelines through the first lints we deal with... i.e. let's establish policy through precedent and do it more "by example".
I do think that if the compiler lints and determines that you probably have UB in the function, even if it is indirect, it is better than nothing. While it might not point directly point at the problem and a possible solution, it will hopefully at least make the user raise some questions which then leads to them searching for answers from various resources. The lint can also offer a link which provides more context in the description.
I agree with 2, but I'm not so sure about 1 (for reasons noted below) and 3 (for reasons aforementioned). We already have lints that identifies bad code such as |
oli-obk commentedAug 9, 2018
•
edited by joshtriplett
cc @Manishearth @rust-lang/lang
As discussed in the Clippy 1.0 RFC, we would like to uplift some lints from clippy to rustc. Full rationale can be found in https://github.com/rust-lang/rfcs/blob/b9c8471887f308223c226642cad3a8290731b942/text/0000-clippy-uno.md#compiler-uplift
The list of correctness lints in clippy follows. I have checked the boxes of lints that I think should be uplifted
Renamings happening during uplift have been added via
-> new_nameannotationsforloops overOptionvalues.same_operands: Checks for equal operands to comparison, logical andbitwise, difference and division binary operators (
==,>, etc.,&&,||,&,|,^,-and/).for_val_in_iter_next: Checks for loops onx.next().incorrect_semver_strings: Checks for#[deprecated]annotations with asincefield that is not a valid semantic version.
dropping_copy_types: Checks for calls tostd::mem::dropwith a valuethat derives the Copy trait
deref_ptr_arg_in_safe_fns: Checks for public functions that dereferences raw pointerarguments but are not marked unsafe.
unused_boolean_operands: Checks for boolean expressions that contain terminals thatcan be eliminated.
cloning_references: Checks for usage of.clone()on an&&T.incorrect_swaps: Checks forfoo = bar; bar = foosequences.an array element is a binary operator expression and it lies on two lines.
undefined_transmutes: Checks for transmutes that can't ever be correct on anyarchitecture.
(with
Regex::new,RegexBuilder::neworRegexSet::new) for correctregex syntax.
unused_bitmasks: Checks for incompatible bit masks in comparisons.dropping_references: Checks for calls tostd::mem::dropwith a referenceinstead of an owned value.
Hashbut implementingPartialEqexplicitly or vice versa.
extern crateanduseitems annotated withlint attributes
temporary_cstring_as_ptr: Checks for getting the inner pointer of a temporaryCString.incorrect_clamps: Checks for expressions wherestd::cmp::minandmaxareused to clamp values, but switched so that the result is constant.
unit_comparisons: Checks for comparisons to unit.incorrect_reversed_ranges: Checks for loops over rangesx..ywhere bothxandyare constant and
xis greater or equal toy, unless the range isreversed or has a negative
.step_by(_).x * 0.subtracting elements in an AddAssign impl.
values (apart from zero), except in functions called
*eq*(which probablyimplement equality for a type involving floats).
zero_width_spaces: Checks for the Unicode zero-width space in the code.truncating_fn_ptr_to_int_casts: Checks for casts of a function pointer to a numeric type not large enough to store address.subtracting elements in an Add impl.
constants which are defined in
std::f32::constsor
std::f64::consts,respectively, suggesting to use the predefined constant.
unused_while_loop_conditions: Checks whether variables used within while loop conditioncan be (and are) mutated in the body.
break,returnorcontinuean outer loop.unused_open_options: Checks for duplicate open options as well as combinationsthat make no sense.
forgetting_copy_types: Checks for calls tostd::mem::forgetwith a value thatderives the Copy trait
unused_branching: Checks forif/elsewith the same body as the then partand the else part.
more-strictly-aligned pointer
unused_branching: Checks for consecutiveifs with the same condition.index.
inline_fns_without_body: Checks for#[inline]on trait methods without bodiesunused_comparisons: Checks for comparisons to NaN.without changing the outcome.
infinite_iterators: Checks for iteration that is guaranteed to be infinite.returning_mut_ref_from_ref: This lint checks for functions that take immutablereferences and return
mutable ones.
unused_io_amounts: Checks for unused written/read amount.undefined_references: Checks for creation of references to zeroed or uninitialized memory.forgetting_references: Checks for calls tostd::mem::forgetwith a referenceinstead of an owned value.
unused_comparisons: Checks for comparisons where one side of the relation iseither the minimum or maximum value for its type and warns if it involves a
case that is always true or always false. Only integer and boolean types are
checked.
forloops overResultvalues.iter_step_by_zero: Checks for calling.step_by(0)on iterators,which never terminates.
repr(isize/usize)and have values that don't fit into ani32.