-
Notifications
You must be signed in to change notification settings - Fork 13.3k
For E0277 on for
loops, point at the "head" expression
#47690
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 all commits
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// E0277 should point exclusively at line 14, not the entire for loop span | ||
|
||
fn main() { | ||
for c in "asdf" { | ||
//~^ ERROR the trait bound `&str: std::iter::Iterator` is not satisfied | ||
//~| NOTE `&str` is not an iterator | ||
//~| HELP the trait `std::iter::Iterator` is not implemented for `&str` | ||
//~| NOTE required by `std::iter::IntoIterator::into_iter` | ||
println!(""); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error[E0277]: the trait bound `&str: std::iter::Iterator` is not satisfied | ||
--> $DIR/for-c-in-str.rs:14:14 | ||
| | ||
14 | for c in "asdf" { | ||
| ^^^^^^ `&str` is not an iterator; maybe try calling `.iter()` or a similar method | ||
| | ||
= help: the trait `std::iter::Iterator` is not implemented for `&str` | ||
= note: required by `std::iter::IntoIterator::into_iter` | ||
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. it'd be cool if we could highlight the 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. I agree. That will require some extra changes to |
||
|
||
error: aborting due to previous error | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,7 @@ error[E0277]: the `?` operator can only be used in a function that returns `Resu | |
--> $DIR/try-operator-on-main.rs:19:5 | ||
| | ||
19 | std::fs::File::open("foo")?; //~ ERROR the `?` operator can only | ||
| --------------------------- | ||
| | | ||
| cannot use the `?` operator in a function that returns `()` | ||
| in this macro invocation | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot use the `?` operator in a function that returns `()` | ||
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. nice drive-by fix here 🚗 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. 😎 |
||
| | ||
= help: the trait `std::ops::Try` is not implemented for `()` | ||
= note: required by `std::ops::Try::from_error` | ||
|
@@ -14,10 +11,7 @@ error[E0277]: the `?` operator can only be applied to values that implement `std | |
--> $DIR/try-operator-on-main.rs:22:5 | ||
| | ||
22 | ()?; //~ ERROR the `?` operator can only | ||
| --- | ||
| | | ||
| the `?` operator cannot be applied to type `()` | ||
| in this macro invocation | ||
| ^^^ the `?` operator cannot be applied to type `()` | ||
| | ||
= help: the trait `std::ops::Try` is not implemented for `()` | ||
= note: required by `std::ops::Try::into_result` | ||
|
@@ -38,10 +32,7 @@ error[E0277]: the `?` operator can only be applied to values that implement `std | |
--> $DIR/try-operator-on-main.rs:32:5 | ||
| | ||
32 | ()?; //~ ERROR the `?` operator can only | ||
| --- | ||
| | | ||
| the `?` operator cannot be applied to type `()` | ||
| in this macro invocation | ||
| ^^^ the `?` operator cannot be applied to type `()` | ||
| | ||
= help: the trait `std::ops::Try` is not implemented for `()` | ||
= note: required by `std::ops::Try::into_result` | ||
|
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.
nice