Skip to content

Commit e17f6c3

Browse files
KivooeoKivooeo
authored andcommitted
cleaned up some tests
1 parent 8072811 commit e17f6c3

15 files changed

+151
-148
lines changed

tests/ui/defaults-well-formedness.rs

Lines changed: 0 additions & 27 deletions
This file was deleted.

tests/ui/deprecation-in-force-unstable.rs renamed to tests/ui/deprecation/deprecated_main_function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
//@ compile-flags:-Zforce-unstable-if-unmarked
33

44
#[deprecated] // should work even with -Zforce-unstable-if-unmarked
5-
fn main() { }
5+
fn main() {}

tests/ui/deref-rc.rs

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/ui/deref.rs

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/ui/derive-uninhabited-enum-38885.rs

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//! Regression test for `#[derive(Debug)]` on enums with uninhabited variants.
2+
//!
3+
//! Ensures there are no special warnings about uninhabited types when deriving
4+
//! Debug on an enum with uninhabited variants, only standard unused warnings.
5+
//!
6+
//! Issue: https://github.com/rust-lang/rust/issues/38885
7+
8+
//@ check-pass
9+
//@ compile-flags: -Wunused
10+
11+
#[derive(Debug)]
12+
enum Void {}
13+
14+
#[derive(Debug)]
15+
enum Foo {
16+
Bar(#[allow(dead_code)] u8),
17+
Void(Void), //~ WARN variant `Void` is never constructed
18+
}
19+
20+
fn main() {
21+
let x = Foo::Bar(42);
22+
println!("{:?}", x);
23+
}

tests/ui/derive-uninhabited-enum-38885.stderr renamed to tests/ui/derives/derive-debug-uninhabited-enum.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: variant `Void` is never constructed
2-
--> $DIR/derive-uninhabited-enum-38885.rs:13:5
2+
--> $DIR/derive-debug-uninhabited-enum.rs:17:5
33
|
44
LL | enum Foo {
55
| --- variant in this enum

tests/ui/destructure-trait-ref.rs

Lines changed: 0 additions & 46 deletions
This file was deleted.

tests/ui/diverging-fallback-method-chain.rs

Lines changed: 0 additions & 20 deletions
This file was deleted.

tests/ui/diverging-fallback-option.rs

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//! Test for well-formedness checking of default type parameters.
2+
//!
3+
//! Regression Test for: https://github.com/rust-lang/rust/issues/49344
4+
5+
//@ run-pass
6+
7+
#![allow(dead_code)]
8+
9+
trait Trait<T> {}
10+
struct Foo<U, V = i32>(U, V)
11+
where
12+
U: Trait<V>;
13+
14+
trait Marker {}
15+
struct TwoParams<T, U>(T, U);
16+
impl Marker for TwoParams<i32, i32> {}
17+
18+
// Clauses with more than 1 param are not checked.
19+
struct IndividuallyBogus<T = i32, U = i32>(TwoParams<T, U>)
20+
where
21+
TwoParams<T, U>: Marker;
22+
23+
struct BogusTogether<T = u32, U = i32>(T, U)
24+
where
25+
TwoParams<T, U>: Marker;
26+
27+
// Clauses with non-defaulted params are not checked.
28+
struct NonDefaultedInClause<T, U = i32>(TwoParams<T, U>)
29+
where
30+
TwoParams<T, U>: Marker;
31+
32+
struct DefaultedLhs<U, V = i32>(U, V)
33+
where
34+
V: Trait<U>;
35+
36+
// Dependent defaults are not checked.
37+
struct Dependent<T, U = T>(T, U)
38+
where
39+
U: Copy;
40+
41+
trait SelfBound<T: Copy = Self> {}
42+
43+
// Not even for well-formedness.
44+
struct WellFormedProjection<A, T = <A as Iterator>::Item>(A, T);
45+
46+
// Issue #49344, predicates with lifetimes should not be checked.
47+
trait Scope<'a> {}
48+
struct Request<'a, S: Scope<'a> = i32>(S, &'a ());
49+
50+
fn main() {}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//@ run-pass
2+
3+
#![allow(warnings)]
4+
5+
//! Tests type inference fallback to `!` (never type) in `Option` context.
6+
//!
7+
//! Regression test for issues:
8+
//! - https://github.com/rust-lang/rust/issues/39808
9+
//! - https://github.com/rust-lang/rust/issues/39984
10+
//!
11+
//! Here the type of `c` is `Option<?T>`, where `?T` is unconstrained.
12+
//! Because there is data-flow from the `{ return; }` block, which
13+
//! diverges and hence has type `!`, into `c`, we will default `?T` to
14+
//! `!`, and hence this code compiles rather than failing and requiring
15+
//! a type annotation.
16+
17+
fn main() {
18+
let c: Option<!> = Some({
19+
return;
20+
});
21+
c.unwrap();
22+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//! Regression test for destructuring trait references (`&dyn T`/`Box<dyn T>`).
2+
//! Checks cases where number of `&`/`Box` patterns (n) matches/doesn't match references (m).
3+
//!
4+
//! Issue: https://github.com/rust-lang/rust/issues/15031
5+
6+
#![feature(box_patterns)]
7+
8+
trait T {
9+
fn foo(&self) {}
10+
}
11+
12+
impl T for isize {}
13+
14+
fn main() {
15+
// Valid cases: n < m (can dereference)
16+
let &x = &(&1isize as &dyn T);
17+
let &x = &&(&1isize as &dyn T);
18+
let &&x = &&(&1isize as &dyn T);
19+
20+
// Error cases: n == m (cannot dereference trait object)
21+
let &x = &1isize as &dyn T; //~ ERROR type `&dyn T` cannot be dereferenced
22+
let &&x = &(&1isize as &dyn T); //~ ERROR type `&dyn T` cannot be dereferenced
23+
let box x = Box::new(1isize) as Box<dyn T>; //~ ERROR type `Box<dyn T>` cannot be dereferenced
24+
25+
// Error cases: n > m (type mismatch)
26+
let &&x = &1isize as &dyn T; //~ ERROR mismatched types
27+
let &&&x = &(&1isize as &dyn T); //~ ERROR mismatched types
28+
let box box x = Box::new(1isize) as Box<dyn T>; //~ ERROR mismatched types
29+
}

tests/ui/destructure-trait-ref.stderr renamed to tests/ui/traits/trait-object-destructure.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
error[E0033]: type `&dyn T` cannot be dereferenced
2-
--> $DIR/destructure-trait-ref.rs:28:9
2+
--> $DIR/trait-object-destructure.rs:21:9
33
|
44
LL | let &x = &1isize as &dyn T;
55
| ^^ type `&dyn T` cannot be dereferenced
66

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

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

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

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

5151
error[E0308]: mismatched types
52-
--> $DIR/destructure-trait-ref.rs:42:13
52+
--> $DIR/trait-object-destructure.rs:28:13
5353
|
5454
LL | let box box x = Box::new(1isize) as Box<dyn T>;
5555
| ^^^^^ ------------------------------ this expression has type `Box<dyn T>`
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//! Test type inference in method chains with diverging fallback.
2+
//! Verifies that closure type in `unwrap_or_else` is properly inferred
3+
//! when chained with other combinators and contains a diverging path.
4+
5+
//@ run-pass
6+
7+
fn produce<T>() -> Result<&'static str, T> {
8+
Ok("22")
9+
}
10+
11+
fn main() {
12+
// The closure's error type `T` must unify with `ParseIntError`,
13+
// while the success type must be `usize` (from parse())
14+
let x: usize = produce()
15+
.and_then(|x| x.parse::<usize>()) // Explicit turbofish for clarity
16+
.unwrap_or_else(|_| panic!()); // Diverging fallback
17+
18+
assert_eq!(x, 22);
19+
}

0 commit comments

Comments
 (0)