cleaned up some tests

Additionally, remove unused `tests/ui/auxiliary/svh-*` crates that are duplicates of `tests/ui/svh/auxiliary/svh-*`.
This commit is contained in:
Kivooeo
2025-07-01 20:20:14 +05:00
parent 47b8a32ca3
commit 98934707eb
27 changed files with 161 additions and 97 deletions
-25
View File
@@ -1,25 +0,0 @@
//! The `svh-a-*.rs` files are all deviations from the base file
//! svh-a-base.rs with some difference (usually in `fn foo`) that
//! should not affect the strict version hash (SVH) computation
//! (#14132).
#![crate_name = "a"]
macro_rules! three {
() => { 3 }
}
pub trait U {}
pub trait V {}
impl U for () {}
impl V for () {}
static A_CONSTANT : isize = 2;
pub fn foo<T:U>(_: isize) -> isize {
3
}
pub fn an_unused_name() -> isize {
4
}
-13
View File
@@ -1,13 +0,0 @@
//! This is a client of the `a` crate defined in `svn-a-base.rs`. The
//! rpass and cfail tests (such as `run-pass/svh-add-comment.rs`) use
//! it by swapping in a different object code library crate built from
//! some variant of `svn-a-base.rs`, and then we are checking if the
//! compiler properly ignores or accepts the change, based on whether
//! the change could affect the downstream crate content or not
//! (#14132).
#![crate_name = "b"]
extern crate a;
pub fn foo() { assert_eq!(a::foo::<()>(0), 3); }
@@ -1,5 +1,10 @@
//! This test verifies that a direct non-primitive cast from an enum to an integer type
//! is correctly disallowed, even when a `From` implementation exists for that enum.
//@ run-rustfix
#![allow(dead_code, unused_variables)]
enum NonNullary {
Nullary,
Other(isize),
@@ -16,5 +21,7 @@ impl From<NonNullary> for isize {
fn main() {
let v = NonNullary::Nullary;
let val = isize::from(v); //~ ERROR non-primitive cast: `NonNullary` as `isize` [E0605]
let val = isize::from(v);
//~^ ERROR non-primitive cast: `NonNullary` as `isize` [E0605]
//~| HELP consider using the `From` trait instead
}
@@ -1,5 +1,10 @@
//! This test verifies that a direct non-primitive cast from an enum to an integer type
//! is correctly disallowed, even when a `From` implementation exists for that enum.
//@ run-rustfix
#![allow(dead_code, unused_variables)]
enum NonNullary {
Nullary,
Other(isize),
@@ -16,5 +21,7 @@ fn from(val: NonNullary) -> isize {
fn main() {
let v = NonNullary::Nullary;
let val = v as isize; //~ ERROR non-primitive cast: `NonNullary` as `isize` [E0605]
let val = v as isize;
//~^ ERROR non-primitive cast: `NonNullary` as `isize` [E0605]
//~| HELP consider using the `From` trait instead
}
@@ -1,5 +1,5 @@
error[E0605]: non-primitive cast: `NonNullary` as `isize`
--> $DIR/tag-variant-cast-non-nullary.rs:19:15
--> $DIR/cast-enum-to-primitive-error.rs:24:15
|
LL | let val = v as isize;
| ^^^^^^^^^^ an `as` expression can be used to convert enum types to numeric types only if the enum type is unit-only or field-less
+3 -1
View File
@@ -1,5 +1,7 @@
//! This test checks that various forms of "trivial" casts and coercions
//! can be explicitly performed using the `as` keyword without compilation errors.
//@ run-pass
// Test that all coercions can actually be done using casts (modulo the lints).
#![allow(trivial_casts, trivial_numeric_casts)]
@@ -1,5 +1,5 @@
warning: method `foo` is never used
--> $DIR/trivial_casts-rpass.rs:7:8
--> $DIR/coercion-as-explicit-cast.rs:9:8
|
LL | trait Foo {
| --- method in this trait
+13 -4
View File
@@ -1,6 +1,15 @@
enum Quux<T> { Bar }
//~^ ERROR: parameter `T` is never used
//! This test checks that unused generics are rejected by compiler
fn foo(c: Quux) { assert!((false)); } //~ ERROR missing generics for enum `Quux`
enum Quux<T> {
//~^ ERROR: parameter `T` is never used
Bar,
}
fn main() { panic!(); }
fn foo(c: Quux) {
//~^ ERROR missing generics for enum `Quux`
assert!((false));
}
fn main() {
panic!();
}
+7 -7
View File
@@ -1,26 +1,26 @@
error[E0392]: type parameter `T` is never used
--> $DIR/tag-type-args.rs:1:11
--> $DIR/generic-enum-errors.rs:3:11
|
LL | enum Quux<T> { Bar }
LL | enum Quux<T> {
| ^ unused type parameter
|
= help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
= help: if you intended `T` to be a const parameter, use `const T: /* Type */` instead
error[E0107]: missing generics for enum `Quux`
--> $DIR/tag-type-args.rs:4:11
--> $DIR/generic-enum-errors.rs:8:11
|
LL | fn foo(c: Quux) { assert!((false)); }
LL | fn foo(c: Quux) {
| ^^^^ expected 1 generic argument
|
note: enum defined here, with 1 generic parameter: `T`
--> $DIR/tag-type-args.rs:1:6
--> $DIR/generic-enum-errors.rs:3:6
|
LL | enum Quux<T> { Bar }
LL | enum Quux<T> {
| ^^^^ -
help: add missing generic argument
|
LL | fn foo(c: Quux<T>) { assert!((false)); }
LL | fn foo(c: Quux<T>) {
| +++
error: aborting due to 2 previous errors
+4 -3
View File
@@ -1,3 +1,5 @@
//! Check path resolution using `super`
//@ run-pass
#![allow(dead_code)]
@@ -6,10 +8,9 @@ pub mod a {
pub fn f() {}
pub mod b {
fn g() {
super::f();
super::f(); // Accessing `f` from module `a` (parent of `b`)
}
}
}
pub fn main() {
}
pub fn main() {}
+4 -2
View File
@@ -1,4 +1,6 @@
//! Check that `super` keyword used at the crate root (top-level) results in a compilation error
//! as there is no parent module to resolve.
use super::f; //~ ERROR there are too many leading `super` keywords
fn main() {
}
fn main() {}
+1 -1
View File
@@ -1,5 +1,5 @@
error[E0433]: failed to resolve: there are too many leading `super` keywords
--> $DIR/super-at-top-level.rs:1:5
--> $DIR/super-at-crate-root.rs:4:5
|
LL | use super::f;
| ^^^^^ there are too many leading `super` keywords
@@ -1,3 +1,11 @@
//! Checks trailing commas are accepted in various places:
//! - Generic parameters in function and struct definitions.
//! - Function and method arguments.
//! - Tuple and array literal expressions.
//! - Tuple and array destructuring patterns, including those with `..`.
//! - Enum variant declarations.
//! - Attributes.
//@ run-pass
fn f<T,>(_: T,) {}
+5 -1
View File
@@ -1,9 +1,13 @@
//! Check the basic functionality of `std::mem::swap` to ensure it correctly
//! exchanges the values of two mutable variables.
//@ run-pass
use std::mem::swap;
pub fn main() {
let mut x = 3; let mut y = 7;
let mut x = 3;
let mut y = 7;
swap(&mut x, &mut y);
assert_eq!(x, 7);
assert_eq!(y, 3);
@@ -1,17 +1,17 @@
//! Check that `std::ptr::swap` behaves correctly when the source and destination
//! pointers refer to the same memory location, avoiding issues like overlapping `memcpy`.
//!
//! Regression test: <https://github.com/rust-lang/rust/issues/5041>
//@ run-pass
#![allow(dead_code)]
// Issue #5041 - avoid overlapping memcpy when src and dest of a swap are the same
use std::ptr;
pub fn main() {
let mut test = TestDescAndFn {
desc: TestDesc {
name: TestName::DynTestName("test".to_string()),
should_fail: false
},
desc: TestDesc { name: TestName::DynTestName("test".to_string()), should_fail: false },
testfn: TestFn::DynTestFn(22),
};
do_swap(&mut test);
@@ -24,7 +24,7 @@ fn do_swap(test: &mut TestDescAndFn) {
}
pub enum TestName {
DynTestName(String)
DynTestName(String),
}
pub enum TestFn {
@@ -34,7 +34,7 @@ pub enum TestFn {
pub struct TestDesc {
name: TestName,
should_fail: bool
should_fail: bool,
}
pub struct TestDescAndFn {
@@ -1,7 +1,14 @@
//@ run-pass
// use of tail calls causes arg slot leaks, issue #160.
//! This test verifies that tail call optimization does not lead to argument slot leaks.
//!
//! Regression test for: <https://github.com/rust-lang/rust/issues/160>
fn inner(dummy: String, b: bool) { if b { return inner(dummy, false); } }
//@ run-pass
fn inner(dummy: String, b: bool) {
if b {
return inner(dummy, false);
}
}
pub fn main() {
inner("hi".to_string(), true);
+21 -4
View File
@@ -1,17 +1,34 @@
//! Verify that mutually recursive functions use CPS to avoid overflowing the stack.
//@ run-pass
fn checktrue(rs: bool) -> bool { assert!(rs); return true; }
fn checktrue(rs: bool) -> bool {
assert!(rs);
return true;
}
pub fn main() { let k = checktrue; evenk(42, k); oddk(45, k); }
pub fn main() {
let k = checktrue;
evenk(42, k);
oddk(45, k);
}
fn evenk(n: isize, k: fn(bool) -> bool) -> bool {
println!("evenk");
println!("{}", n);
if n == 0 { return k(true); } else { return oddk(n - 1, k); }
if n == 0 {
return k(true);
} else {
return oddk(n - 1, k);
}
}
fn oddk(n: isize, k: fn(bool) -> bool) -> bool {
println!("oddk");
println!("{}", n);
if n == 0 { return k(false); } else { return evenk(n - 1, k); }
if n == 0 {
return k(false);
} else {
return evenk(n - 1, k);
}
}
@@ -1,10 +1,17 @@
//! This test verifies that the Signature Version Hash (SVH) system correctly identifies
//! when changes to an auxiliary crate do not affect its public API.
//!
//! Specifically, it checks that adding non-public items to a crate does not alter
//! its SVH, preventing unnecessary recompilations of dependent crates.
//@ run-pass
// note that these aux-build directives must be in this order
// Note that these aux-build directives must be in this order
//@ aux-build:svh-a-base.rs
//@ aux-build:svh-b.rs
//@ aux-build:svh-a-base.rs
extern crate a;
extern crate b;
@@ -1,10 +1,15 @@
//! This test verifies that implementing a trait method with a signature that does not
//! exactly match its declaration in the trait results in a compilation error.
//! Specifically, it checks for errors when the number of parameters or the return type
//! in the `impl` differs from the trait definition.
trait Foo {
fn foo(&mut self, x: i32, y: i32) -> i32;
}
impl Foo for i32 {
fn foo(
&mut self, //~ ERROR
&mut self, //~ ERROR method `foo` has 2 parameters but the declaration
x: i32,
) {
}
@@ -1,5 +1,5 @@
error[E0050]: method `foo` has 2 parameters but the declaration in trait `Foo::foo` has 3
--> $DIR/trait-method-number-parameters.rs:7:9
--> $DIR/trait-method-signature-mismatch.rs:12:9
|
LL | fn foo(&mut self, x: i32, y: i32) -> i32;
| ------------------------- trait requires 3 parameters
@@ -1,12 +1,19 @@
//! This test verifies that `std::num::TryFromIntError` correctly implements `PartialEq`,
//! allowing `Result<T, TryFromIntError>` values to be compared for equality using `==`.
//! It specifically checks a successful numeric conversion scenario where the `Result::Ok`
//! variant is compared, ensuring that the comparison yields the expected boolean result.
//@ run-pass
#![allow(unused_must_use)]
#![allow(unused_must_use)] // Allow ignoring the result of the comparison for the test's purpose
use std::convert::TryFrom;
use std::num::TryFromIntError;
fn main() {
let x: u32 = 125;
// Attempt to convert u32 to u8, which should succeed as 125 fits in u8.
let y: Result<u8, TryFromIntError> = u8::try_from(x);
// Verify that the Result can be correctly compared with an Ok value.
y == Ok(125);
}
@@ -1,10 +1,14 @@
//@ run-pass
// Issue #7988
// Transmuting non-immediate type to immediate type
//! Verify transmuting from a single-element array to a scalar is allowed.
//!
//! Regression test: <https://github.com/rust-lang/rust/issues/7988>
//@ run-pass
pub fn main() {
unsafe {
::std::mem::transmute::<[isize; 1],isize>([1])
};
// Transmute a single-element array `[1]` (which might be treated as a "non-immediate" type)
// to a scalar `isize` (an "immediate" type).
// This is safe because `[isize; 1]` and `isize` have the same size and alignment.
::std::mem::transmute::<[isize; 1], isize>([1]);
}
}
@@ -1,3 +1,5 @@
//! Verify transmuting is allowed when `Src` and `Dst` are the same associated type.
//@ check-pass
trait Foo {
@@ -1,3 +1,7 @@
//! Check that a `mismatched types` error (E0308) is correctly reported when attempting to
//! bind a reference to an `i32` to a reference to a `String`.
//! Ensure `ref` bindings report a mismatched type error.
fn main() {
let var = 10i32;
let ref string: String = var; //~ ERROR mismatched types [E0308]
@@ -1,5 +1,5 @@
error[E0308]: mismatched types
--> $DIR/switched-expectations.rs:3:30
--> $DIR/mismatched-types-ref-binding.rs:7:30
|
LL | let ref string: String = var;
| ^^^ expected `String`, found `i32`
+12 -3
View File
@@ -1,5 +1,14 @@
fn f() -> isize { return g(); } //~ ERROR mismatched types
//! Test for type mismatch error when returning `usize` from `isize` function.
fn g() -> usize { return 0; }
fn f() -> isize {
return g();
//~^ ERROR mismatched types [E0308]
}
fn main() { let y = f(); }
fn g() -> usize {
return 0;
}
fn main() {
let y = f();
}
@@ -1,15 +1,15 @@
error[E0308]: mismatched types
--> $DIR/tail-typeck.rs:1:26
--> $DIR/tail-return-type-mismatch.rs:4:12
|
LL | fn f() -> isize { return g(); }
| ----- ^^^ expected `isize`, found `usize`
| |
| expected `isize` because of return type
LL | fn f() -> isize {
| ----- expected `isize` because of return type
LL | return g();
| ^^^ expected `isize`, found `usize`
|
help: you can convert a `usize` to an `isize` and panic if the converted value doesn't fit
|
LL | fn f() -> isize { return g().try_into().unwrap(); }
| ++++++++++++++++++++
LL | return g().try_into().unwrap();
| ++++++++++++++++++++
error: aborting due to 1 previous error