From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- src/test/ui/for/for-c-in-str.rs | 14 ++++++++++++++ src/test/ui/for/for-c-in-str.stderr | 12 ++++++++++++ src/test/ui/for/for-expn.rs | 9 +++++++++ src/test/ui/for/for-expn.stderr | 9 +++++++++ src/test/ui/for/for-loop-bogosity.rs | 21 +++++++++++++++++++++ src/test/ui/for/for-loop-bogosity.stderr | 12 ++++++++++++ .../for/for-loop-refutable-pattern-error-message.rs | 3 +++ .../for-loop-refutable-pattern-error-message.stderr | 11 +++++++++++ src/test/ui/for/for-loop-type-error.rs | 6 ++++++ src/test/ui/for/for-loop-type-error.stderr | 11 +++++++++++ .../ui/for/for-loop-unconstrained-element-type.rs | 9 +++++++++ .../for/for-loop-unconstrained-element-type.stderr | 14 ++++++++++++++ 12 files changed, 131 insertions(+) create mode 100644 src/test/ui/for/for-c-in-str.rs create mode 100644 src/test/ui/for/for-c-in-str.stderr create mode 100644 src/test/ui/for/for-expn.rs create mode 100644 src/test/ui/for/for-expn.stderr create mode 100644 src/test/ui/for/for-loop-bogosity.rs create mode 100644 src/test/ui/for/for-loop-bogosity.stderr create mode 100644 src/test/ui/for/for-loop-refutable-pattern-error-message.rs create mode 100644 src/test/ui/for/for-loop-refutable-pattern-error-message.stderr create mode 100644 src/test/ui/for/for-loop-type-error.rs create mode 100644 src/test/ui/for/for-loop-type-error.stderr create mode 100644 src/test/ui/for/for-loop-unconstrained-element-type.rs create mode 100644 src/test/ui/for/for-loop-unconstrained-element-type.stderr (limited to 'src/test/ui/for') 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 { + 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::::new() { } + | +++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0282`. -- cgit v1.2.3