-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when appliedL-suggestionLint: Improving, adding or fixing lint suggestionsLint: Improving, adding or fixing lint suggestions
Description
The range_plus_one
lint suggests replacing Range
syntax with RangeInclusive
syntax. That's fine if you're immediately going to loop. But it's invalid if the Range
in question is going to be assigned to a variable of type Range
. For example, clippy will suggest replacing this code:
struct Foo {
r: Range<u32>
}
fn bar() {
let x = 0;
let foo = Foo{r: x..x+1};
}
with this:
struct Foo {
r: Range<u32>
}
fn bar() {
let x = 0;
let foo = Foo{r: x..=x};
}
But that fails to compile
2263 | let foo = Foo{r: x..=x};
| ^^^^^ expected struct `std::ops::Range`, found struct `std::ops::RangeInclusive`
|
= note: expected type `std::ops::Range<u32>`
found type `std::ops::RangeInclusive<{integer}>`
clippy 0.0.212 (32b1d1fc 2018-10-05)
djc, LunaBorowska, jonasbb, rocurley, adrienball and 11 more
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when appliedL-suggestionLint: Improving, adding or fixing lint suggestionsLint: Improving, adding or fixing lint suggestions
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
jonasbb commentedon Dec 6, 2018
Another example using rayon:
The following program compiles, but clippy produces a warning on it:
The warning is:
However, applying the suggestion results in the following error:
See also the rayon documentation for ranges.
oxalica commentedon May 26, 2019
+1 for this issue.
I also met it when calling a function requiring
Range
. Example:I don't think implementing a generic function for all ranges would be always better.
flip1995 commentedon Dec 22, 2019
Citing #4898 to keep traack of this in a single issue:
So the same problem exists the other way around.
[-]range_plus_one lint wrongly suggests using RangeInclusive when Range is required[/-][+]range_plus_one lint wrongly suggests using RangeInclusive when Range is required and the other way around[/+]kvark commentedon Dec 31, 2019
We hit this in gfx-rs since the code expects
Range
specifically and fails upon turning the expression intoRangeInclusive
.jyn514 commentedon Jan 13, 2020
This also happens when returning a value from a function.
krishna-veerareddy commentedon Jan 24, 2020
@flip1995 Hey I would like to tackle this one but I am not sure how we would know if the type of an expression can be changed or not. Any suggestions?
22 remaining items