Rollup merge of #140036 - jieyouxu:ui-cleanup-4, r=compiler-errors

Advent of `tests/ui` (misc cleanups and improvements) [4/N]

Some `tests/ui/` housekeeping, to trim down number of tests directly under `tests/ui/`. Part of #133895.

### Review advice

- Best reviewed commit-by-commit.
- I can squash commits before merge, commits are separate to make it easier to review.
This commit is contained in:
Chris Denton 2025-04-21 18:53:17 +00:00 committed by GitHub
commit 204e9a0a8d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 76 additions and 33 deletions

View file

@ -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`

View file

@ -1,13 +0,0 @@
//@ run-pass
#![allow(dead_code)]
#[derive(Debug)]
struct Pair<T, U> { a: T, b: U }
struct Triple { x: isize, y: isize, z: isize }
fn f<T,U>(x: T, y: U) -> Pair<T, U> { 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);
}

View file

@ -1,3 +1,5 @@
//! Smoke test for overloaded compound assignments cross-crate.
//@ run-pass
//@ aux-build:augmented_assignments.rs

View file

@ -1,3 +1,6 @@
//! Check that overloaded compound assignment operators respect usual borrowck rules and emit
//! reasonable diagnostics.
use std::ops::AddAssign;
#[derive(Clone)]

View file

@ -1,5 +1,5 @@
error[E0505]: cannot move out of `x` because it is borrowed
--> $DIR/augmented-assignments.rs:17:5
--> $DIR/augmented-assignments.rs:20:5
|
LL | let mut x = Int(1);
| ----- binding `x` declared here
@ -10,7 +10,7 @@ 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
--> $DIR/augmented-assignments.rs:27:5
|
LL | y
| ^ cannot borrow as mutable

View file

@ -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 <https://github.com/rust-lang/rust/issues/45>.
//@ run-pass
#![allow(dead_code)]
#[derive(Debug)]
struct Pair<T, U> {
a: T,
b: U,
}
struct Triple {
x: isize,
y: isize,
z: isize,
}
fn f<T, U>(x: T, y: U) -> Pair<T, U> {
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);
}

View file

@ -0,0 +1,4 @@
error: target requires explicitly specifying a cpu with `-C target-cpu`
error: aborting due to 1 previous error

View file

@ -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`