From a4b7ed7a42c716ab9f05e351f003d589124fd55d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:18:58 +0200 Subject: Adding upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- tests/ui/for/for-c-in-str.rs | 14 ++++++++++++++ tests/ui/for/for-c-in-str.stderr | 12 ++++++++++++ tests/ui/for/for-expn.rs | 9 +++++++++ tests/ui/for/for-expn.stderr | 9 +++++++++ tests/ui/for/for-loop-bogosity.rs | 21 +++++++++++++++++++++ tests/ui/for/for-loop-bogosity.stderr | 12 ++++++++++++ .../for/for-loop-refutable-pattern-error-message.rs | 3 +++ .../for-loop-refutable-pattern-error-message.stderr | 11 +++++++++++ tests/ui/for/for-loop-type-error.rs | 6 ++++++ tests/ui/for/for-loop-type-error.stderr | 11 +++++++++++ tests/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 tests/ui/for/for-c-in-str.rs create mode 100644 tests/ui/for/for-c-in-str.stderr create mode 100644 tests/ui/for/for-expn.rs create mode 100644 tests/ui/for/for-expn.stderr create mode 100644 tests/ui/for/for-loop-bogosity.rs create mode 100644 tests/ui/for/for-loop-bogosity.stderr create mode 100644 tests/ui/for/for-loop-refutable-pattern-error-message.rs create mode 100644 tests/ui/for/for-loop-refutable-pattern-error-message.stderr create mode 100644 tests/ui/for/for-loop-type-error.rs create mode 100644 tests/ui/for/for-loop-type-error.stderr create mode 100644 tests/ui/for/for-loop-unconstrained-element-type.rs create mode 100644 tests/ui/for/for-loop-unconstrained-element-type.stderr (limited to 'tests/ui/for') diff --git a/tests/ui/for/for-c-in-str.rs b/tests/ui/for/for-c-in-str.rs new file mode 100644 index 000000000..b086128d2 --- /dev/null +++ b/tests/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 for `&str` to implement `IntoIterator` + //~| 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/tests/ui/for/for-c-in-str.stderr b/tests/ui/for/for-c-in-str.stderr new file mode 100644 index 000000000..959a7c43f --- /dev/null +++ b/tests/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 for `&str` to implement `IntoIterator` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/for/for-expn.rs b/tests/ui/for/for-expn.rs new file mode 100644 index 000000000..b9c4bbeda --- /dev/null +++ b/tests/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/tests/ui/for/for-expn.stderr b/tests/ui/for/for-expn.stderr new file mode 100644 index 000000000..cdb211555 --- /dev/null +++ b/tests/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/tests/ui/for/for-loop-bogosity.rs b/tests/ui/for/for-loop-bogosity.rs new file mode 100644 index 000000000..9341dea09 --- /dev/null +++ b/tests/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/tests/ui/for/for-loop-bogosity.stderr b/tests/ui/for/for-loop-bogosity.stderr new file mode 100644 index 000000000..9bf8056e8 --- /dev/null +++ b/tests/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 for `MyStruct` to implement `IntoIterator` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/for/for-loop-refutable-pattern-error-message.rs b/tests/ui/for/for-loop-refutable-pattern-error-message.rs new file mode 100644 index 000000000..221951c87 --- /dev/null +++ b/tests/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/tests/ui/for/for-loop-refutable-pattern-error-message.stderr b/tests/ui/for/for-loop-refutable-pattern-error-message.stderr new file mode 100644 index 000000000..49a82a676 --- /dev/null +++ b/tests/ui/for/for-loop-refutable-pattern-error-message.stderr @@ -0,0 +1,11 @@ +error[E0005]: refutable pattern in `for` loop binding + --> $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/tests/ui/for/for-loop-type-error.rs b/tests/ui/for/for-loop-type-error.rs new file mode 100644 index 000000000..8d9fc20f0 --- /dev/null +++ b/tests/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/tests/ui/for/for-loop-type-error.stderr b/tests/ui/for/for-loop-type-error.stderr new file mode 100644 index 000000000..c93a3b9b2 --- /dev/null +++ b/tests/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/tests/ui/for/for-loop-unconstrained-element-type.rs b/tests/ui/for/for-loop-unconstrained-element-type.rs new file mode 100644 index 000000000..0c7a3516a --- /dev/null +++ b/tests/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/tests/ui/for/for-loop-unconstrained-element-type.stderr b/tests/ui/for/for-loop-unconstrained-element-type.stderr new file mode 100644 index 000000000..b1b38f6b9 --- /dev/null +++ b/tests/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