Skip to content

tests/ui: A New Order [8/N] #142200

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 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions tests/ui/defaults-well-formedness.rs

This file was deleted.

5 changes: 0 additions & 5 deletions tests/ui/deprecation-in-force-unstable.rs

This file was deleted.

8 changes: 0 additions & 8 deletions tests/ui/deref-rc.rs

This file was deleted.

6 changes: 0 additions & 6 deletions tests/ui/deref.rs

This file was deleted.

19 changes: 0 additions & 19 deletions tests/ui/derive-uninhabited-enum-38885.rs

This file was deleted.

23 changes: 23 additions & 0 deletions tests/ui/derives/derive-debug-uninhabited-enum.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//! Regression test for derive(Debug) on enums with uninhabited variants.
//!
//! Ensures there are no special warnings about uninhabited types when deriving
//! Debug on an enum with uninhabited variants, only standard unused warnings.
//!
//! Issue: https://github.com/rust-lang/rust/issues/38885

//@ check-pass
//@ compile-flags: -Wunused

#[derive(Debug)]
enum Void {}

#[derive(Debug)]
enum Foo {
Bar(#[allow(dead_code)] u8),
Void(Void), //~ WARN variant `Void` is never constructed
}

fn main() {
let x = Foo::Bar(42);
println!("{:?}", x);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: variant `Void` is never constructed
--> $DIR/derive-uninhabited-enum-38885.rs:13:5
--> $DIR/derive-debug-uninhabited-enum.rs:17:5
|
LL | enum Foo {
| --- variant in this enum
Expand Down
46 changes: 0 additions & 46 deletions tests/ui/destructure-trait-ref.rs

This file was deleted.

20 changes: 0 additions & 20 deletions tests/ui/diverging-fallback-method-chain.rs

This file was deleted.

14 changes: 0 additions & 14 deletions tests/ui/diverging-fallback-option.rs

This file was deleted.

54 changes: 54 additions & 0 deletions tests/ui/generics/default-type-params-well-formedness.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//! Test for well-formedness checking of default type parameters.
//!
//! This test verifies that the compiler correctly handles various cases
//! where default type parameters may or may not be checked for well-formedness
//! in where clauses.
//!
//! Issue: https://github.com/rust-lang/rust/issues/49344

//@ run-pass

#![allow(dead_code)]

trait Trait<T> {}
struct Foo<U, V = i32>(U, V)
where
U: Trait<V>;

trait Marker {}
struct TwoParams<T, U>(T, U);
impl Marker for TwoParams<i32, i32> {}

// Clauses with more than 1 param are not checked.
struct IndividuallyBogus<T = i32, U = i32>(TwoParams<T, U>)
where
TwoParams<T, U>: Marker;

struct BogusTogether<T = u32, U = i32>(T, U)
where
TwoParams<T, U>: Marker;

// Clauses with non-defaulted params are not checked.
struct NonDefaultedInClause<T, U = i32>(TwoParams<T, U>)
where
TwoParams<T, U>: Marker;

struct DefaultedLhs<U, V = i32>(U, V)
where
V: Trait<U>;

// Dependent defaults are not checked.
struct Dependent<T, U = T>(T, U)
where
U: Copy;

trait SelfBound<T: Copy = Self> {}

// Not even for well-formedness.
struct WellFormedProjection<A, T = <A as Iterator>::Item>(A, T);

// Issue #49344, predicates with lifetimes should not be checked.
trait Scope<'a> {}
struct Request<'a, S: Scope<'a> = i32>(S, &'a ());

fn main() {}
19 changes: 19 additions & 0 deletions tests/ui/never_type/never-type-fallback-option.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//@ run-pass

#![allow(warnings)]

//! Tests type inference fallback to `!` (never type) in `Option` context.
//!
//! Regression test for issues:
//! - https://github.com/rust-lang/rust/issues/39808
//! - https://github.com/rust-lang/rust/issues/39984
//!
//! Checks that when creating `Option` from a diverging expression,
//! the type parameter defaults to `!` without requiring explicit annotations.

fn main() {
// This expression diverges, so its type is `!`
let c = Some({ return; });
// The type of `c` is inferred as `Option<!>`
c.unwrap();
}
29 changes: 29 additions & 0 deletions tests/ui/traits/trait-object-destructure.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//! Regression test for destructuring trait references (`&dyn T`/`Box<dyn T>`).
//! Checks cases where number of `&`/`Box` patterns (n) matches/doesn't match references (m).
//!
//! Issue: https://github.com/rust-lang/rust/issues/15031

#![feature(box_patterns)]

trait T {
fn foo(&self) {}
}

impl T for isize {}

fn main() {
// Valid cases: n < m (can dereference)
let &x = &(&1isize as &dyn T);
let &x = &&(&1isize as &dyn T);
let &&x = &&(&1isize as &dyn T);

// Error cases: n == m (cannot dereference trait object)
let &x = &1isize as &dyn T; //~ ERROR type `&dyn T` cannot be dereferenced
let &&x = &(&1isize as &dyn T); //~ ERROR type `&dyn T` cannot be dereferenced
let box x = Box::new(1isize) as Box<dyn T>; //~ ERROR type `Box<dyn T>` cannot be dereferenced

// Error cases: n > m (type mismatch)
let &&x = &1isize as &dyn T; //~ ERROR mismatched types
let &&&x = &(&1isize as &dyn T); //~ ERROR mismatched types
let box box x = Box::new(1isize) as Box<dyn T>; //~ ERROR mismatched types
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
error[E0033]: type `&dyn T` cannot be dereferenced
--> $DIR/destructure-trait-ref.rs:28:9
--> $DIR/trait-object-destructure.rs:21:9
|
LL | let &x = &1isize as &dyn T;
| ^^ type `&dyn T` cannot be dereferenced

error[E0033]: type `&dyn T` cannot be dereferenced
--> $DIR/destructure-trait-ref.rs:29:10
--> $DIR/trait-object-destructure.rs:22:10
|
LL | let &&x = &(&1isize as &dyn T);
| ^^ type `&dyn T` cannot be dereferenced

error[E0033]: type `Box<dyn T>` cannot be dereferenced
--> $DIR/destructure-trait-ref.rs:30:9
--> $DIR/trait-object-destructure.rs:23:9
|
LL | let box x = Box::new(1isize) as Box<dyn T>;
| ^^^^^ type `Box<dyn T>` cannot be dereferenced

error[E0308]: mismatched types
--> $DIR/destructure-trait-ref.rs:34:10
--> $DIR/trait-object-destructure.rs:26:10
|
LL | let &&x = &1isize as &dyn T;
| ^^ ----------------- this expression has type `&dyn T`
Expand All @@ -33,7 +33,7 @@ LL + let &x = &1isize as &dyn T;
|

error[E0308]: mismatched types
--> $DIR/destructure-trait-ref.rs:38:11
--> $DIR/trait-object-destructure.rs:27:11
|
LL | let &&&x = &(&1isize as &dyn T);
| ^^ -------------------- this expression has type `&&dyn T`
Expand All @@ -49,7 +49,7 @@ LL + let &&x = &(&1isize as &dyn T);
|

error[E0308]: mismatched types
--> $DIR/destructure-trait-ref.rs:42:13
--> $DIR/trait-object-destructure.rs:28:13
|
LL | let box box x = Box::new(1isize) as Box<dyn T>;
| ^^^^^ ------------------------------ this expression has type `Box<dyn T>`
Expand Down
23 changes: 23 additions & 0 deletions tests/ui/typeck/inference-method-chain-diverging-fallback.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//! Test type inference in method chains with diverging fallback.
//! Verifies that closure type in `unwrap_or_else` is properly inferred
//! when chained with other combinators and contains a diverging path.

//@ run-pass

#![allow(unused)]

use std::num::ParseIntError;

fn produce<T>() -> Result<&'static str, T> {
Ok("22")
}

fn main() {
// The closure's error type `T` must unify with `ParseIntError`,
// while the success type must be `usize` (from parse())
let x: usize = produce()
.and_then(|x| x.parse::<usize>()) // Explicit turbofish for clarity
.unwrap_or_else(|_| panic!()); // Diverging fallback

assert_eq!(x, 22);
}
Loading