Skip to content

tests/ui: A New Order [27/N] #143302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
//! Checks how type parameters interact with auto-traits like `Send` and `Sync` (implicitly),
//! even when no explicit trait bounds are provided for `Send` or `Sync`.

//@ 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() {
Expand Down
15 changes: 15 additions & 0 deletions tests/ui/consts/const-eval-array-len-in-impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! 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();
}

impl Foo for [(); 1] {
fn foo() {}
}

fn main() {
<[(); 0] as Foo>::foo() //~ ERROR E0277
}
Original file line number Diff line number Diff line change
@@ -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]`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Checks basic multiple variable declaration using tuple destructuring in a `let` binding.

//@ run-pass

pub fn main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
//! Checks that `std::any::Any` cannot be used to circumvent lifetime rules
//! particularly 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);
Expand All @@ -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> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
//~ ERROR reached the type-length limit

//! Checks the enforcement of the type-length limit
//! and its configurability via `#![type_length_limit]`.

//@ build-fail
//@ compile-flags: -Copt-level=0 -Zenforce-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.

#![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 }
Expand All @@ -26,7 +30,7 @@ link! { D, E }
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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:36: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`
|
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/macros/macro-fragment-ident-underscore-error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//! 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
};
}

fn main() {
let identity!(_) = 10; //~ ERROR no rules expected reserved identifier `_`
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions tests/ui/namespace/struct-type-and-function-name-coexistence.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//@ run-pass

struct A {
a: isize,
}

fn a(a: A) -> isize {
return a.a;
}

pub fn main() {
let x: A = A { a: 1 };
assert_eq!(a(x), 1);
}
15 changes: 15 additions & 0 deletions tests/ui/parser/integer-literal-method-call-underscore.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! 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 {
fn _method_on_numbers(self) {}
}

impl Tr for i32 {}

fn main() {
42._method_on_numbers();
}
18 changes: 18 additions & 0 deletions tests/ui/ptr_ops/ptr-write-bool-representation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//! 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;

pub fn main() {
unsafe {
let mut x: bool = false;
// this line breaks it
ptr::write(&mut x, false);
}
}
18 changes: 18 additions & 0 deletions tests/ui/ptr_ops/raw-pointer-type-basic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +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 g(a: *const isize) -> *const isize {
let b = f(a);
return b;
}

pub fn main() {
return;
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
//! Checks the `?` operator expansion.

//@ 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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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>())?)
Expand All @@ -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 };

Expand Down Expand Up @@ -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();
Expand All @@ -98,19 +107,11 @@ fn on_args() -> Result<i32, ParseIntError> {
}

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> {
Expand All @@ -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?)
Expand Down
14 changes: 0 additions & 14 deletions tests/ui/tydesc-name.rs

This file was deleted.

10 changes: 10 additions & 0 deletions tests/ui/type-inference/type-inference-none-in-generic-ref.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//! Checks that compiler prevent from using a reference
//! to an unconstrained `None` in generic context

struct S<'a, T: 'a> {
o: &'a Option<T>,
}

fn main() {
S { o: &None }; //~ ERROR type annotations needed [E0282]
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0282]: type annotations needed
--> $DIR/unconstrained-ref.rs:6:5
--> $DIR/type-inference-none-in-generic-ref.rs:9:5
|
LL | S { o: &None };
| ^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the struct `S`
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/type-inference/type-inference-unconstrained-none.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//! Regression test for <https://github.com/rust-lang/rust/issues/5062>.

fn main() {
None; //~ ERROR type annotations needed [E0282]
}
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
7 changes: 0 additions & 7 deletions tests/ui/type-namespace.rs

This file was deleted.

Loading
Loading