summaryrefslogtreecommitdiffstats
path: root/src/test/ui/for
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/ui/for')
-rw-r--r--src/test/ui/for/for-c-in-str.rs14
-rw-r--r--src/test/ui/for/for-c-in-str.stderr12
-rw-r--r--src/test/ui/for/for-expn.rs9
-rw-r--r--src/test/ui/for/for-expn.stderr9
-rw-r--r--src/test/ui/for/for-loop-bogosity.rs21
-rw-r--r--src/test/ui/for/for-loop-bogosity.stderr12
-rw-r--r--src/test/ui/for/for-loop-refutable-pattern-error-message.rs3
-rw-r--r--src/test/ui/for/for-loop-refutable-pattern-error-message.stderr11
-rw-r--r--src/test/ui/for/for-loop-type-error.rs6
-rw-r--r--src/test/ui/for/for-loop-type-error.stderr11
-rw-r--r--src/test/ui/for/for-loop-unconstrained-element-type.rs9
-rw-r--r--src/test/ui/for/for-loop-unconstrained-element-type.stderr14
12 files changed, 131 insertions, 0 deletions
diff --git a/src/test/ui/for/for-c-in-str.rs b/src/test/ui/for/for-c-in-str.rs
new file mode 100644
index 000000000..86a1c1a34
--- /dev/null
+++ b/src/test/ui/for/for-c-in-str.rs
@@ -0,0 +1,14 @@
+// E0277 should point exclusively at line 6, not the entire for loop span
+
+fn main() {
+ for c in "asdf" {
+ //~^ ERROR `&str` is not an iterator
+ //~| NOTE `&str` is not an iterator
+ //~| HELP the trait `Iterator` is not implemented for `&str`
+ //~| NOTE required because of the requirements on the impl of `IntoIterator` for `&str`
+ //~| NOTE in this expansion of desugaring of `for` loop
+ //~| NOTE in this expansion of desugaring of `for` loop
+ //~| NOTE in this expansion of desugaring of `for` loop
+ println!();
+ }
+}
diff --git a/src/test/ui/for/for-c-in-str.stderr b/src/test/ui/for/for-c-in-str.stderr
new file mode 100644
index 000000000..07ddc8ea7
--- /dev/null
+++ b/src/test/ui/for/for-c-in-str.stderr
@@ -0,0 +1,12 @@
+error[E0277]: `&str` is not an iterator
+ --> $DIR/for-c-in-str.rs:4:14
+ |
+LL | for c in "asdf" {
+ | ^^^^^^ `&str` is not an iterator; try calling `.chars()` or `.bytes()`
+ |
+ = help: the trait `Iterator` is not implemented for `&str`
+ = note: required because of the requirements on the impl of `IntoIterator` for `&str`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/for/for-expn.rs b/src/test/ui/for/for-expn.rs
new file mode 100644
index 000000000..b9c4bbeda
--- /dev/null
+++ b/src/test/ui/for/for-expn.rs
@@ -0,0 +1,9 @@
+// Test that an error on a sub-expresson in a for loop has the correct span.
+
+fn main() {
+ // Odd formatting to make sure we get the right span.
+ for t in &
+ foo //~ ERROR cannot find value `foo` in this scope
+ {
+ }
+}
diff --git a/src/test/ui/for/for-expn.stderr b/src/test/ui/for/for-expn.stderr
new file mode 100644
index 000000000..cdb211555
--- /dev/null
+++ b/src/test/ui/for/for-expn.stderr
@@ -0,0 +1,9 @@
+error[E0425]: cannot find value `foo` in this scope
+ --> $DIR/for-expn.rs:6:7
+ |
+LL | foo
+ | ^^^ not found in this scope
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0425`.
diff --git a/src/test/ui/for/for-loop-bogosity.rs b/src/test/ui/for/for-loop-bogosity.rs
new file mode 100644
index 000000000..9341dea09
--- /dev/null
+++ b/src/test/ui/for/for-loop-bogosity.rs
@@ -0,0 +1,21 @@
+struct MyStruct {
+ x: isize,
+ y: isize,
+}
+
+impl MyStruct {
+ fn next(&mut self) -> Option<isize> {
+ Some(self.x)
+ }
+}
+
+pub fn main() {
+ let mut bogus = MyStruct {
+ x: 1,
+ y: 2,
+ };
+ for x in bogus {
+ //~^ ERROR `MyStruct` is not an iterator
+ drop(x);
+ }
+}
diff --git a/src/test/ui/for/for-loop-bogosity.stderr b/src/test/ui/for/for-loop-bogosity.stderr
new file mode 100644
index 000000000..0bdd75b35
--- /dev/null
+++ b/src/test/ui/for/for-loop-bogosity.stderr
@@ -0,0 +1,12 @@
+error[E0277]: `MyStruct` is not an iterator
+ --> $DIR/for-loop-bogosity.rs:17:14
+ |
+LL | for x in bogus {
+ | ^^^^^ `MyStruct` is not an iterator
+ |
+ = help: the trait `Iterator` is not implemented for `MyStruct`
+ = note: required because of the requirements on the impl of `IntoIterator` for `MyStruct`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/for/for-loop-refutable-pattern-error-message.rs b/src/test/ui/for/for-loop-refutable-pattern-error-message.rs
new file mode 100644
index 000000000..221951c87
--- /dev/null
+++ b/src/test/ui/for/for-loop-refutable-pattern-error-message.rs
@@ -0,0 +1,3 @@
+fn main() {
+ for &1 in [1].iter() {} //~ ERROR refutable pattern in `for` loop binding
+}
diff --git a/src/test/ui/for/for-loop-refutable-pattern-error-message.stderr b/src/test/ui/for/for-loop-refutable-pattern-error-message.stderr
new file mode 100644
index 000000000..20b689aa5
--- /dev/null
+++ b/src/test/ui/for/for-loop-refutable-pattern-error-message.stderr
@@ -0,0 +1,11 @@
+error[E0005]: refutable pattern in `for` loop binding: `&i32::MIN..=0_i32` and `&2_i32..=i32::MAX` not covered
+ --> $DIR/for-loop-refutable-pattern-error-message.rs:2:9
+ |
+LL | for &1 in [1].iter() {}
+ | ^^ patterns `&i32::MIN..=0_i32` and `&2_i32..=i32::MAX` not covered
+ |
+ = note: the matched value is of type `&i32`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0005`.
diff --git a/src/test/ui/for/for-loop-type-error.rs b/src/test/ui/for/for-loop-type-error.rs
new file mode 100644
index 000000000..8d9fc20f0
--- /dev/null
+++ b/src/test/ui/for/for-loop-type-error.rs
@@ -0,0 +1,6 @@
+pub fn main() {
+ let x = () + (); //~ ERROR cannot add `()` to `()`
+
+ // this shouldn't have a flow-on error:
+ for _ in x {}
+}
diff --git a/src/test/ui/for/for-loop-type-error.stderr b/src/test/ui/for/for-loop-type-error.stderr
new file mode 100644
index 000000000..c93a3b9b2
--- /dev/null
+++ b/src/test/ui/for/for-loop-type-error.stderr
@@ -0,0 +1,11 @@
+error[E0369]: cannot add `()` to `()`
+ --> $DIR/for-loop-type-error.rs:2:16
+ |
+LL | let x = () + ();
+ | -- ^ -- ()
+ | |
+ | ()
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0369`.
diff --git a/src/test/ui/for/for-loop-unconstrained-element-type.rs b/src/test/ui/for/for-loop-unconstrained-element-type.rs
new file mode 100644
index 000000000..0c7a3516a
--- /dev/null
+++ b/src/test/ui/for/for-loop-unconstrained-element-type.rs
@@ -0,0 +1,9 @@
+// Test that `for` loops don't introduce artificial
+// constraints on the type of the binding (`i`).
+// Subtle changes in the desugaring can cause the
+// type of elements in the vector to (incorrectly)
+// fallback to `!` or `()`.
+
+fn main() {
+ for i in Vec::new() { } //~ ERROR type annotations needed
+}
diff --git a/src/test/ui/for/for-loop-unconstrained-element-type.stderr b/src/test/ui/for/for-loop-unconstrained-element-type.stderr
new file mode 100644
index 000000000..b1b38f6b9
--- /dev/null
+++ b/src/test/ui/for/for-loop-unconstrained-element-type.stderr
@@ -0,0 +1,14 @@
+error[E0282]: type annotations needed
+ --> $DIR/for-loop-unconstrained-element-type.rs:8:14
+ |
+LL | for i in Vec::new() { }
+ | ^^^^^^^^ cannot infer type of the type parameter `T` declared on the struct `Vec`
+ |
+help: consider specifying the generic argument
+ |
+LL | for i in Vec::<T>::new() { }
+ | +++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0282`.