diff options
| author | bors <bors@rust-lang.org> | 2018-01-27 08:04:12 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-01-27 08:04:12 +0000 |
| commit | 6272b60dcaae2e69c991fc64cfb2e403c8a616a3 (patch) | |
| tree | c07e40f847e804b187a35aa2b36ca94faffd92da /src/test | |
| parent | 5c41fcec4cd6e76180edb088a48914aa71612e5d (diff) | |
| parent | 106e5c554d6b6b97aecac254a2694247e84e718e (diff) | |
| download | rust-6272b60dcaae2e69c991fc64cfb2e403c8a616a3.tar.gz rust-6272b60dcaae2e69c991fc64cfb2e403c8a616a3.zip | |
Auto merge of #47690 - estebank:for-block-277, r=nikomatsakis
For E0277 on `for` loops, point at the "head" expression When E0277's span points at a `for` loop, the actual issue is in the element being iterated. Instead of pointing at the entire loop, point only at the first line (when possible) so that the span ends in the element for which E0277 was triggered.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/compile-fail/issue-20605.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/const-fn-error.stderr | 18 | ||||
| -rw-r--r-- | src/test/ui/issue-33941.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/suggestions/for-c-in-str.rs | 21 | ||||
| -rw-r--r-- | src/test/ui/suggestions/for-c-in-str.stderr | 11 | ||||
| -rw-r--r-- | src/test/ui/suggestions/try-on-option.stderr | 5 | ||||
| -rw-r--r-- | src/test/ui/suggestions/try-operator-on-main.stderr | 15 |
7 files changed, 45 insertions, 31 deletions
diff --git a/src/test/compile-fail/issue-20605.rs b/src/test/compile-fail/issue-20605.rs index b7c544c7848..5eb0e4360fc 100644 --- a/src/test/compile-fail/issue-20605.rs +++ b/src/test/compile-fail/issue-20605.rs @@ -10,7 +10,7 @@ fn changer<'a>(mut things: Box<Iterator<Item=&'a mut u8>>) { for item in *things { *item = 0 } -//~^ ERROR `std::iter::Iterator<Item=&mut u8>: std::marker::Sized` is not satisfied +//~^ ERROR the trait bound `std::iter::Iterator<Item=&mut u8>: std::marker::Sized` is not satisfied } fn main() {} diff --git a/src/test/ui/const-fn-error.stderr b/src/test/ui/const-fn-error.stderr index 0e275e78fc6..4f4f8b5ad00 100644 --- a/src/test/ui/const-fn-error.stderr +++ b/src/test/ui/const-fn-error.stderr @@ -13,22 +13,16 @@ error[E0016]: blocks in constant functions are limited to items and tail express | ^ error[E0015]: calls in constant functions are limited to constant functions, struct and enum constructors - --> $DIR/const-fn-error.rs:17:5 + --> $DIR/const-fn-error.rs:17:14 | -17 | / for i in 0..x { //~ ERROR calls in constant functions -18 | | //~| ERROR constant function contains unimplemented -19 | | sum += i; -20 | | } - | |_____^ +17 | for i in 0..x { //~ ERROR calls in constant functions + | ^^^^ error[E0019]: constant function contains unimplemented expression type - --> $DIR/const-fn-error.rs:17:5 + --> $DIR/const-fn-error.rs:17:14 | -17 | / for i in 0..x { //~ ERROR calls in constant functions -18 | | //~| ERROR constant function contains unimplemented -19 | | sum += i; -20 | | } - | |_____^ +17 | for i in 0..x { //~ ERROR calls in constant functions + | ^^^^ error[E0080]: constant evaluation error --> $DIR/const-fn-error.rs:21:5 diff --git a/src/test/ui/issue-33941.stderr b/src/test/ui/issue-33941.stderr index 953e6fe77d7..78c9ce9a1b1 100644 --- a/src/test/ui/issue-33941.stderr +++ b/src/test/ui/issue-33941.stderr @@ -8,10 +8,10 @@ error[E0271]: type mismatch resolving `<std::collections::hash_map::Iter<'_, _, found type `&_` error[E0271]: type mismatch resolving `<std::collections::hash_map::Iter<'_, _, _> as std::iter::Iterator>::Item == &_` - --> $DIR/issue-33941.rs:14:5 + --> $DIR/issue-33941.rs:14:14 | 14 | for _ in HashMap::new().iter().cloned() {} //~ ERROR type mismatch - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected tuple, found reference + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected tuple, found reference | = note: expected type `(&_, &_)` found type `&_` diff --git a/src/test/ui/suggestions/for-c-in-str.rs b/src/test/ui/suggestions/for-c-in-str.rs new file mode 100644 index 00000000000..011886e8073 --- /dev/null +++ b/src/test/ui/suggestions/for-c-in-str.rs @@ -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!(""); + } +} diff --git a/src/test/ui/suggestions/for-c-in-str.stderr b/src/test/ui/suggestions/for-c-in-str.stderr new file mode 100644 index 00000000000..7a6dc9a5040 --- /dev/null +++ b/src/test/ui/suggestions/for-c-in-str.stderr @@ -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` + +error: aborting due to previous error + diff --git a/src/test/ui/suggestions/try-on-option.stderr b/src/test/ui/suggestions/try-on-option.stderr index b1be9ad3cf6..dfe950818e7 100644 --- a/src/test/ui/suggestions/try-on-option.stderr +++ b/src/test/ui/suggestions/try-on-option.stderr @@ -10,10 +10,7 @@ error[E0277]: the `?` operator can only be used in a function that returns `Resu --> $DIR/try-on-option.rs:23:5 | 23 | x?; //~ the `?` operator - | -- - | | - | cannot use the `?` operator in a function that returns `u32` - | in this macro invocation + | ^^ cannot use the `?` operator in a function that returns `u32` | = help: the trait `std::ops::Try` is not implemented for `u32` = note: required by `std::ops::Try::from_error` diff --git a/src/test/ui/suggestions/try-operator-on-main.stderr b/src/test/ui/suggestions/try-operator-on-main.stderr index 3b32b4a9eb7..e97823a3d5d 100644 --- a/src/test/ui/suggestions/try-operator-on-main.stderr +++ b/src/test/ui/suggestions/try-operator-on-main.stderr @@ -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 `()` | = 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` |
