cleaned up some tests

This commit is contained in:
Kivooeo
2025-07-01 21:46:28 +05:00
parent e9191ec57e
commit 3ad95cccf9
24 changed files with 132 additions and 86 deletions
@@ -1,24 +1,25 @@
//! Checks how type parameters interact with auto-traits like `Send` and `Sync` with implicit
//! bounds
//@ run-pass
#![allow(non_camel_case_types)]
#![allow(dead_code)]
fn p_foo<T>(_pinned: T) { }
fn s_foo<T>(_shared: T) { }
fn u_foo<T:Send>(_unique: T) { }
fn p_foo<T>(_pinned: T) {}
fn s_foo<T>(_shared: T) {}
fn u_foo<T: Send>(_unique: T) {}
struct r {
i: isize,
i: isize,
}
impl Drop for r {
fn drop(&mut self) {}
}
fn r(i:isize) -> r {
r {
i: i
}
fn r(i: isize) -> r {
r { i }
}
pub fn main() {
@@ -1,4 +1,6 @@
// https://github.com/rust-lang/rust/issues/49208
//! This checks that compiler correctly evaluate constant array lengths within trait `impl` headers.
//!
//! Regression test for <https://github.com/rust-lang/rust/issues/49208>.
trait Foo {
fn foo();
@@ -1,5 +1,5 @@
error[E0277]: the trait bound `[(); 0]: Foo` is not satisfied
--> $DIR/unevaluated_fixed_size_array_len.rs:12:6
--> $DIR/const-eval-array-len-in-impl.rs:14:6
|
LL | <[(); 0] as Foo>::foo()
| ^^^^^^^ the trait `Foo` is not implemented for `[(); 0]`
@@ -1,3 +1,5 @@
//! Checks basic multiple variable declaration using tuple destructuring in a `let` binding.
//@ run-pass
pub fn main() {
@@ -1,11 +1,15 @@
//! Checks that `std::any::Any` cannot be used to circumvent lifetime rules
//! with higher-rank types.
//@ run-pass
// Test that we can't ignore lifetimes by going through Any.
use std::any::Any;
struct Foo<'a>(&'a str);
fn good(s: &String) -> Foo<'_> { Foo(s) }
fn good(s: &String) -> Foo<'_> {
Foo(s)
}
fn bad1(s: String) -> Option<&'static str> {
let a: Box<dyn Any> = Box::new(good as fn(&String) -> Foo);
@@ -17,7 +21,9 @@ trait AsStr<'a, 'b> {
}
impl<'a> AsStr<'a, 'a> for String {
fn get(&'a self) -> &'a str { self }
fn get(&'a self) -> &'a str {
self
}
}
fn bad2(s: String) -> Option<&'static str> {
@@ -1,17 +1,19 @@
//@ build-fail
//@ compile-flags: -Copt-level=0 -Zenforce-type-length-limit
//~^^ ERROR reached the type-length limit
//~ ERROR reached the type-length limit
// Test that the type length limit can be changed.
// The exact type depends on optimizations, so disable them.
//! Checks the enforcement of the type-length limit
//! and its configurability via `#![type_length_limit]`.
//@ compile-flags: -Copt-level=0 -Zenforce-type-length-limit
//@ build-fail
#![allow(dead_code)]
#![type_length_limit="8"]
#![type_length_limit = "8"]
macro_rules! link {
($id:ident, $t:ty) => {
pub type $id = ($t, $t, $t);
}
};
}
link! { A1, B1 }
@@ -26,7 +28,7 @@ macro_rules! link {
link! { E, F }
link! { F, G<Option<i32>, Option<i32>> }
pub struct G<T, K>(std::marker::PhantomData::<(T, K)>);
pub struct G<T, K>(std::marker::PhantomData<(T, K)>);
fn main() {
drop::<Option<A>>(None);
@@ -1,11 +1,11 @@
error: reached the type-length limit while instantiating `std::mem::drop::<Option<((((..., ..., ...), ..., ...), ..., ...), ..., ...)>>`
--> $DIR/type_length_limit.rs:32:5
--> $DIR/type-length-limit-enforcement.rs:34:5
|
LL | drop::<Option<A>>(None);
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider adding a `#![type_length_limit="4010"]` attribute to your crate
= note: the full type name has been written to '$TEST_BUILD_DIR/type_length_limit.long-type.txt'
= note: the full type name has been written to '$TEST_BUILD_DIR/type-length-limit-enforcement.long-type.txt'
error: reached the type-length limit while instantiating `<{closure@rt::lang_start<()>::{closure#0}} as FnMut<()>>::call_mut`
|
@@ -1,7 +1,10 @@
//! Verifies that the reserved underscore `_` cannot be used as an `ident` fragment specifier
//! within a macro pattern, as it leads to a compilation error.
macro_rules! identity {
($i: ident) => (
($i: ident) => {
$i
)
};
}
fn main() {
@@ -1,5 +1,5 @@
error: no rules expected reserved identifier `_`
--> $DIR/underscore-ident-matcher.rs:8:19
--> $DIR/macro-fragment-ident-underscore-error.rs:11:19
|
LL | macro_rules! identity {
| --------------------- when calling this macro
@@ -8,9 +8,9 @@ LL | let identity!(_) = 10;
| ^ no rules expected this token in macro call
|
note: while trying to match meta-variable `$i:ident`
--> $DIR/underscore-ident-matcher.rs:2:6
--> $DIR/macro-fragment-ident-underscore-error.rs:5:6
|
LL | ($i: ident) => (
LL | ($i: ident) => {
| ^^^^^^^^^
error: aborting due to 1 previous error
@@ -1,7 +1,14 @@
//@ run-pass
struct A { a: isize }
struct A {
a: isize,
}
fn a(a: A) -> isize { return a.a; }
fn a(a: A) -> isize {
return a.a;
}
pub fn main() { let x: A = A {a: 1}; assert_eq!(a(x), 1); }
pub fn main() {
let x: A = A { a: 1 };
assert_eq!(a(x), 1);
}
@@ -1,6 +1,10 @@
//! Checks that methods with names starting with an underscore (`_`) can be
//! successfully called directly on integer literals, confirming the correct
//! parsing of such expressions where the underscore is part of the method identifier.
//@ run-pass
trait Tr : Sized {
trait Tr: Sized {
fn _method_on_numbers(self) {}
}
@@ -1,3 +1,10 @@
//! Validates the correct behavior of writing a `bool` value using `std::ptr::write`.
//!
//! This test addresses historical concerns regarding the internal representation of `bool`
//! (e.g., as `i1` in LLVM versus its byte-aligned memory layout) and checks that
//! `ptr::write` correctly handles this type without issues, confirming its memory
//! behavior is as expected.
//@ run-pass
use std::ptr;
+12 -3
View File
@@ -1,9 +1,18 @@
//! Checks the basic usage of raw pointers (`*const isize`) as function argument and return types.
//@ run-pass
#![allow(dead_code)]
fn f(a: *const isize) -> *const isize { return a; }
fn f(a: *const isize) -> *const isize {
return a;
}
fn g(a: *const isize) -> *const isize { let b = f(a); return b; }
fn g(a: *const isize) -> *const isize {
let b = f(a);
return b;
}
pub fn main() { return; }
pub fn main() {
return;
}
@@ -1,16 +1,14 @@
//! This test verifies that the `?` operator expansion is hygienic,
//! i.e., it's not affected by other `val` and `err` bindings that may be in scope.
//!
//! Note: Prior to the Try trait stabilization, `expr?` expanded to a match
//! with `val` and `err` bindings. The current implementation uses Try::branch()
//! but this test remains relevant for hygiene verification.
//@ run-pass
#![allow(non_upper_case_globals)]
#![allow(dead_code)]
// `expr?` expands to:
//
// match expr {
// Ok(val) => val,
// Err(err) => return Err(From::from(err)),
// }
//
// This test verifies that the expansion is hygienic, i.e., it's not affected by other `val` and
// `err` bindings that may be in scope.
use std::num::ParseIntError;
@@ -1,9 +1,11 @@
//! Checks the functionality of the `?` operator in various syntactic contexts.
//@ run-pass
#![allow(dead_code)]
use std::fs::File;
use std::io::{Read, self};
use std::io::{self, Read};
use std::num::ParseIntError;
use std::str::FromStr;
@@ -35,7 +37,9 @@ fn on_path() -> Result<i32, ParseIntError> {
fn on_macro() -> Result<i32, ParseIntError> {
macro_rules! id {
($e:expr) => { $e }
($e:expr) => {
$e
};
}
Ok(id!("7".parse::<i32>())?)
@@ -50,11 +54,14 @@ fn on_parens() -> Result<i32, ParseIntError> {
fn on_block() -> Result<i32, ParseIntError> {
let x = "9".parse::<i32>();
Ok({x}?)
Ok({ x }?)
}
fn on_field() -> Result<i32, ParseIntError> {
struct Pair<A, B> { a: A, b: B }
struct Pair<A, B> {
a: A,
b: B,
}
let x = Pair { a: "10".parse::<i32>(), b: 0 };
@@ -89,7 +96,9 @@ fn on_index() -> Result<i32, ParseIntError> {
}
fn on_args() -> Result<i32, ParseIntError> {
fn sub(x: i32, y: i32) -> i32 { x - y }
fn sub(x: i32, y: i32) -> i32 {
x - y
}
let x = "20".parse();
let y = "21".parse();
@@ -98,19 +107,11 @@ fn sub(x: i32, y: i32) -> i32 { x - y }
}
fn on_if() -> Result<i32, ParseIntError> {
Ok(if true {
"22".parse::<i32>()
} else {
"23".parse::<i32>()
}?)
Ok(if true { "22".parse::<i32>() } else { "23".parse::<i32>() }?)
}
fn on_if_let() -> Result<i32, ParseIntError> {
Ok(if let Ok(..) = "24".parse::<i32>() {
"25".parse::<i32>()
} else {
"26".parse::<i32>()
}?)
Ok(if let Ok(..) = "24".parse::<i32>() { "25".parse::<i32>() } else { "26".parse::<i32>() }?)
}
fn on_match() -> Result<i32, ParseIntError> {
@@ -121,7 +122,9 @@ fn on_match() -> Result<i32, ParseIntError> {
}
fn tight_binding() -> Result<bool, ()> {
fn ok<T>(x: T) -> Result<T, ()> { Ok(x) }
fn ok<T>(x: T) -> Result<T, ()> {
Ok(x)
}
let x = ok(true);
Ok(!x?)
@@ -1,5 +1,7 @@
struct S<'a, T:'a> {
o: &'a Option<T>
//! Checks that unconstrained `None` is rejected through references and generics
struct S<'a, T: 'a> {
o: &'a Option<T>,
}
fn main() {
@@ -1,5 +1,5 @@
error[E0282]: type annotations needed
--> $DIR/unconstrained-ref.rs:6:5
--> $DIR/type-inference-none-in-generic-ref.rs:8:5
|
LL | S { o: &None };
| ^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the struct `S`
@@ -1,4 +1,4 @@
// Issue #5062
//! Regression test for <https://github.com/rust-lang/rust/issues/5062>.
fn main() {
None; //~ ERROR type annotations needed [E0282]
@@ -1,5 +1,5 @@
error[E0282]: type annotations needed
--> $DIR/unconstrained-none.rs:4:5
--> $DIR/type-inference-unconstrained-none.rs:4:5
|
LL | None;
| ^^^^ cannot infer type of the type parameter `T` declared on the enum `Option`
+5 -2
View File
@@ -1,3 +1,6 @@
//! Checks the basic functionality of `std::any::type_name` for primitive types
//! and simple generic structs.
//@ run-pass
#![allow(dead_code)]
@@ -5,10 +8,10 @@
use std::any::type_name;
struct Foo<T> {
x: T
x: T,
}
pub fn main() {
assert_eq!(type_name::<isize>(), "isize");
assert_eq!(type_name::<Foo<usize>>(), "tydesc_name::Foo<usize>");
assert_eq!(type_name::<Foo<usize>>(), "type_name_basic::Foo<usize>");
}
@@ -1,16 +1,18 @@
//! Checks the correctness and consistency of `std::any::TypeId::of`.
//@ run-pass
#![allow(deprecated)]
//@ aux-build:typeid-intrinsic-aux1.rs
//@ aux-build:typeid-intrinsic-aux2.rs
#![feature(core_intrinsics)]
extern crate typeid_intrinsic_aux1 as other1;
extern crate typeid_intrinsic_aux2 as other2;
//@ aux-build:typeid-consistency-aux1.rs
//@ aux-build:typeid-consistency-aux2.rs
extern crate typeid_consistency_aux1 as other1;
extern crate typeid_consistency_aux2 as other2;
use std::hash::{SipHasher, Hasher, Hash};
use std::any::TypeId;
use std::hash::{Hash, Hasher, SipHasher};
struct A;
struct Test;
@@ -34,7 +36,7 @@ pub fn main() {
assert_eq!(TypeId::of::<other2::F>(), other2::id_F());
assert_eq!(TypeId::of::<other2::G>(), other2::id_G());
assert_eq!(TypeId::of::<other2::H>(), other2::id_H());
assert_eq!(TypeId::of::<other1::I>(), other2::id_I());
assert_eq!(TypeId::of::<other2::I>(), other2::id_I());
assert_eq!(other1::id_F(), other2::id_F());
assert_eq!(other1::id_G(), other2::id_G());
@@ -49,10 +51,8 @@ pub fn main() {
assert_eq!(other2::foo::<A>(), other1::foo::<A>());
// sanity test of TypeId
let (a, b, c) = (TypeId::of::<usize>(), TypeId::of::<&'static str>(),
TypeId::of::<Test>());
let (d, e, f) = (TypeId::of::<usize>(), TypeId::of::<&'static str>(),
TypeId::of::<Test>());
let (a, b, c) = (TypeId::of::<usize>(), TypeId::of::<&'static str>(), TypeId::of::<Test>());
let (d, e, f) = (TypeId::of::<usize>(), TypeId::of::<&'static str>(), TypeId::of::<Test>());
assert!(a != b);
assert!(a != c);
@@ -82,10 +82,7 @@ pub fn main() {
assert_ne!(TypeId::of::<other1::I32Iterator>(), TypeId::of::<other1::U32Iterator>());
// Check fn pointer against collisions
assert_ne!(
TypeId::of::<fn(fn(A) -> A) -> A>(),
TypeId::of::<fn(fn() -> A, A) -> A>()
);
assert_ne!(TypeId::of::<fn(fn(A) -> A) -> A>(), TypeId::of::<fn(fn() -> A, A) -> A>());
assert_ne!(
TypeId::of::<for<'a> fn(&'a i32) -> &'a i32>(),
TypeId::of::<for<'a> fn(&'a i32) -> &'static i32>()
@@ -1,6 +1,9 @@
//! Checks the correct usage and behavior of the anonymous lifetime `'_` (underscore lifetime)
//@ run-pass
#![allow(dead_code, mismatched_lifetime_syntaxes)]
struct Foo<'a>(&'a u8);
fn foo(x: &u8) -> Foo<'_> {
@@ -31,8 +34,5 @@ fn main() {
let _ = foo2(x);
let _ = foo3(x);
foo4(Foo(x));
let _ = foo5(Foo2 {
a: x,
b: &6,
});
let _ = foo5(Foo2 { a: x, b: &6 });
}