-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add filtering option to rustc_on_unimplemented
and reword Iterator
E0277 errors
#54946
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
Changes from 6 commits
cd7c818
5b0223e
330b7ed
2305d02
a0fd68b
c71228e
5beeb53
def0f54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,11 +30,56 @@ fn _assert_is_object_safe(_: &dyn Iterator<Item=()>) {} | |
/// [impl]: index.html#implementing-iterator | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[rustc_on_unimplemented( | ||
on( | ||
_Self="[std::ops::Range<Idx>; 1]", | ||
label="if you meant to iterate between two values, remove the square brackets", | ||
note="`[start..end]` is an array of one `Range`; you might have meant to have a `Range` \ | ||
without the brackets: `start..end`" | ||
), | ||
on( | ||
_Self="[std::ops::RangeFrom<Idx>; 1]", | ||
label="if you meant to iterate from a value onwards, remove the square brackets", | ||
note="`[start..]` is an array of one `RangeFrom`; you might have meant to have a \ | ||
`RangeFrom` without the brackets: `start..`" | ||
), | ||
on( | ||
_Self="[std::ops::RangeTo<Idx>; 1]", | ||
label="if you meant to iterate until a value, remove the square brackets", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can't iterate over a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're absolutely right, I just never had thought about it enough to look it up. I will still add a note to it in order to let users know that. |
||
note="`[..end]` is an array of one `RangeTo`; you might have meant to have a \ | ||
`RangeTo` without the brackets: `..end`" | ||
), | ||
on( | ||
_Self="[std::ops::RangeInclusive<Idx>; 1]", | ||
label="if you meant to iterate between two values, remove the square brackets", | ||
note="`[start..=end]` is an array of one `RangeInclusive`; you might have meant to have a \ | ||
`RangeInclusive` without the brackets: `start..=end`" | ||
), | ||
on( | ||
_Self="[std::ops::RangeToInclusive<Idx>; 1]", | ||
label="if you meant to iterate until a value, remove the square brackets", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same with |
||
note="`[..=end]` is an array of one `RangeToInclusive`; you might have meant to have a \ | ||
`RangeToInclusive` without the brackets: `..=end`" | ||
), | ||
on( | ||
_Self="&str", | ||
label="`{Self}` is not an iterator; try calling `.chars()` or `.bytes()`" | ||
), | ||
label="`{Self}` is not an iterator; maybe try calling `.iter()` or a similar method" | ||
on( | ||
_Self="std::string::String", | ||
label="`{Self}` is not an iterator; try calling `.chars()` or `.bytes()`" | ||
), | ||
on( | ||
_Self="[]", | ||
label="borrow the array with `&` or call `.iter()` on it to iterate over it", | ||
note="arrays are not an iterators, but slices like the following are: `&[1, 2, 3]`" | ||
), | ||
on( | ||
_Self="{integral}", | ||
note="if you want to iterate between `start` until a value `end`, use the exclusive range \ | ||
syntax `start..end` or the inclusive range syntax `start..=end`" | ||
), | ||
label="`{Self}` is not an iterator", | ||
message="`{Self}` is not an iterator" | ||
)] | ||
#[doc(spotlight)] | ||
pub trait Iterator { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
trait Wrap<'b> { | ||
fn foo(&'b mut self); | ||
} | ||
|
||
struct Wrapper<P>(P); | ||
|
||
impl<'b, P> Wrap<'b> for Wrapper<P> | ||
where P: Process<'b>, | ||
<P as Process<'b>>::Item: Iterator { | ||
fn foo(&mut self) {} | ||
} | ||
|
||
|
||
pub trait Process<'a> { | ||
type Item; | ||
fn bar(&'a self); | ||
} | ||
|
||
fn push_process<P>(process: P) where P: Process<'static> { | ||
let _: Box<for<'b> Wrap<'b>> = Box::new(Wrapper(process)); | ||
} | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
error[E0277]: the trait bound `for<'b> P: Process<'b>` is not satisfied | ||
--> $DIR/issue-22872.rs:20:36 | ||
| | ||
LL | let _: Box<for<'b> Wrap<'b>> = Box::new(Wrapper(process)); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `for<'b> Process<'b>` is not implemented for `P` | ||
| | ||
= help: consider adding a `where for<'b> P: Process<'b>` bound | ||
= note: required because of the requirements on the impl of `for<'b> Wrap<'b>` for `Wrapper<P>` | ||
= note: required for the cast to the object type `dyn for<'b> Wrap<'b>` | ||
|
||
error[E0277]: `<P as Process<'b>>::Item` is not an iterator | ||
--> $DIR/issue-22872.rs:20:36 | ||
| | ||
LL | let _: Box<for<'b> Wrap<'b>> = Box::new(Wrapper(process)); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ `<P as Process<'b>>::Item` is not an iterator | ||
| | ||
= help: the trait `for<'b> std::iter::Iterator` is not implemented for `<P as Process<'b>>::Item` | ||
= note: required because of the requirements on the impl of `for<'b> Wrap<'b>` for `Wrapper<P>` | ||
= note: required for the cast to the object type `dyn for<'b> Wrap<'b>` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
fn main() { | ||
for _ in [0..1] {} | ||
let start = 0; | ||
let end = 0; | ||
for _ in [start..end] {} | ||
let array_of_range = [start..end]; | ||
for _ in array_of_range {} | ||
for _ in [0..1, 2..3] {} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.