-
Couldn't load subscription status.
- Fork 13.9k
Suggest add bounding value for RangeTo #147753
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
Open
chenyukang
wants to merge
1
commit into
rust-lang:master
Choose a base branch
from
chenyukang:yukang-147749
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+207
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
tests/ui/range/range-to-iterator-suggestion-issue-147749.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| fn main() { | ||
| for x in (..4).rev() { | ||
| //~^ ERROR `RangeTo<{integer}>` is not an iterator | ||
| //~| HELP consider using a bounded `Range` by adding a concrete starting value | ||
| let _ = x; | ||
| } | ||
|
|
||
| for x in (..=4).rev() { | ||
| //~^ ERROR `std::ops::RangeToInclusive<{integer}>` is not an iterator | ||
| //~| HELP consider using a bounded `RangeInclusive` by adding a concrete starting value | ||
| let _ = x; | ||
| } | ||
|
|
||
| // should not suggest for `iter` method | ||
| let _v: Vec<_> = (..5).iter().collect(); | ||
| //~^ ERROR no method named `iter` found | ||
|
|
||
| for _x in (..'a').rev() {} | ||
| //~^ ERROR `RangeTo<char>` is not an iterator | ||
| //~| HELP consider using a bounded `Range` by adding a concrete starting value | ||
|
|
||
| for _x in (..='a').rev() {} | ||
| //~^ ERROR `std::ops::RangeToInclusive<char>` is not an iterator | ||
| //~| HELP consider using a bounded `RangeInclusive` by adding a concrete starting value | ||
|
|
||
| for _x in (..-10).rev() {} | ||
| //~^ ERROR `RangeTo<{integer}>` is not an iterator | ||
| //~| HELP consider using a bounded `Range` by adding a concrete starting value | ||
|
|
||
| for _x in (..=-10).rev() {} | ||
| //~^ ERROR `std::ops::RangeToInclusive<{integer}>` is not an iterator | ||
| //~| HELP consider using a bounded `RangeInclusive` by adding a concrete starting value | ||
| } |
99 changes: 99 additions & 0 deletions
99
tests/ui/range/range-to-iterator-suggestion-issue-147749.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| error[E0599]: `RangeTo<{integer}>` is not an iterator | ||
| --> $DIR/range-to-iterator-suggestion-issue-147749.rs:2:20 | ||
| | | ||
| LL | for x in (..4).rev() { | ||
| | ^^^ `RangeTo<{integer}>` is not an iterator | ||
| | | ||
| = note: the following trait bounds were not satisfied: | ||
| `RangeTo<{integer}>: Iterator` | ||
| which is required by `&mut RangeTo<{integer}>: Iterator` | ||
| = note: you might have meant to use a bounded `Range` | ||
| help: consider using a bounded `Range` by adding a concrete starting value | ||
| | | ||
| LL | for x in (0..4).rev() { | ||
| | + | ||
chenyukang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| error[E0599]: `std::ops::RangeToInclusive<{integer}>` is not an iterator | ||
| --> $DIR/range-to-iterator-suggestion-issue-147749.rs:8:21 | ||
| | | ||
| LL | for x in (..=4).rev() { | ||
| | ^^^ `std::ops::RangeToInclusive<{integer}>` is not an iterator | ||
| | | ||
| = note: the following trait bounds were not satisfied: | ||
| `std::ops::RangeToInclusive<{integer}>: Iterator` | ||
| which is required by `&mut std::ops::RangeToInclusive<{integer}>: Iterator` | ||
| = note: you might have meant to use a bounded `RangeInclusive` | ||
| help: consider using a bounded `RangeInclusive` by adding a concrete starting value | ||
| | | ||
| LL | for x in (0..=4).rev() { | ||
| | + | ||
|
|
||
| error[E0599]: no method named `iter` found for struct `RangeTo<Idx>` in the current scope | ||
| --> $DIR/range-to-iterator-suggestion-issue-147749.rs:15:28 | ||
| | | ||
| LL | let _v: Vec<_> = (..5).iter().collect(); | ||
| | ^^^^ method not found in `RangeTo<{integer}>` | ||
|
|
||
| error[E0599]: `RangeTo<char>` is not an iterator | ||
| --> $DIR/range-to-iterator-suggestion-issue-147749.rs:18:23 | ||
| | | ||
| LL | for _x in (..'a').rev() {} | ||
| | ^^^ `RangeTo<char>` is not an iterator | ||
| | | ||
| = note: the following trait bounds were not satisfied: | ||
| `RangeTo<char>: Iterator` | ||
| which is required by `&mut RangeTo<char>: Iterator` | ||
| = note: you might have meant to use a bounded `Range` | ||
| help: consider using a bounded `Range` by adding a concrete starting value | ||
| | | ||
| LL | for _x in (/* start */..'a').rev() {} | ||
| | +++++++++++ | ||
|
|
||
| error[E0599]: `std::ops::RangeToInclusive<char>` is not an iterator | ||
| --> $DIR/range-to-iterator-suggestion-issue-147749.rs:22:24 | ||
| | | ||
| LL | for _x in (..='a').rev() {} | ||
| | ^^^ `std::ops::RangeToInclusive<char>` is not an iterator | ||
| | | ||
| = note: the following trait bounds were not satisfied: | ||
| `std::ops::RangeToInclusive<char>: Iterator` | ||
| which is required by `&mut std::ops::RangeToInclusive<char>: Iterator` | ||
| = note: you might have meant to use a bounded `RangeInclusive` | ||
| help: consider using a bounded `RangeInclusive` by adding a concrete starting value | ||
| | | ||
| LL | for _x in (/* start */..='a').rev() {} | ||
| | +++++++++++ | ||
|
|
||
| error[E0599]: `RangeTo<{integer}>` is not an iterator | ||
| --> $DIR/range-to-iterator-suggestion-issue-147749.rs:26:23 | ||
| | | ||
| LL | for _x in (..-10).rev() {} | ||
| | ^^^ `RangeTo<{integer}>` is not an iterator | ||
| | | ||
| = note: the following trait bounds were not satisfied: | ||
| `RangeTo<{integer}>: Iterator` | ||
| which is required by `&mut RangeTo<{integer}>: Iterator` | ||
| = note: you might have meant to use a bounded `Range` | ||
| help: consider using a bounded `Range` by adding a concrete starting value | ||
| | | ||
| LL | for _x in (/* start */..-10).rev() {} | ||
| | +++++++++++ | ||
|
|
||
| error[E0599]: `std::ops::RangeToInclusive<{integer}>` is not an iterator | ||
| --> $DIR/range-to-iterator-suggestion-issue-147749.rs:30:24 | ||
| | | ||
| LL | for _x in (..=-10).rev() {} | ||
| | ^^^ `std::ops::RangeToInclusive<{integer}>` is not an iterator | ||
| | | ||
| = note: the following trait bounds were not satisfied: | ||
| `std::ops::RangeToInclusive<{integer}>: Iterator` | ||
| which is required by `&mut std::ops::RangeToInclusive<{integer}>: Iterator` | ||
| = note: you might have meant to use a bounded `RangeInclusive` | ||
| help: consider using a bounded `RangeInclusive` by adding a concrete starting value | ||
| | | ||
| LL | for _x in (/* start */..=-10).rev() {} | ||
| | +++++++++++ | ||
|
|
||
| error: aborting due to 7 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0599`. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should only suggest
0if the element type is integral.Right now, you suggest
(0..'f').rev()for(..'f').rev(). This affects all types that implement theSteptrait and aren't integral.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, should it be 0 if the element is signed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, it's not good to suggest
(0..-10), so I changed the code to only suggest0for integral and without negative sign, otherwise suggest a place hold_, not sure this is the best way, but I didn't come out with a better one.it's complex to handle all scenario, for instance the code maybe
(...val), while val is a negative value or some other types..anyway, this is a
MaybeIncorrectsuggestion.