-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Uplift lints from clippy to rustc #53224
Comments
@rfcbot fcp merge please raise concerns about specific lints directly with rfcbot |
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. |
https://rust-lang-nursery.github.io/rust-clippy/master/index.html#unused_io_amount seems like it should be replaced with a |
cc @rust-lang/compiler |
@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. |
The problem is not that the return value is unused, it is usually used via |
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 |
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. |
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. |
@rfcbot concern naming conventions Lints in rustc follow some naming conventions. |
I added renaming suggestions to all lints with a checkbox if the name didn't follow the rules |
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. |
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. |
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). |
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>
.
|
I think (I'll take a better look at the others soon.) |
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. |
Sorry again for the land grab, but... EDIT: Apparently rfcbot wasn't appreciative; I'll have to fix the bot first ^,- |
Would be possible to add #54905 as well? :) |
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 |
What's the current state of this? What are the next steps? Is the plan to uplift clippy lints one by one? (Is there a finalized list?) Does anyone want to take on the tasks of 1) working through the concerns one by one and 2) updating the RFC accordingly? (Is that the right next step here?) |
imo that's the only feasible way to get this thing through. I think we should go through each lint one by one in a separate issue with FCPs and then gradually coalesce around a way of applying our policy. That seems more efficient... we don't have to treat the lints as a package deal. |
@rfcbot close We discussed this sometime ago on a language team meeting and came to the conclusion that we don't think considering all lints together is going anywhere. Rather, we would be open to people filing issues or PRs to uplift particular lints on a case-by-case basis. When doing so, please the language team (@rust-lang/lang) and possibly also the compiler team. If you cannot ping the entire team, ping some folks in it and we can forward it. In some cases, we might just accept a PR or we might start a language team FCP. When deciding on whether to file a PR or issue, consider however that we might not accept all uplifts. I'm leaving this issue open as a tracking issue. |
Oops... wrong command; @rfcbot cancel |
@Centril proposal cancelled. |
Should we close this? |
It might be worth opening a separate tracking issue that tracks these things, though. |
…-obk Uplift `temporary-cstring-as-ptr` lint from `clippy` into rustc The general consensus seems to be that this lint covers a common enough mistake to warrant inclusion in rustc. The diagnostic message might need some tweaking, as I'm not sure the use of second-person perspective matches the rest of rustc, but I'd like to hear others' thoughts on that. (cc rust-lang#53224). r? @oli-obk
Uplift `temporary-cstring-as-ptr` lint from `clippy` into rustc The general consensus seems to be that this lint covers a common enough mistake to warrant inclusion in rustc. The diagnostic message might need some tweaking, as I'm not sure the use of second-person perspective matches the rest of rustc, but I'd like to hear others' thoughts on that. (cc rust-lang#53224). r? `@oli-obk`
…lints, r=fee1-dead Rename `{drop,forget}_{copy,ref}` lints to more consistent naming This PR renames previous uplifted lints in rust-lang#109732 to more consistent naming. I followed the renaming done [here](rust-lang#53224) and also advocated in this [clippy issue](rust-lang/rust-clippy#2845): - `drop_copy` to `dropping_copy_types` - `forget_copy` to `forgetting_copy_types` - `drop_ref` to `dropping_references` - `forget_ref` to `forgetting_references`
…fee1-dead Rename `{drop,forget}_{copy,ref}` lints to more consistent naming This PR renames previous uplifted lints in rust-lang/rust#109732 to more consistent naming. I followed the renaming done [here](rust-lang/rust#53224) and also advocated in this [clippy issue](rust-lang/rust-clippy#2845): - `drop_copy` to `dropping_copy_types` - `forget_copy` to `forgetting_copy_types` - `drop_ref` to `dropping_references` - `forget_ref` to `forgetting_references`
…fee1-dead Rename `{drop,forget}_{copy,ref}` lints to more consistent naming This PR renames previous uplifted lints in rust-lang/rust#109732 to more consistent naming. I followed the renaming done [here](rust-lang/rust#53224) and also advocated in this [clippy issue](rust-lang/rust-clippy#2845): - `drop_copy` to `dropping_copy_types` - `forget_copy` to `forgetting_copy_types` - `drop_ref` to `dropping_references` - `forget_ref` to `forgetting_references`
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_name
annotationsfor
loops overOption
values.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 asince
field that is not a valid semantic version.
dropping_copy_types
: Checks for calls tostd::mem::drop
with 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 = foo
sequences.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::new
orRegexSet::new
) for correctregex syntax.
unused_bitmasks
: Checks for incompatible bit masks in comparisons.dropping_references
: Checks for calls tostd::mem::drop
with a referenceinstead of an owned value.
Hash
but implementingPartialEq
explicitly or vice versa.
extern crate
anduse
items annotated withlint attributes
temporary_cstring_as_ptr
: Checks for getting the inner pointer of a temporaryCString
.incorrect_clamps
: Checks for expressions wherestd::cmp::min
andmax
areused 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..y
where bothx
andy
are constant and
x
is 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::consts
or
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
,return
orcontinue
an 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::forget
with a value thatderives the Copy trait
unused_branching
: Checks forif/else
with the same body as the then partand the else part.
more-strictly-aligned pointer
unused_branching
: Checks for consecutiveif
s 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::forget
with 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.
for
loops overResult
values.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
.The text was updated successfully, but these errors were encountered: