Rollup merge of #142200 - Kivooeo:tf8, r=jieyouxu
`tests/ui`: A New Order [8/N] Some `tests/ui/` housekeeping, to trim down number of tests directly under `tests/ui/`. Part of rust-lang/rust#133895.
This commit is contained in:
commit
131a2e47fb
15 changed files with 151 additions and 148 deletions
|
|
@ -1,27 +0,0 @@
|
|||
//@ 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() {}
|
||||
|
|
@ -2,4 +2,4 @@
|
|||
//@ compile-flags:-Zforce-unstable-if-unmarked
|
||||
|
||||
#[deprecated] // should work even with -Zforce-unstable-if-unmarked
|
||||
fn main() { }
|
||||
fn main() {}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
//@ run-pass
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
fn main() {
|
||||
let x = Rc::new([1, 2, 3, 4]);
|
||||
assert_eq!(*x, [1, 2, 3, 4]);
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
//@ run-pass
|
||||
|
||||
pub fn main() {
|
||||
let x: Box<isize> = Box::new(10);
|
||||
let _y: isize = *x;
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
//@ check-pass
|
||||
//@ compile-flags: -Wunused
|
||||
|
||||
// ensure there are no special warnings about uninhabited types
|
||||
// when deriving Debug on an empty enum
|
||||
|
||||
#[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);
|
||||
}
|
||||
23
tests/ui/derives/derive-debug-uninhabited-enum.rs
Normal file
23
tests/ui/derives/derive-debug-uninhabited-enum.rs
Normal file
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
// The regression test for #15031 to make sure destructuring trait
|
||||
// reference work properly.
|
||||
|
||||
//@ dont-require-annotations: NOTE
|
||||
|
||||
#![feature(box_patterns)]
|
||||
|
||||
trait T { fn foo(&self) {} }
|
||||
impl T for isize {}
|
||||
|
||||
|
||||
fn main() {
|
||||
// For an expression of the form:
|
||||
//
|
||||
// let &...&x = &..&SomeTrait;
|
||||
//
|
||||
// Say we have n `&` at the left hand and m `&` right hand, then:
|
||||
// if n < m, we are golden;
|
||||
// if n == m, it's a derefing non-derefable type error;
|
||||
// if n > m, it's a type mismatch error.
|
||||
|
||||
// n < m
|
||||
let &x = &(&1isize as &dyn T);
|
||||
let &x = &&(&1isize as &dyn T);
|
||||
let &&x = &&(&1isize as &dyn T);
|
||||
|
||||
// n == m
|
||||
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
|
||||
|
||||
// n > m
|
||||
let &&x = &1isize as &dyn T;
|
||||
//~^ ERROR mismatched types
|
||||
//~| NOTE expected trait object `dyn T`
|
||||
//~| NOTE found reference `&_`
|
||||
let &&&x = &(&1isize as &dyn T);
|
||||
//~^ ERROR mismatched types
|
||||
//~| NOTE expected trait object `dyn T`
|
||||
//~| NOTE found reference `&_`
|
||||
let box box x = Box::new(1isize) as Box<dyn T>;
|
||||
//~^ ERROR mismatched types
|
||||
//~| NOTE expected trait object `dyn T`
|
||||
//~| NOTE found struct `Box<_>`
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
//@ run-pass
|
||||
|
||||
#![allow(unused_imports)]
|
||||
// Test a regression found when building compiler. The `produce()`
|
||||
// error type `T` winds up getting unified with result of `x.parse()`;
|
||||
// the type of the closure given to `unwrap_or_else` needs to be
|
||||
// inferred to `usize`.
|
||||
|
||||
use std::num::ParseIntError;
|
||||
|
||||
fn produce<T>() -> Result<&'static str, T> {
|
||||
Ok("22")
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x: usize = produce()
|
||||
.and_then(|x| x.parse())
|
||||
.unwrap_or_else(|_| panic!());
|
||||
println!("{}", x);
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
//@ run-pass
|
||||
|
||||
#![allow(warnings)]
|
||||
|
||||
// Here the type of `c` is `Option<?T>`, where `?T` is unconstrained.
|
||||
// Because there is data-flow from the `{ return; }` block, which
|
||||
// diverges and hence has type `!`, into `c`, we will default `?T` to
|
||||
// `!`, and hence this code compiles rather than failing and requiring
|
||||
// a type annotation.
|
||||
|
||||
fn main() {
|
||||
let c = Some({ return; });
|
||||
c.unwrap();
|
||||
}
|
||||
50
tests/ui/generics/default-type-params-well-formedness.rs
Normal file
50
tests/ui/generics/default-type-params-well-formedness.rs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
//! Test for well-formedness checking of default type parameters.
|
||||
//!
|
||||
//! Regression Test for: 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() {}
|
||||
22
tests/ui/never_type/never-type-fallback-option.rs
Normal file
22
tests/ui/never_type/never-type-fallback-option.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
//@ 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
|
||||
//!
|
||||
//! Here the type of `c` is `Option<?T>`, where `?T` is unconstrained.
|
||||
//! Because there is data-flow from the `{ return; }` block, which
|
||||
//! diverges and hence has type `!`, into `c`, we will default `?T` to
|
||||
//! `!`, and hence this code compiles rather than failing and requiring
|
||||
//! a type annotation.
|
||||
|
||||
fn main() {
|
||||
let c = Some({
|
||||
return;
|
||||
});
|
||||
c.unwrap();
|
||||
}
|
||||
29
tests/ui/traits/trait-object-destructure.rs
Normal file
29
tests/ui/traits/trait-object-destructure.rs
Normal file
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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`
|
||||
|
|
@ -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`
|
||||
|
|
@ -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>`
|
||||
19
tests/ui/typeck/inference-method-chain-diverging-fallback.rs
Normal file
19
tests/ui/typeck/inference-method-chain-diverging-fallback.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
//! 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
|
||||
|
||||
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…
Add table
Add a link
Reference in a new issue