From 73b00ca8c65fcabf07d48378852c920a44a14c8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= <39484203+jieyouxu@users.noreply.github.com> Date: Sun, 8 Dec 2024 15:31:40 +0800 Subject: [PATCH 01/10] Document `assign-assign.rs` --- tests/ui/assign-assign.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/ui/assign-assign.rs b/tests/ui/assign-assign.rs index 002393f5bffbb..b4268b5e09a3c 100644 --- a/tests/ui/assign-assign.rs +++ b/tests/ui/assign-assign.rs @@ -1,5 +1,11 @@ +//! Regression test for [Using the result of an assignment expression results in an LLVM assert +//! #483][issue-483]. This test checks that assignment expressions produce a unit type, and is +//! properly lowered to LLVM IR such that it does not trigger an LLVM assertion. This test was added +//! *really* early, back in 2011. +//! +//! [issue-483]: https://github.com/rust-lang/rust/issues/483 + //@ run-pass -// Issue 483 - Assignment expressions result in nil fn test_assign() { let mut x: isize; @@ -27,4 +33,7 @@ fn test_assign_op() { assert_eq!(z, ()); } -pub fn main() { test_assign(); test_assign_op(); } +pub fn main() { + test_assign(); + test_assign_op(); +} From 5a79963179a2aafb60342144abb02c17262a1f43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= <39484203+jieyouxu@users.noreply.github.com> Date: Sun, 8 Dec 2024 13:53:47 +0800 Subject: [PATCH 02/10] Move `assign-assign.rs` to `tests/ui/codegen/assign-expr-unit-type.rs` --- tests/ui/{assign-assign.rs => codegen/assign-expr-unit-type.rs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/ui/{assign-assign.rs => codegen/assign-expr-unit-type.rs} (100%) diff --git a/tests/ui/assign-assign.rs b/tests/ui/codegen/assign-expr-unit-type.rs similarity index 100% rename from tests/ui/assign-assign.rs rename to tests/ui/codegen/assign-expr-unit-type.rs From 62c3160a2981186e67932bfc693743d0152b4723 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= <39484203+jieyouxu@users.noreply.github.com> Date: Sun, 8 Dec 2024 14:01:10 +0800 Subject: [PATCH 03/10] Adjust `assign-imm-local-twice.rs` - Document the test intention, including both the language semantics it is checking, as well as the borrowck diagnostics that this is exercising. - Tag this test with `//@ run-rustfix` as this ui test exercises a suggestion diagnostics to make an immutable local var mutable. - Minor error annotation reformatting. --- tests/ui/assign-imm-local-twice.fixed | 21 +++++++++++++++++++++ tests/ui/assign-imm-local-twice.rs | 22 +++++++++++++++------- tests/ui/assign-imm-local-twice.stderr | 4 ++-- 3 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 tests/ui/assign-imm-local-twice.fixed diff --git a/tests/ui/assign-imm-local-twice.fixed b/tests/ui/assign-imm-local-twice.fixed new file mode 100644 index 0000000000000..dca994141bb8b --- /dev/null +++ b/tests/ui/assign-imm-local-twice.fixed @@ -0,0 +1,21 @@ +//! Check that we do not allow assigning twice to an immutable variable. This test also checks a +//! few pieces of borrowck diagnostics: +//! +//! - A multipart borrowck diagnostics that points out the first assignment to an immutable +//! variable, alongside violating assignments that follow subsequently. +//! - A suggestion diagnostics to make the immutable binding mutable. + +//@ run-rustfix + +fn main() { + let mut v: isize; + //~^ HELP consider making this binding mutable + //~| SUGGESTION mut + v = 1; + //~^ NOTE first assignment + println!("v={}", v); + v = 2; + //~^ ERROR cannot assign twice to immutable variable + //~| NOTE cannot assign twice to immutable + println!("v={}", v); +} diff --git a/tests/ui/assign-imm-local-twice.rs b/tests/ui/assign-imm-local-twice.rs index b2dfeb564d9f9..43437fa69fa84 100644 --- a/tests/ui/assign-imm-local-twice.rs +++ b/tests/ui/assign-imm-local-twice.rs @@ -1,13 +1,21 @@ -fn test() { +//! Check that we do not allow assigning twice to an immutable variable. This test also checks a +//! few pieces of borrowck diagnostics: +//! +//! - A multipart borrowck diagnostics that points out the first assignment to an immutable +//! variable, alongside violating assignments that follow subsequently. +//! - A suggestion diagnostics to make the immutable binding mutable. + +//@ run-rustfix + +fn main() { let v: isize; //~^ HELP consider making this binding mutable //~| SUGGESTION mut - v = 1; //~ NOTE first assignment + v = 1; + //~^ NOTE first assignment println!("v={}", v); - v = 2; //~ ERROR cannot assign twice to immutable variable - //~| NOTE cannot assign twice to immutable + v = 2; + //~^ ERROR cannot assign twice to immutable variable + //~| NOTE cannot assign twice to immutable println!("v={}", v); } - -fn main() { -} diff --git a/tests/ui/assign-imm-local-twice.stderr b/tests/ui/assign-imm-local-twice.stderr index fda3aa3de1b4b..0a2138d0b9625 100644 --- a/tests/ui/assign-imm-local-twice.stderr +++ b/tests/ui/assign-imm-local-twice.stderr @@ -1,9 +1,9 @@ error[E0384]: cannot assign twice to immutable variable `v` - --> $DIR/assign-imm-local-twice.rs:7:5 + --> $DIR/assign-imm-local-twice.rs:17:5 | LL | v = 1; | ----- first assignment to `v` -LL | println!("v={}", v); +... LL | v = 2; | ^^^^^ cannot assign twice to immutable variable | From 5e07f6e1971e3bd4c5bed559265842ff177ae35d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= <39484203+jieyouxu@users.noreply.github.com> Date: Sun, 8 Dec 2024 14:05:46 +0800 Subject: [PATCH 04/10] Move `assign-imm-local-twice.rs` to `tests/ui/borrowck/` --- tests/ui/{ => borrowck}/assign-imm-local-twice.fixed | 0 tests/ui/{ => borrowck}/assign-imm-local-twice.rs | 0 tests/ui/{ => borrowck}/assign-imm-local-twice.stderr | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename tests/ui/{ => borrowck}/assign-imm-local-twice.fixed (100%) rename tests/ui/{ => borrowck}/assign-imm-local-twice.rs (100%) rename tests/ui/{ => borrowck}/assign-imm-local-twice.stderr (100%) diff --git a/tests/ui/assign-imm-local-twice.fixed b/tests/ui/borrowck/assign-imm-local-twice.fixed similarity index 100% rename from tests/ui/assign-imm-local-twice.fixed rename to tests/ui/borrowck/assign-imm-local-twice.fixed diff --git a/tests/ui/assign-imm-local-twice.rs b/tests/ui/borrowck/assign-imm-local-twice.rs similarity index 100% rename from tests/ui/assign-imm-local-twice.rs rename to tests/ui/borrowck/assign-imm-local-twice.rs diff --git a/tests/ui/assign-imm-local-twice.stderr b/tests/ui/borrowck/assign-imm-local-twice.stderr similarity index 100% rename from tests/ui/assign-imm-local-twice.stderr rename to tests/ui/borrowck/assign-imm-local-twice.stderr From 1e3328dd72a3aed8050d2c090b0dd818a5645d9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= <39484203+jieyouxu@users.noreply.github.com> Date: Sun, 8 Dec 2024 14:24:23 +0800 Subject: [PATCH 05/10] Document `assoc-lang-items.rs` --- tests/ui/assoc-lang-items.rs | 14 ++++++++++++++ tests/ui/assoc-lang-items.stderr | 8 ++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/ui/assoc-lang-items.rs b/tests/ui/assoc-lang-items.rs index 23453d201a72f..460d3ed232665 100644 --- a/tests/ui/assoc-lang-items.rs +++ b/tests/ui/assoc-lang-items.rs @@ -1,3 +1,17 @@ +//! Check that associated items can be marked as lang items, so that they don't have to be looked up +//! by name or by definition order indirectly. +//! +//! This test is not *quite* high-fidelity: it checks that you can use lang items on associated +//! items by looking at the error message *as a proxy*. That is, the error message is about +//! undefined lang items and not invalid attribute target, indicating that it has reached lang item +//! machinery (which is relying on knowing the implementation detail). However, it's annoying to +//! write a full-fidelity test for this, so I think this is acceptable even though it's not *great*. +//! +//! This was implemented in to help with +//! , which is itself relevant for e.g. `Fn::Output` +//! or `Future::Output` or specific use cases like [Use `T`'s discriminant type in +//! `mem::Discriminant` instead of `u64`](https://github.com/rust-lang/rust/pull/70705). + #![feature(lang_items)] trait Foo { diff --git a/tests/ui/assoc-lang-items.stderr b/tests/ui/assoc-lang-items.stderr index 59aec8e3fdc6e..7e61fea449be8 100644 --- a/tests/ui/assoc-lang-items.stderr +++ b/tests/ui/assoc-lang-items.stderr @@ -1,23 +1,23 @@ error[E0522]: definition of an unknown lang item: `dummy_lang_item_1` - --> $DIR/assoc-lang-items.rs:4:5 + --> $DIR/assoc-lang-items.rs:18:5 | LL | #[lang = "dummy_lang_item_1"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition of unknown lang item `dummy_lang_item_1` error[E0522]: definition of an unknown lang item: `dummy_lang_item_2` - --> $DIR/assoc-lang-items.rs:7:5 + --> $DIR/assoc-lang-items.rs:21:5 | LL | #[lang = "dummy_lang_item_2"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition of unknown lang item `dummy_lang_item_2` error[E0522]: definition of an unknown lang item: `dummy_lang_item_3` - --> $DIR/assoc-lang-items.rs:10:5 + --> $DIR/assoc-lang-items.rs:24:5 | LL | #[lang = "dummy_lang_item_3"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition of unknown lang item `dummy_lang_item_3` error[E0522]: definition of an unknown lang item: `dummy_lang_item_4` - --> $DIR/assoc-lang-items.rs:17:5 + --> $DIR/assoc-lang-items.rs:31:5 | LL | #[lang = "dummy_lang_item_4"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition of unknown lang item `dummy_lang_item_4` From 6959582ac6378e1c1c2b858497770df609feb37e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= <39484203+jieyouxu@users.noreply.github.com> Date: Sun, 8 Dec 2024 14:25:39 +0800 Subject: [PATCH 06/10] Move `assoc-lang-items.rs` to `tests/ui/lang-items/` --- tests/ui/{ => lang-items}/assoc-lang-items.rs | 0 tests/ui/{ => lang-items}/assoc-lang-items.stderr | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename tests/ui/{ => lang-items}/assoc-lang-items.rs (100%) rename tests/ui/{ => lang-items}/assoc-lang-items.stderr (100%) diff --git a/tests/ui/assoc-lang-items.rs b/tests/ui/lang-items/assoc-lang-items.rs similarity index 100% rename from tests/ui/assoc-lang-items.rs rename to tests/ui/lang-items/assoc-lang-items.rs diff --git a/tests/ui/assoc-lang-items.stderr b/tests/ui/lang-items/assoc-lang-items.stderr similarity index 100% rename from tests/ui/assoc-lang-items.stderr rename to tests/ui/lang-items/assoc-lang-items.stderr From b815a9361423e7d18ab7458650ee366f8cf5e3d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= <39484203+jieyouxu@users.noreply.github.com> Date: Sun, 8 Dec 2024 14:27:41 +0800 Subject: [PATCH 07/10] Move `assoc-oddities-3.rs` under `tests/ui/parser/assoc/` This is where `assoc-oddities-{1,2}.rs` are located, reunite them! --- tests/ui/{ => parser/assoc}/assoc-oddities-3.rs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/ui/{ => parser/assoc}/assoc-oddities-3.rs (100%) diff --git a/tests/ui/assoc-oddities-3.rs b/tests/ui/parser/assoc/assoc-oddities-3.rs similarity index 100% rename from tests/ui/assoc-oddities-3.rs rename to tests/ui/parser/assoc/assoc-oddities-3.rs From 3a33522ca87202d52cb568d7710cfc3543aaf39e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= <39484203+jieyouxu@users.noreply.github.com> Date: Sun, 8 Dec 2024 14:45:24 +0800 Subject: [PATCH 08/10] Adjust `assoc-oddities-3.rs` - Include the original MCVE as reported in . - Document the intention of the test. --- tests/ui/parser/assoc/assoc-oddities-3.rs | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/ui/parser/assoc/assoc-oddities-3.rs b/tests/ui/parser/assoc/assoc-oddities-3.rs index ffde2ccf78635..1a41c4be02373 100644 --- a/tests/ui/parser/assoc/assoc-oddities-3.rs +++ b/tests/ui/parser/assoc/assoc-oddities-3.rs @@ -1,3 +1,10 @@ +//! Check that braces has the expected precedence in relation to index op and some arithmetic +//! bin-ops involving nested braces. +//! +//! This is a regression test for [Wrapping expr in curly braces changes the operator precedence +//! #28777](https://github.com/rust-lang/rust/issues/28777), which was fixed by +//! . + //@ run-pass fn that_odd_parse(c: bool, n: usize) -> u32 { @@ -7,7 +14,28 @@ fn that_odd_parse(c: bool, n: usize) -> u32 { x + if c { a } else { b }[n] } +/// See [Wrapping expr in curly braces changes the operator precedence +/// #28777](https://github.com/rust-lang/rust/issues/28777). This was fixed by +/// . #30375 added the `that_odd_parse` example above, +/// but that is not *quite* the same original example as reported in #28777, so we also include the +/// original example here. +fn check_issue_28777() { + // Before #30375 fixed the precedence... + + // ... `v1` evaluated to 9, indicating a parse of `(1 + 2) * 3`, while + let v1 = { 1 + { 2 } * { 3 } }; + + // `v2` evaluated to 7, indicating a parse of `1 + (2 * 3)`. + let v2 = 1 + { 2 } * { 3 }; + + // Check that both now evaluate to 7, as was fixed by #30375. + assert_eq!(v1, 7); + assert_eq!(v2, 7); +} + fn main() { assert_eq!(4, that_odd_parse(true, 1)); assert_eq!(8, that_odd_parse(false, 1)); + + check_issue_28777(); } From 1247f01a3c4a1c51f31fddf145a3fcc3a806d59e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= <39484203+jieyouxu@users.noreply.github.com> Date: Sun, 8 Dec 2024 14:54:03 +0800 Subject: [PATCH 09/10] Move `atomic-from-mut-not-available.rs` to `tests/ui/stdlib-unit-tests/` This test exercises the combined effect of the `cfg(target_has_atomic_equal_alignment = "...")` implementation in the compiler as well as the usage of said `cfg(target_has_atomic_equal_alignment)` in `core`. --- tests/ui/atomic-from-mut-not-available.stderr | 17 ----------------- .../atomic-from-mut-not-available.rs | 0 2 files changed, 17 deletions(-) delete mode 100644 tests/ui/atomic-from-mut-not-available.stderr rename tests/ui/{ => stdlib-unit-tests}/atomic-from-mut-not-available.rs (100%) diff --git a/tests/ui/atomic-from-mut-not-available.stderr b/tests/ui/atomic-from-mut-not-available.stderr deleted file mode 100644 index a4514524f48f5..0000000000000 --- a/tests/ui/atomic-from-mut-not-available.stderr +++ /dev/null @@ -1,17 +0,0 @@ -error[E0599]: no function or associated item named `from_mut` found for struct `AtomicU64` in the current scope - --> $DIR/atomic-from-mut-not-available.rs:5:36 - | -LL | core::sync::atomic::AtomicU64::from_mut(&mut 0u64); - | ^^^^^^^^ function or associated item not found in `AtomicU64` - | -note: if you're trying to build a new `AtomicU64`, consider using `AtomicU64::new` which returns `AtomicU64` - --> $SRC_DIR/core/src/sync/atomic.rs:LL:COL - = note: this error originates in the macro `atomic_int` (in Nightly builds, run with -Z macro-backtrace for more info) -help: there is an associated function `from` with a similar name - | -LL | core::sync::atomic::AtomicU64::from(&mut 0u64); - | ~~~~ - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0599`. diff --git a/tests/ui/atomic-from-mut-not-available.rs b/tests/ui/stdlib-unit-tests/atomic-from-mut-not-available.rs similarity index 100% rename from tests/ui/atomic-from-mut-not-available.rs rename to tests/ui/stdlib-unit-tests/atomic-from-mut-not-available.rs From 754dec3fbc9982289be107273b5d01c008e66c75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= <39484203+jieyouxu@users.noreply.github.com> Date: Sun, 8 Dec 2024 15:12:36 +0800 Subject: [PATCH 10/10] Adjust `atomic-from-mut-not-available.rs` - Introduce two revisions: one for 32-bit x86 vs one for 64-bit x86_64 and compare & contrast the errors. - Document the test intention and note its limitations. --- ...mut-not-available.alignment_matches.stderr | 13 ++++++++++ ...ut-not-available.alignment_mismatch.stderr | 17 ++++++++++++ .../atomic-from-mut-not-available.rs | 26 ++++++++++++++++--- 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 tests/ui/stdlib-unit-tests/atomic-from-mut-not-available.alignment_matches.stderr create mode 100644 tests/ui/stdlib-unit-tests/atomic-from-mut-not-available.alignment_mismatch.stderr diff --git a/tests/ui/stdlib-unit-tests/atomic-from-mut-not-available.alignment_matches.stderr b/tests/ui/stdlib-unit-tests/atomic-from-mut-not-available.alignment_matches.stderr new file mode 100644 index 0000000000000..109985c005286 --- /dev/null +++ b/tests/ui/stdlib-unit-tests/atomic-from-mut-not-available.alignment_matches.stderr @@ -0,0 +1,13 @@ +error[E0658]: use of unstable library feature `atomic_from_mut` + --> $DIR/atomic-from-mut-not-available.rs:24:5 + | +LL | core::sync::atomic::AtomicU64::from_mut(&mut 0u64); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #76314 for more information + = help: add `#![feature(atomic_from_mut)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/stdlib-unit-tests/atomic-from-mut-not-available.alignment_mismatch.stderr b/tests/ui/stdlib-unit-tests/atomic-from-mut-not-available.alignment_mismatch.stderr new file mode 100644 index 0000000000000..47b17f9fcd7ad --- /dev/null +++ b/tests/ui/stdlib-unit-tests/atomic-from-mut-not-available.alignment_mismatch.stderr @@ -0,0 +1,17 @@ +error[E0599]: no function or associated item named `from_mut` found for struct `AtomicU64` in the current scope + --> $DIR/atomic-from-mut-not-available.rs:24:36 + | +LL | core::sync::atomic::AtomicU64::from_mut(&mut 0u64); + | ^^^^^^^^ function or associated item not found in `AtomicU64` + | +note: if you're trying to build a new `AtomicU64`, consider using `AtomicU64::new` which returns `AtomicU64` + --> $SRC_DIR/core/src/sync/atomic.rs:LL:COL + = note: this error originates in the macro `atomic_int` (in Nightly builds, run with -Z macro-backtrace for more info) +help: there is an associated function `from` with a similar name + | +LL | core::sync::atomic::AtomicU64::from(&mut 0u64); + | ~~~~ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0599`. diff --git a/tests/ui/stdlib-unit-tests/atomic-from-mut-not-available.rs b/tests/ui/stdlib-unit-tests/atomic-from-mut-not-available.rs index 8326187838a20..7e9de3570eb91 100644 --- a/tests/ui/stdlib-unit-tests/atomic-from-mut-not-available.rs +++ b/tests/ui/stdlib-unit-tests/atomic-from-mut-not-available.rs @@ -1,7 +1,27 @@ -//@ only-x86 -//@ only-linux +//! This test exercises the combined effect of the `cfg(target_has_atomic_equal_alignment = "...")` +//! implementation in the compiler plus usage of said `cfg(target_has_atomic_equal_alignment)` in +//! `core` for the `Atomic64::from_mut` API. +//! +//! This test is a basic smoke test: that `AtomicU64::from_mut` is gated by +//! `#[cfg(target_has_atomic_equal_alignment = "8")]`, which is only available on platforms where +//! `AtomicU64` has the same alignment as `u64`. This is notably *not* satisfied by `x86_32`, where +//! they have differing alignments. Thus, `AtomicU64::from_mut` should *not* be available on +//! `x86_32` linux and should report assoc item not found, if the `cfg` is working correctly. +//! Conversely, `AtomicU64::from_mut` *should* be available on `x86_64` linux where the alignment +//! matches. + +//@ revisions: alignment_mismatch alignment_matches + +// This should fail on 32-bit x86 linux... +//@[alignment_mismatch] only-x86 +//@[alignment_mismatch] only-linux + +// ... but pass on 64-bit x86_64 linux. +//@[alignment_matches] only-x86_64 +//@[alignment_matches] only-linux fn main() { core::sync::atomic::AtomicU64::from_mut(&mut 0u64); - //~^ ERROR: no function or associated item named `from_mut` found for struct `AtomicU64` + //[alignment_mismatch]~^ ERROR no function or associated item named `from_mut` found for struct `AtomicU64` + //[alignment_matches]~^^ ERROR use of unstable library feature `atomic_from_mut` }