diff --git a/src/tools/tidy/src/issues.txt b/src/tools/tidy/src/issues.txt index a37700f2e8538..0f3f2f37ebf26 100644 --- a/src/tools/tidy/src/issues.txt +++ b/src/tools/tidy/src/issues.txt @@ -1014,7 +1014,6 @@ ui/for-loop-while/issue-1257.rs ui/for-loop-while/issue-2216.rs ui/for-loop-while/issue-51345.rs ui/for-loop-while/issue-69841.rs -ui/for/issue-20605.rs ui/foreign/issue-74120-lowering-of-ffi-block-bodies.rs ui/foreign/issue-91370-foreign-fn-block-impl.rs ui/foreign/issue-99276-same-type-lifetimes.rs diff --git a/tests/ui/README.md b/tests/ui/README.md index 11003bbef9928..c175b2e293b18 100644 --- a/tests/ui/README.md +++ b/tests/ui/README.md @@ -585,12 +585,6 @@ Exercises the `format!` macro. A broad category of tests on functions. -## `tests/ui/for/`: `for` keyword - -Tests on the `for` keyword and some of its associated errors, such as attempting to write the faulty pattern `for _ in 0..1 {} else {}`. - -**FIXME**: Should be merged with `ui/for-loop-while`. - ## `tests/ui/force-inlining/`: `#[rustc_force_inline]` Tests for `#[rustc_force_inline]`, which will force a function to always be labelled as inline by the compiler (it will be inserted at the point of its call instead of being used as a normal function call.) If the compiler is unable to inline the function, an error will be reported. See . @@ -1545,10 +1539,6 @@ Tests on `enum` variants. **FIXME**: Contains a single test described as "Check that rustc accepts various version info flags.", should be rehomed. -## `tests/ui/warnings/` - -**FIXME**: Contains a single test on non-explicit paths (`::one()`). Should be rehomed probably to `tests/ui/resolve/`. - ## `tests/ui/wasm/` These tests target the `wasm32` architecture specifically. They are usually regression tests for WASM-specific bugs which were observed in the past. diff --git a/tests/ui/warnings/hello-world.rs b/tests/ui/entry-point/hello-world.rs similarity index 100% rename from tests/ui/warnings/hello-world.rs rename to tests/ui/entry-point/hello-world.rs diff --git a/tests/ui/for/for-c-in-str.rs b/tests/ui/for-loop-while/for-c-in-str.rs similarity index 75% rename from tests/ui/for/for-c-in-str.rs rename to tests/ui/for-loop-while/for-c-in-str.rs index b086128d28cbc..b3190101da09d 100644 --- a/tests/ui/for/for-c-in-str.rs +++ b/tests/ui/for-loop-while/for-c-in-str.rs @@ -1,4 +1,5 @@ -// E0277 should point exclusively at line 6, not the entire for loop span +//! Tests that the E0277 error span, generated by the `for` loop desugaring, +//! points exclusively to the loop header expression and not the full loop block. fn main() { for c in "asdf" { diff --git a/tests/ui/for/for-c-in-str.stderr b/tests/ui/for-loop-while/for-c-in-str.stderr similarity index 92% rename from tests/ui/for/for-c-in-str.stderr rename to tests/ui/for-loop-while/for-c-in-str.stderr index 475cf8c887491..30749274f919c 100644 --- a/tests/ui/for/for-c-in-str.stderr +++ b/tests/ui/for-loop-while/for-c-in-str.stderr @@ -1,5 +1,5 @@ error[E0277]: `&str` is not an iterator - --> $DIR/for-c-in-str.rs:4:14 + --> $DIR/for-c-in-str.rs:5:14 | LL | for c in "asdf" { | ^^^^^^ `&str` is not an iterator; try calling `.chars()` or `.bytes()` diff --git a/tests/ui/for/for-else-err.rs b/tests/ui/for-loop-while/for-else-err.rs similarity index 100% rename from tests/ui/for/for-else-err.rs rename to tests/ui/for-loop-while/for-else-err.rs diff --git a/tests/ui/for/for-else-err.stderr b/tests/ui/for-loop-while/for-else-err.stderr similarity index 100% rename from tests/ui/for/for-else-err.stderr rename to tests/ui/for-loop-while/for-else-err.stderr diff --git a/tests/ui/for/for-else-let-else-err.rs b/tests/ui/for-loop-while/for-else-let-else-err.rs similarity index 100% rename from tests/ui/for/for-else-let-else-err.rs rename to tests/ui/for-loop-while/for-else-let-else-err.rs diff --git a/tests/ui/for/for-else-let-else-err.stderr b/tests/ui/for-loop-while/for-else-let-else-err.stderr similarity index 100% rename from tests/ui/for/for-else-let-else-err.stderr rename to tests/ui/for-loop-while/for-else-let-else-err.stderr diff --git a/tests/ui/for-loop-while/for-loop-bogosity.rs b/tests/ui/for-loop-while/for-loop-bogosity.rs new file mode 100644 index 0000000000000..19117620c5e67 --- /dev/null +++ b/tests/ui/for-loop-while/for-loop-bogosity.rs @@ -0,0 +1,21 @@ +//! Tests that a struct with a `next` method but without the `Iterator` trait +//! implementation yields an error in a `for` loop. + +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-loop-while/for-loop-bogosity.stderr similarity index 92% rename from tests/ui/for/for-loop-bogosity.stderr rename to tests/ui/for-loop-while/for-loop-bogosity.stderr index f4d99671f8e0c..53bd32e337fd8 100644 --- a/tests/ui/for/for-loop-bogosity.stderr +++ b/tests/ui/for-loop-while/for-loop-bogosity.stderr @@ -5,7 +5,7 @@ LL | for x in bogus { | ^^^^^ `MyStruct` is not an iterator | help: the trait `Iterator` is not implemented for `MyStruct` - --> $DIR/for-loop-bogosity.rs:1:1 + --> $DIR/for-loop-bogosity.rs:4:1 | LL | struct MyStruct { | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/for/for-expn.rs b/tests/ui/for-loop-while/for-loop-diagnostic-span.rs similarity index 100% rename from tests/ui/for/for-expn.rs rename to tests/ui/for-loop-while/for-loop-diagnostic-span.rs diff --git a/tests/ui/for/for-expn.stderr b/tests/ui/for-loop-while/for-loop-diagnostic-span.stderr similarity index 83% rename from tests/ui/for/for-expn.stderr rename to tests/ui/for-loop-while/for-loop-diagnostic-span.stderr index 00822324039f0..d2fc05f054a00 100644 --- a/tests/ui/for/for-expn.stderr +++ b/tests/ui/for-loop-while/for-loop-diagnostic-span.stderr @@ -1,5 +1,5 @@ error[E0425]: cannot find value `foo` in this scope - --> $DIR/for-expn.rs:6:7 + --> $DIR/for-loop-diagnostic-span.rs:6:7 | LL | foo | ^^^ not found in this scope diff --git a/tests/ui/for/for-loop-refutable-pattern-error-message.rs b/tests/ui/for-loop-while/for-loop-refutable-pattern-error-message.rs similarity index 100% rename from tests/ui/for/for-loop-refutable-pattern-error-message.rs rename to tests/ui/for-loop-while/for-loop-refutable-pattern-error-message.rs diff --git a/tests/ui/for/for-loop-refutable-pattern-error-message.stderr b/tests/ui/for-loop-while/for-loop-refutable-pattern-error-message.stderr similarity index 100% rename from tests/ui/for/for-loop-refutable-pattern-error-message.stderr rename to tests/ui/for-loop-while/for-loop-refutable-pattern-error-message.stderr diff --git a/tests/ui/for/for-loop-type-error.rs b/tests/ui/for-loop-while/for-loop-type-error.rs similarity index 62% rename from tests/ui/for/for-loop-type-error.rs rename to tests/ui/for-loop-while/for-loop-type-error.rs index 8d9fc20f0d0d6..895f1985a6199 100644 --- a/tests/ui/for/for-loop-type-error.rs +++ b/tests/ui/for-loop-while/for-loop-type-error.rs @@ -1,3 +1,5 @@ +//! regression test for issue + pub fn main() { let x = () + (); //~ ERROR cannot add `()` to `()` diff --git a/tests/ui/for/for-loop-type-error.stderr b/tests/ui/for-loop-while/for-loop-type-error.stderr similarity index 86% rename from tests/ui/for/for-loop-type-error.stderr rename to tests/ui/for-loop-while/for-loop-type-error.stderr index 393becd1b3452..88f383444cb3f 100644 --- a/tests/ui/for/for-loop-type-error.stderr +++ b/tests/ui/for-loop-while/for-loop-type-error.stderr @@ -1,5 +1,5 @@ error[E0369]: cannot add `()` to `()` - --> $DIR/for-loop-type-error.rs:2:16 + --> $DIR/for-loop-type-error.rs:4:16 | LL | let x = () + (); | -- ^ -- () diff --git a/tests/ui/for/for-loop-unconstrained-element-type.rs b/tests/ui/for-loop-while/for-loop-unconstrained-element-type.rs similarity index 63% rename from tests/ui/for/for-loop-unconstrained-element-type.rs rename to tests/ui/for-loop-while/for-loop-unconstrained-element-type.rs index 0c7a3516a14ca..4fff6df5f4d39 100644 --- a/tests/ui/for/for-loop-unconstrained-element-type.rs +++ b/tests/ui/for-loop-while/for-loop-unconstrained-element-type.rs @@ -3,7 +3,8 @@ // Subtle changes in the desugaring can cause the // type of elements in the vector to (incorrectly) // fallback to `!` or `()`. +// regression test for issue fn main() { - for i in Vec::new() { } //~ ERROR type annotations needed + 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-loop-while/for-loop-unconstrained-element-type.stderr similarity index 72% rename from tests/ui/for/for-loop-unconstrained-element-type.stderr rename to tests/ui/for-loop-while/for-loop-unconstrained-element-type.stderr index 3add3ae2eeb21..3b3fa6e7b5c66 100644 --- a/tests/ui/for/for-loop-unconstrained-element-type.stderr +++ b/tests/ui/for-loop-while/for-loop-unconstrained-element-type.stderr @@ -1,12 +1,12 @@ error[E0282]: type annotations needed - --> $DIR/for-loop-unconstrained-element-type.rs:8:14 + --> $DIR/for-loop-unconstrained-element-type.rs:9:14 | -LL | for i in Vec::new() { } +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() { } +LL | for i in Vec::::new() {} | +++++ error: aborting due to 1 previous error diff --git a/tests/ui/for-loop-while/iter-from-mac-call.rs b/tests/ui/for-loop-while/iter-from-mac-call.rs new file mode 100644 index 0000000000000..58177444c3f98 --- /dev/null +++ b/tests/ui/for-loop-while/iter-from-mac-call.rs @@ -0,0 +1,29 @@ +//! Tests for trait/type errors when dereferencing via macro in a for loop. + +macro_rules! deref { + ($e:expr) => { + *$e + }; +} + +fn f1(x: &mut i32) { + for _item in deref!(x) {} + //~^ ERROR `i32` is not an iterator +} + +struct Wrapped(i32); + +macro_rules! borrow_deref { + ($e:expr) => { + &mut *$e + }; +} + +fn f2<'a>(mut iter: Box>) { + for Wrapped(item) in borrow_deref!(iter) { + //~^ ERROR mismatched types + *item = 0 + } +} + +fn main() {} diff --git a/tests/ui/for-loop-while/iter-from-mac-call.stderr b/tests/ui/for-loop-while/iter-from-mac-call.stderr new file mode 100644 index 0000000000000..4cde6a8a86d38 --- /dev/null +++ b/tests/ui/for-loop-while/iter-from-mac-call.stderr @@ -0,0 +1,22 @@ +error[E0277]: `i32` is not an iterator + --> $DIR/iter-from-mac-call.rs:10:18 + | +LL | for _item in deref!(x) {} + | ^^^^^^^^^ `i32` is not an iterator + | + = help: the trait `Iterator` is not implemented for `i32` + = note: if you want to iterate between `start` until a value `end`, use the exclusive range syntax `start..end` or the inclusive range syntax `start..=end` + = note: required for `i32` to implement `IntoIterator` + +error[E0308]: mismatched types + --> $DIR/iter-from-mac-call.rs:23:9 + | +LL | for Wrapped(item) in borrow_deref!(iter) { + | ^^^^^^^^^^^^^ ------------------- this is an iterator with items of type `&mut i32` + | | + | expected `i32`, found `Wrapped` + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0277, E0308. +For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/for/for-loop-bogosity.rs b/tests/ui/for/for-loop-bogosity.rs deleted file mode 100644 index 9341dea0974b4..0000000000000 --- a/tests/ui/for/for-loop-bogosity.rs +++ /dev/null @@ -1,21 +0,0 @@ -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/issue-20605.rs b/tests/ui/for/issue-20605.rs deleted file mode 100644 index 5c56e64a01727..0000000000000 --- a/tests/ui/for/issue-20605.rs +++ /dev/null @@ -1,10 +0,0 @@ -//@ revisions: current next -//@ ignore-compare-mode-next-solver (explicit revisions) -//@[next] compile-flags: -Znext-solver - -fn changer<'a>(mut things: Box>) { - for item in *things { *item = 0 } - //~^ ERROR `dyn Iterator` is not an iterator -} - -fn main() {} diff --git a/tests/ui/for/iter_from_mac_call.rs b/tests/ui/for/iter_from_mac_call.rs deleted file mode 100644 index 8df21456222c4..0000000000000 --- a/tests/ui/for/iter_from_mac_call.rs +++ /dev/null @@ -1,26 +0,0 @@ -macro_rules! deref { - ($e:expr) => { *$e }; -} - -fn f1<'a>(mut iter: Box>) { - for item in deref!(iter) { *item = 0 } - //~^ ERROR `dyn Iterator` is not an iterator -} - -fn f2(x: &mut i32) { - for _item in deref!(x) {} - //~^ ERROR `i32` is not an iterator -} - -struct Wrapped(i32); - -macro_rules! borrow_deref { - ($e:expr) => { &mut *$e }; -} - -fn f3<'a>(mut iter: Box>) { - for Wrapped(item) in borrow_deref!(iter) { *item = 0 } - //~^ ERROR mismatched types -} - -fn main() {} diff --git a/tests/ui/for/iter_from_mac_call.stderr b/tests/ui/for/iter_from_mac_call.stderr deleted file mode 100644 index e62efb250e299..0000000000000 --- a/tests/ui/for/iter_from_mac_call.stderr +++ /dev/null @@ -1,35 +0,0 @@ -error[E0277]: `dyn Iterator` is not an iterator - --> $DIR/iter_from_mac_call.rs:6:17 - | -LL | for item in deref!(iter) { *item = 0 } - | ^^^^^^^^^^^^ the trait `IntoIterator` is not implemented for `dyn Iterator` - | - = note: the trait bound `dyn Iterator: IntoIterator` is not satisfied - = note: required for `dyn Iterator` to implement `IntoIterator` -help: consider mutably borrowing here - | -LL | for item in &mut deref!(iter) { *item = 0 } - | ++++ - -error[E0277]: `i32` is not an iterator - --> $DIR/iter_from_mac_call.rs:11:18 - | -LL | for _item in deref!(x) {} - | ^^^^^^^^^ `i32` is not an iterator - | - = help: the trait `Iterator` is not implemented for `i32` - = note: if you want to iterate between `start` until a value `end`, use the exclusive range syntax `start..end` or the inclusive range syntax `start..=end` - = note: required for `i32` to implement `IntoIterator` - -error[E0308]: mismatched types - --> $DIR/iter_from_mac_call.rs:22:9 - | -LL | for Wrapped(item) in borrow_deref!(iter) { *item = 0 } - | ^^^^^^^^^^^^^ ------------------- this is an iterator with items of type `&mut i32` - | | - | expected `i32`, found `Wrapped` - -error: aborting due to 3 previous errors - -Some errors have detailed explanations: E0277, E0308. -For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/warnings/no-explicit-path-issue-122509.rs b/tests/ui/resolve/no-explicit-path.rs similarity index 79% rename from tests/ui/warnings/no-explicit-path-issue-122509.rs rename to tests/ui/resolve/no-explicit-path.rs index 5be4b174076db..11a5b78ab910e 100644 --- a/tests/ui/warnings/no-explicit-path-issue-122509.rs +++ b/tests/ui/resolve/no-explicit-path.rs @@ -1,3 +1,4 @@ +//! regression test for issue //@ build-pass //@ compile-flags: -C codegen-units=2 --emit asm diff --git a/tests/ui/for/issue-20605.current.stderr b/tests/ui/traits/dyn-iterator-deref-in-for-loop.current.stderr similarity index 81% rename from tests/ui/for/issue-20605.current.stderr rename to tests/ui/traits/dyn-iterator-deref-in-for-loop.current.stderr index 1a66cb4146495..b5a9b82a93a3e 100644 --- a/tests/ui/for/issue-20605.current.stderr +++ b/tests/ui/traits/dyn-iterator-deref-in-for-loop.current.stderr @@ -1,14 +1,14 @@ error[E0277]: `dyn Iterator` is not an iterator - --> $DIR/issue-20605.rs:6:17 + --> $DIR/dyn-iterator-deref-in-for-loop.rs:9:17 | -LL | for item in *things { *item = 0 } +LL | for item in *things { | ^^^^^^^ the trait `IntoIterator` is not implemented for `dyn Iterator` | = note: the trait bound `dyn Iterator: IntoIterator` is not satisfied = note: required for `dyn Iterator` to implement `IntoIterator` help: consider mutably borrowing here | -LL | for item in &mut *things { *item = 0 } +LL | for item in &mut *things { | ++++ error: aborting due to 1 previous error diff --git a/tests/ui/for/issue-20605.next.stderr b/tests/ui/traits/dyn-iterator-deref-in-for-loop.next.stderr similarity index 81% rename from tests/ui/for/issue-20605.next.stderr rename to tests/ui/traits/dyn-iterator-deref-in-for-loop.next.stderr index 1a66cb4146495..b5a9b82a93a3e 100644 --- a/tests/ui/for/issue-20605.next.stderr +++ b/tests/ui/traits/dyn-iterator-deref-in-for-loop.next.stderr @@ -1,14 +1,14 @@ error[E0277]: `dyn Iterator` is not an iterator - --> $DIR/issue-20605.rs:6:17 + --> $DIR/dyn-iterator-deref-in-for-loop.rs:9:17 | -LL | for item in *things { *item = 0 } +LL | for item in *things { | ^^^^^^^ the trait `IntoIterator` is not implemented for `dyn Iterator` | = note: the trait bound `dyn Iterator: IntoIterator` is not satisfied = note: required for `dyn Iterator` to implement `IntoIterator` help: consider mutably borrowing here | -LL | for item in &mut *things { *item = 0 } +LL | for item in &mut *things { | ++++ error: aborting due to 1 previous error diff --git a/tests/ui/traits/dyn-iterator-deref-in-for-loop.rs b/tests/ui/traits/dyn-iterator-deref-in-for-loop.rs new file mode 100644 index 0000000000000..04587df1555d7 --- /dev/null +++ b/tests/ui/traits/dyn-iterator-deref-in-for-loop.rs @@ -0,0 +1,15 @@ +//! Tests that dereferencing a Box in a for loop correctly yields an error, +//! as the unsized trait object does not implement IntoIterator. +//! regression test for +//@ revisions: current next +//@ ignore-compare-mode-next-solver (explicit revisions) +//@[next] compile-flags: -Znext-solver + +fn changer<'a>(mut things: Box>) { + for item in *things { + //~^ ERROR `dyn Iterator` is not an iterator + *item = 0 + } +} + +fn main() {} diff --git a/tests/ui/trait-objects/trait-object-lifetime-conversion-47638.rs b/tests/ui/traits/object/trait-object-lifetime-conversion.rs similarity index 100% rename from tests/ui/trait-objects/trait-object-lifetime-conversion-47638.rs rename to tests/ui/traits/object/trait-object-lifetime-conversion.rs