From a86df238d3f21ccb6ec25080bcc24b1f9153ea63 Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Sat, 19 Apr 2025 16:46:06 +0800 Subject: tests: rework `amdgpu-require-explicit-cpu.rs` - Reworked the test as a *centralized* version of checking that certain targets correctly require `-C target-cpu` being specified. - Document test intention. - Move `amdgpu-require-explicit-cpu.rs` under new dir `tests/ui/target-cpu/` - No other ui subdir really fits this "requires `-Ctarget-cpu`" check. --- tests/ui/amdgpu-require-explicit-cpu.nocpu.stderr | 4 --- tests/ui/amdgpu-require-explicit-cpu.rs | 18 ----------- .../explicit-target-cpu.amdgcn_nocpu.stderr | 4 +++ .../explicit-target-cpu.avr_nocpu.stderr | 4 +++ tests/ui/target-cpu/explicit-target-cpu.rs | 37 ++++++++++++++++++++++ 5 files changed, 45 insertions(+), 22 deletions(-) delete mode 100644 tests/ui/amdgpu-require-explicit-cpu.nocpu.stderr delete mode 100644 tests/ui/amdgpu-require-explicit-cpu.rs create mode 100644 tests/ui/target-cpu/explicit-target-cpu.amdgcn_nocpu.stderr create mode 100644 tests/ui/target-cpu/explicit-target-cpu.avr_nocpu.stderr create mode 100644 tests/ui/target-cpu/explicit-target-cpu.rs (limited to 'tests') diff --git a/tests/ui/amdgpu-require-explicit-cpu.nocpu.stderr b/tests/ui/amdgpu-require-explicit-cpu.nocpu.stderr deleted file mode 100644 index 7480a8ed38f..00000000000 --- a/tests/ui/amdgpu-require-explicit-cpu.nocpu.stderr +++ /dev/null @@ -1,4 +0,0 @@ -error: target requires explicitly specifying a cpu with `-C target-cpu` - -error: aborting due to 1 previous error - diff --git a/tests/ui/amdgpu-require-explicit-cpu.rs b/tests/ui/amdgpu-require-explicit-cpu.rs deleted file mode 100644 index d40cb97977d..00000000000 --- a/tests/ui/amdgpu-require-explicit-cpu.rs +++ /dev/null @@ -1,18 +0,0 @@ -//@ revisions: nocpu cpu -//@ no-prefer-dynamic -//@ compile-flags: --crate-type=cdylib --target=amdgcn-amd-amdhsa -//@ needs-llvm-components: amdgpu -//@ needs-rust-lld -//@[nocpu] build-fail -//@[cpu] compile-flags: -Ctarget-cpu=gfx900 -//@[cpu] build-pass - -#![feature(no_core, lang_items)] -#![no_core] - -#[lang="sized"] -trait Sized {} - -pub fn foo() {} - -//[nocpu]~? ERROR target requires explicitly specifying a cpu with `-C target-cpu` diff --git a/tests/ui/target-cpu/explicit-target-cpu.amdgcn_nocpu.stderr b/tests/ui/target-cpu/explicit-target-cpu.amdgcn_nocpu.stderr new file mode 100644 index 00000000000..7480a8ed38f --- /dev/null +++ b/tests/ui/target-cpu/explicit-target-cpu.amdgcn_nocpu.stderr @@ -0,0 +1,4 @@ +error: target requires explicitly specifying a cpu with `-C target-cpu` + +error: aborting due to 1 previous error + diff --git a/tests/ui/target-cpu/explicit-target-cpu.avr_nocpu.stderr b/tests/ui/target-cpu/explicit-target-cpu.avr_nocpu.stderr new file mode 100644 index 00000000000..7480a8ed38f --- /dev/null +++ b/tests/ui/target-cpu/explicit-target-cpu.avr_nocpu.stderr @@ -0,0 +1,4 @@ +error: target requires explicitly specifying a cpu with `-C target-cpu` + +error: aborting due to 1 previous error + diff --git a/tests/ui/target-cpu/explicit-target-cpu.rs b/tests/ui/target-cpu/explicit-target-cpu.rs new file mode 100644 index 00000000000..cd4c2384bc1 --- /dev/null +++ b/tests/ui/target-cpu/explicit-target-cpu.rs @@ -0,0 +1,37 @@ +//! Check that certain target *requires* the user to specify a target CPU via `-C target-cpu`. + +//@ revisions: amdgcn_nocpu amdgcn_cpu + +//@[amdgcn_nocpu] compile-flags: --target=amdgcn-amd-amdhsa +//@[amdgcn_nocpu] needs-llvm-components: amdgpu +//@[amdgcn_nocpu] build-fail + +//@[amdgcn_cpu] compile-flags: --target=amdgcn-amd-amdhsa +//@[amdgcn_cpu] needs-llvm-components: amdgpu +//@[amdgcn_cpu] compile-flags: -Ctarget-cpu=gfx900 +//@[amdgcn_cpu] build-pass + +//@ revisions: avr_nocpu avr_cpu + +//@[avr_nocpu] compile-flags: --target=avr-none +//@[avr_nocpu] needs-llvm-components: avr +//@[avr_nocpu] build-fail + +//@[avr_cpu] compile-flags: --target=avr-none +//@[avr_cpu] needs-llvm-components: avr +//@[avr_cpu] compile-flags: -Ctarget-cpu=atmega328p +//@[avr_cpu] build-pass + +#![crate_type = "rlib"] + +// FIXME(#140038): this can't use `minicore` yet because `minicore` doesn't currently propagate the +// `-C target-cpu` for targets that *require* a `target-cpu` being specified. +#![feature(no_core, lang_items)] +#![no_core] + +#[lang="sized"] +trait Sized {} + +pub fn foo() {} + +//[amdgcn_nocpu,avr_nocpu]~? ERROR target requires explicitly specifying a cpu with `-C target-cpu` -- cgit 1.4.1-3-g733a5 From 40b73322b93bf1627a7cb58aec5a7fe019af1f66 Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Sat, 19 Apr 2025 17:05:05 +0800 Subject: tests: adjust some `augmented-assignment*` tests - `tests/ui/augmented-assignment-feature-gate-cross.rs`: - This was *originally* to feature-gate overloaded OpAssign cross-crate, but now let's keep it as a smoke test. - Renamed as `augmented-assignment-cross-crate.rs`. - Relocated under `tests/ui/binop/`. - `tests/ui/augmented-assignments.rs`: - Documented test intent. - Moved under `tests/ui/borrowck/`. - `tests/ui/augmented-assignment-rpass.rs`: - Renamed to drop the `-rpass` suffix, since this was leftover from when `run-pass` test suite was a thing. - Moved under `tests/ui/binop/`. --- .../ui/augmented-assignments-feature-gate-cross.rs | 11 -- tests/ui/augmented-assignments-rpass.rs | 172 --------------------- tests/ui/augmented-assignments.rs | 28 ---- tests/ui/augmented-assignments.stderr | 26 ---- tests/ui/auxiliary/augmented_assignments.rs | 8 - tests/ui/binop/augmented-assignment.rs | 172 +++++++++++++++++++++ .../ui/binop/augmented-assignments-cross-crate.rs | 13 ++ tests/ui/binop/auxiliary/augmented_assignments.rs | 8 + tests/ui/borrowck/augmented-assignments.rs | 31 ++++ tests/ui/borrowck/augmented-assignments.stderr | 26 ++++ 10 files changed, 250 insertions(+), 245 deletions(-) delete mode 100644 tests/ui/augmented-assignments-feature-gate-cross.rs delete mode 100644 tests/ui/augmented-assignments-rpass.rs delete mode 100644 tests/ui/augmented-assignments.rs delete mode 100644 tests/ui/augmented-assignments.stderr delete mode 100644 tests/ui/auxiliary/augmented_assignments.rs create mode 100644 tests/ui/binop/augmented-assignment.rs create mode 100644 tests/ui/binop/augmented-assignments-cross-crate.rs create mode 100644 tests/ui/binop/auxiliary/augmented_assignments.rs create mode 100644 tests/ui/borrowck/augmented-assignments.rs create mode 100644 tests/ui/borrowck/augmented-assignments.stderr (limited to 'tests') diff --git a/tests/ui/augmented-assignments-feature-gate-cross.rs b/tests/ui/augmented-assignments-feature-gate-cross.rs deleted file mode 100644 index d402d200617..00000000000 --- a/tests/ui/augmented-assignments-feature-gate-cross.rs +++ /dev/null @@ -1,11 +0,0 @@ -//@ run-pass -//@ aux-build:augmented_assignments.rs - -extern crate augmented_assignments; - -use augmented_assignments::Int; - -fn main() { - let mut x = Int(0); - x += 1; -} diff --git a/tests/ui/augmented-assignments-rpass.rs b/tests/ui/augmented-assignments-rpass.rs deleted file mode 100644 index 755ecb466ce..00000000000 --- a/tests/ui/augmented-assignments-rpass.rs +++ /dev/null @@ -1,172 +0,0 @@ -//@ run-pass - -#![allow(unused_imports)] -#![deny(unused_assignments)] - -use std::mem; -use std::ops::{ - AddAssign, BitAndAssign, BitOrAssign, BitXorAssign, DivAssign, Index, MulAssign, RemAssign, - ShlAssign, ShrAssign, SubAssign, -}; - -#[derive(Debug, PartialEq)] -struct Int(i32); - -struct Slice([i32]); - -impl Slice { - fn new(slice: &mut [i32]) -> &mut Slice { - unsafe { - mem::transmute(slice) - } - } -} - -struct View<'a>(&'a mut [i32]); - -fn main() { - let mut x = Int(1); - - x += Int(2); - assert_eq!(x, Int(0b11)); - - x &= Int(0b01); - assert_eq!(x, Int(0b01)); - - x |= Int(0b10); - assert_eq!(x, Int(0b11)); - - x ^= Int(0b01); - assert_eq!(x, Int(0b10)); - - x /= Int(2); - assert_eq!(x, Int(1)); - - x *= Int(3); - assert_eq!(x, Int(3)); - - x %= Int(2); - assert_eq!(x, Int(1)); - - // overloaded RHS - x <<= 1u8; - assert_eq!(x, Int(2)); - - x <<= 1u16; - assert_eq!(x, Int(4)); - - x >>= 1u8; - assert_eq!(x, Int(2)); - - x >>= 1u16; - assert_eq!(x, Int(1)); - - x -= Int(1); - assert_eq!(x, Int(0)); - - // indexed LHS - let mut v = vec![Int(1), Int(2)]; - v[0] += Int(2); - assert_eq!(v[0], Int(3)); - - // unsized RHS - let mut array = [0, 1, 2]; - *Slice::new(&mut array) += 1; - assert_eq!(array[0], 1); - assert_eq!(array[1], 2); - assert_eq!(array[2], 3); - - // sized indirection - // check that this does *not* trigger the unused_assignments lint - let mut array = [0, 1, 2]; - let mut view = View(&mut array); - view += 1; -} - -impl AddAssign for Int { - fn add_assign(&mut self, rhs: Int) { - self.0 += rhs.0; - } -} - -impl BitAndAssign for Int { - fn bitand_assign(&mut self, rhs: Int) { - self.0 &= rhs.0; - } -} - -impl BitOrAssign for Int { - fn bitor_assign(&mut self, rhs: Int) { - self.0 |= rhs.0; - } -} - -impl BitXorAssign for Int { - fn bitxor_assign(&mut self, rhs: Int) { - self.0 ^= rhs.0; - } -} - -impl DivAssign for Int { - fn div_assign(&mut self, rhs: Int) { - self.0 /= rhs.0; - } -} - -impl MulAssign for Int { - fn mul_assign(&mut self, rhs: Int) { - self.0 *= rhs.0; - } -} - -impl RemAssign for Int { - fn rem_assign(&mut self, rhs: Int) { - self.0 %= rhs.0; - } -} - -impl ShlAssign for Int { - fn shl_assign(&mut self, rhs: u8) { - self.0 <<= rhs; - } -} - -impl ShlAssign for Int { - fn shl_assign(&mut self, rhs: u16) { - self.0 <<= rhs; - } -} - -impl ShrAssign for Int { - fn shr_assign(&mut self, rhs: u8) { - self.0 >>= rhs; - } -} - -impl ShrAssign for Int { - fn shr_assign(&mut self, rhs: u16) { - self.0 >>= rhs; - } -} - -impl SubAssign for Int { - fn sub_assign(&mut self, rhs: Int) { - self.0 -= rhs.0; - } -} - -impl AddAssign for Slice { - fn add_assign(&mut self, rhs: i32) { - for lhs in &mut self.0 { - *lhs += rhs; - } - } -} - -impl<'a> AddAssign for View<'a> { - fn add_assign(&mut self, rhs: i32) { - for lhs in self.0.iter_mut() { - *lhs += rhs; - } - } -} diff --git a/tests/ui/augmented-assignments.rs b/tests/ui/augmented-assignments.rs deleted file mode 100644 index 35ab2d454f7..00000000000 --- a/tests/ui/augmented-assignments.rs +++ /dev/null @@ -1,28 +0,0 @@ -use std::ops::AddAssign; - -#[derive(Clone)] -struct Int(i32); - -impl AddAssign for Int { - fn add_assign(&mut self, _: Int) { - unimplemented!() - } -} - -fn main() { - let mut x = Int(1); //~ NOTE binding `x` declared here - x - //~^ NOTE borrow of `x` occurs here - += - x; - //~^ ERROR cannot move out of `x` because it is borrowed - //~| NOTE move out of `x` occurs here - - let y = Int(2); - //~^ HELP consider changing this to be mutable - //~| SUGGESTION mut - y //~ ERROR cannot borrow `y` as mutable, as it is not declared as mutable - //~| NOTE cannot borrow as mutable - += - Int(1); -} diff --git a/tests/ui/augmented-assignments.stderr b/tests/ui/augmented-assignments.stderr deleted file mode 100644 index a4b75cbf6e8..00000000000 --- a/tests/ui/augmented-assignments.stderr +++ /dev/null @@ -1,26 +0,0 @@ -error[E0505]: cannot move out of `x` because it is borrowed - --> $DIR/augmented-assignments.rs:17:5 - | -LL | let mut x = Int(1); - | ----- binding `x` declared here -LL | x - | - borrow of `x` occurs here -... -LL | x; - | ^ move out of `x` occurs here - -error[E0596]: cannot borrow `y` as mutable, as it is not declared as mutable - --> $DIR/augmented-assignments.rs:24:5 - | -LL | y - | ^ cannot borrow as mutable - | -help: consider changing this to be mutable - | -LL | let mut y = Int(2); - | +++ - -error: aborting due to 2 previous errors - -Some errors have detailed explanations: E0505, E0596. -For more information about an error, try `rustc --explain E0505`. diff --git a/tests/ui/auxiliary/augmented_assignments.rs b/tests/ui/auxiliary/augmented_assignments.rs deleted file mode 100644 index d0d3f57459a..00000000000 --- a/tests/ui/auxiliary/augmented_assignments.rs +++ /dev/null @@ -1,8 +0,0 @@ -use std::ops::AddAssign; - -pub struct Int(pub i32); - -impl AddAssign for Int { - fn add_assign(&mut self, _: i32) { - } -} diff --git a/tests/ui/binop/augmented-assignment.rs b/tests/ui/binop/augmented-assignment.rs new file mode 100644 index 00000000000..755ecb466ce --- /dev/null +++ b/tests/ui/binop/augmented-assignment.rs @@ -0,0 +1,172 @@ +//@ run-pass + +#![allow(unused_imports)] +#![deny(unused_assignments)] + +use std::mem; +use std::ops::{ + AddAssign, BitAndAssign, BitOrAssign, BitXorAssign, DivAssign, Index, MulAssign, RemAssign, + ShlAssign, ShrAssign, SubAssign, +}; + +#[derive(Debug, PartialEq)] +struct Int(i32); + +struct Slice([i32]); + +impl Slice { + fn new(slice: &mut [i32]) -> &mut Slice { + unsafe { + mem::transmute(slice) + } + } +} + +struct View<'a>(&'a mut [i32]); + +fn main() { + let mut x = Int(1); + + x += Int(2); + assert_eq!(x, Int(0b11)); + + x &= Int(0b01); + assert_eq!(x, Int(0b01)); + + x |= Int(0b10); + assert_eq!(x, Int(0b11)); + + x ^= Int(0b01); + assert_eq!(x, Int(0b10)); + + x /= Int(2); + assert_eq!(x, Int(1)); + + x *= Int(3); + assert_eq!(x, Int(3)); + + x %= Int(2); + assert_eq!(x, Int(1)); + + // overloaded RHS + x <<= 1u8; + assert_eq!(x, Int(2)); + + x <<= 1u16; + assert_eq!(x, Int(4)); + + x >>= 1u8; + assert_eq!(x, Int(2)); + + x >>= 1u16; + assert_eq!(x, Int(1)); + + x -= Int(1); + assert_eq!(x, Int(0)); + + // indexed LHS + let mut v = vec![Int(1), Int(2)]; + v[0] += Int(2); + assert_eq!(v[0], Int(3)); + + // unsized RHS + let mut array = [0, 1, 2]; + *Slice::new(&mut array) += 1; + assert_eq!(array[0], 1); + assert_eq!(array[1], 2); + assert_eq!(array[2], 3); + + // sized indirection + // check that this does *not* trigger the unused_assignments lint + let mut array = [0, 1, 2]; + let mut view = View(&mut array); + view += 1; +} + +impl AddAssign for Int { + fn add_assign(&mut self, rhs: Int) { + self.0 += rhs.0; + } +} + +impl BitAndAssign for Int { + fn bitand_assign(&mut self, rhs: Int) { + self.0 &= rhs.0; + } +} + +impl BitOrAssign for Int { + fn bitor_assign(&mut self, rhs: Int) { + self.0 |= rhs.0; + } +} + +impl BitXorAssign for Int { + fn bitxor_assign(&mut self, rhs: Int) { + self.0 ^= rhs.0; + } +} + +impl DivAssign for Int { + fn div_assign(&mut self, rhs: Int) { + self.0 /= rhs.0; + } +} + +impl MulAssign for Int { + fn mul_assign(&mut self, rhs: Int) { + self.0 *= rhs.0; + } +} + +impl RemAssign for Int { + fn rem_assign(&mut self, rhs: Int) { + self.0 %= rhs.0; + } +} + +impl ShlAssign for Int { + fn shl_assign(&mut self, rhs: u8) { + self.0 <<= rhs; + } +} + +impl ShlAssign for Int { + fn shl_assign(&mut self, rhs: u16) { + self.0 <<= rhs; + } +} + +impl ShrAssign for Int { + fn shr_assign(&mut self, rhs: u8) { + self.0 >>= rhs; + } +} + +impl ShrAssign for Int { + fn shr_assign(&mut self, rhs: u16) { + self.0 >>= rhs; + } +} + +impl SubAssign for Int { + fn sub_assign(&mut self, rhs: Int) { + self.0 -= rhs.0; + } +} + +impl AddAssign for Slice { + fn add_assign(&mut self, rhs: i32) { + for lhs in &mut self.0 { + *lhs += rhs; + } + } +} + +impl<'a> AddAssign for View<'a> { + fn add_assign(&mut self, rhs: i32) { + for lhs in self.0.iter_mut() { + *lhs += rhs; + } + } +} diff --git a/tests/ui/binop/augmented-assignments-cross-crate.rs b/tests/ui/binop/augmented-assignments-cross-crate.rs new file mode 100644 index 00000000000..6dbb0350988 --- /dev/null +++ b/tests/ui/binop/augmented-assignments-cross-crate.rs @@ -0,0 +1,13 @@ +//! Smoke test for overloaded compound assignments cross-crate. + +//@ run-pass +//@ aux-build:augmented_assignments.rs + +extern crate augmented_assignments; + +use augmented_assignments::Int; + +fn main() { + let mut x = Int(0); + x += 1; +} diff --git a/tests/ui/binop/auxiliary/augmented_assignments.rs b/tests/ui/binop/auxiliary/augmented_assignments.rs new file mode 100644 index 00000000000..d0d3f57459a --- /dev/null +++ b/tests/ui/binop/auxiliary/augmented_assignments.rs @@ -0,0 +1,8 @@ +use std::ops::AddAssign; + +pub struct Int(pub i32); + +impl AddAssign for Int { + fn add_assign(&mut self, _: i32) { + } +} diff --git a/tests/ui/borrowck/augmented-assignments.rs b/tests/ui/borrowck/augmented-assignments.rs new file mode 100644 index 00000000000..d717dcc7935 --- /dev/null +++ b/tests/ui/borrowck/augmented-assignments.rs @@ -0,0 +1,31 @@ +//! Check that overloaded compound assignment operators respect usual borrowck rules and emit +//! reasonable diagnostics. + +use std::ops::AddAssign; + +#[derive(Clone)] +struct Int(i32); + +impl AddAssign for Int { + fn add_assign(&mut self, _: Int) { + unimplemented!() + } +} + +fn main() { + let mut x = Int(1); //~ NOTE binding `x` declared here + x + //~^ NOTE borrow of `x` occurs here + += + x; + //~^ ERROR cannot move out of `x` because it is borrowed + //~| NOTE move out of `x` occurs here + + let y = Int(2); + //~^ HELP consider changing this to be mutable + //~| SUGGESTION mut + y //~ ERROR cannot borrow `y` as mutable, as it is not declared as mutable + //~| NOTE cannot borrow as mutable + += + Int(1); +} diff --git a/tests/ui/borrowck/augmented-assignments.stderr b/tests/ui/borrowck/augmented-assignments.stderr new file mode 100644 index 00000000000..4b945cd998a --- /dev/null +++ b/tests/ui/borrowck/augmented-assignments.stderr @@ -0,0 +1,26 @@ +error[E0505]: cannot move out of `x` because it is borrowed + --> $DIR/augmented-assignments.rs:20:5 + | +LL | let mut x = Int(1); + | ----- binding `x` declared here +LL | x + | - borrow of `x` occurs here +... +LL | x; + | ^ move out of `x` occurs here + +error[E0596]: cannot borrow `y` as mutable, as it is not declared as mutable + --> $DIR/augmented-assignments.rs:27:5 + | +LL | y + | ^ cannot borrow as mutable + | +help: consider changing this to be mutable + | +LL | let mut y = Int(2); + | +++ + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0505, E0596. +For more information about an error, try `rustc --explain E0505`. -- cgit 1.4.1-3-g733a5 From b47fe51610fbe0d8d983f3ace0682044a1a450c3 Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Sat, 19 Apr 2025 17:29:31 +0800 Subject: tests: adjust `tests/ui/auto-instantiate.rs` - Reformat the test. - Document test intention. - Move test under `tests/ui/inference/`. --- tests/ui/auto-instantiate.rs | 13 ------------- tests/ui/inference/auto-instantiate.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 13 deletions(-) delete mode 100644 tests/ui/auto-instantiate.rs create mode 100644 tests/ui/inference/auto-instantiate.rs (limited to 'tests') diff --git a/tests/ui/auto-instantiate.rs b/tests/ui/auto-instantiate.rs deleted file mode 100644 index 73ad5d701e1..00000000000 --- a/tests/ui/auto-instantiate.rs +++ /dev/null @@ -1,13 +0,0 @@ -//@ run-pass - -#![allow(dead_code)] -#[derive(Debug)] -struct Pair { a: T, b: U } -struct Triple { x: isize, y: isize, z: isize } - -fn f(x: T, y: U) -> Pair { return Pair {a: x, b: y}; } - -pub fn main() { - println!("{}", f(Triple {x: 3, y: 4, z: 5}, 4).a.x); - println!("{}", f(5, 6).a); -} diff --git a/tests/ui/inference/auto-instantiate.rs b/tests/ui/inference/auto-instantiate.rs new file mode 100644 index 00000000000..bf43330a0b7 --- /dev/null +++ b/tests/ui/inference/auto-instantiate.rs @@ -0,0 +1,28 @@ +//! Check that type parameters in generic function arg position and in "nested" return type position +//! can be inferred on an invocation of the generic function. +//! +//! See . + +//@ run-pass + +#![allow(dead_code)] +#[derive(Debug)] +struct Pair { + a: T, + b: U, +} + +struct Triple { + x: isize, + y: isize, + z: isize, +} + +fn f(x: T, y: U) -> Pair { + return Pair { a: x, b: y }; +} + +pub fn main() { + println!("{}", f(Triple {x: 3, y: 4, z: 5}, 4).a.x); + println!("{}", f(5, 6).a); +} -- cgit 1.4.1-3-g733a5