Skip to content

Commit 267a70c

Browse files
committed
Import test changes from rust-lang#122553
1 parent 7db37a3 commit 267a70c

File tree

5 files changed

+81
-4
lines changed

5 files changed

+81
-4
lines changed

tests/ui/sized/recursive-type-tail.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@ check-fail
2+
3+
trait A { type Assoc; }
4+
5+
impl A for () {
6+
type Assoc = Foo<()>;
7+
//~^ ERROR overflow evaluating the requirement `<Foo<()> as Pointee>::Metadata == ()`
8+
}
9+
struct Foo<T: A>(T::Assoc);
10+
11+
fn main() {}

tests/ui/trait-bounds/super-assoc-mismatch.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ impl Super for () {
66
}
77
trait Sub: Super<Assoc = u16> {}
88

9+
// direct impls (no nested obligations):
10+
911
trait BoundOnSelf: Sub {}
1012
impl BoundOnSelf for () {}
1113
//~^ ERROR the trait bound `(): Sub` is not satisfied
@@ -25,14 +27,41 @@ impl BoundOnAssoc for () {
2527
trait BoundOnGat where Self::Assoc<u8>: Sub {
2628
type Assoc<T>;
2729
}
28-
impl BoundOnGat for u8 {
30+
impl BoundOnGat for () {
2931
type Assoc<T> = ();
3032
//~^ ERROR the trait bound `(): Sub` is not satisfied
3133
}
3234

3335
fn trivial_bound() where (): Sub {}
3436
//~^ ERROR the trait bound `(): Sub` is not satisfied
3537

38+
// blanket impls with nested obligations:
39+
40+
struct Wrapper<T>(T);
41+
impl<T: Super> Super for Wrapper<T> {
42+
type Assoc = T::Assoc;
43+
}
44+
impl<T: Sub> Sub for Wrapper<T> {}
45+
46+
impl BoundOnSelf for Wrapper<()> {}
47+
//~^ ERROR the trait bound `(): Sub` is not satisfied
48+
49+
impl BoundOnParam<Wrapper<()>> for Wrapper<()> {}
50+
//~^ ERROR the trait bound `(): Sub` is not satisfied
51+
52+
impl BoundOnAssoc for Wrapper<()> {
53+
type Assoc = Wrapper<()>;
54+
//~^ ERROR the trait bound `(): Sub` is not satisfied
55+
}
56+
57+
impl BoundOnGat for Wrapper<()> {
58+
type Assoc<T> = Wrapper<()>;
59+
//~^ ERROR the trait bound `(): Sub` is not satisfied
60+
}
61+
62+
fn trivial_bound_wrapper() where Wrapper<()>: Sub {}
63+
//~^ ERROR the trait bound `(): Sub` is not satisfied
64+
3665
// The following is an edge case where the unsatisfied projection predicate
3766
// `<<u8 as MultiAssoc>::Assoc1<()> as SuperGeneric<u16>>::Assoc == <u8 as MultiAssoc>::Assoc2`
3867
// contains both associated types of `MultiAssoc`. To suppress the error about the unsatisfied

tests/ui/traits/issue-32963.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use std::mem;
22

33
trait Misc {}
44

5-
fn size_of_copy<T: Copy+?Sized>() -> usize { mem::size_of::<T>() }
5+
fn size_of_copy<T: Copy + ?Sized>() -> usize { mem::size_of::<T>() }
66

77
fn main() {
88
size_of_copy::<dyn Misc + Copy>();
99
//~^ ERROR only auto traits can be used as additional traits in a trait object
10+
//~| ERROR the trait bound `dyn Misc<Metadata = ()>: Copy` is not satisfied
1011
}

tests/ui/traits/pointee-normalize-equate.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ fn wrapper_to_unit<T>(ptr: *const ()) -> *const Wrapper<T> {
2626
cast_same_meta(ptr)
2727
}
2828

29+
// normalize `Wrapper<T>::Metadata` -> `()`
30+
fn wrapper_to_unit2<T: ?Sized>(ptr: *const ()) -> *const Wrapper<T>
31+
where
32+
Wrapper<T>: Sized,
33+
{
34+
cast_same_meta(ptr)
35+
}
36+
2937
trait Project {
3038
type Assoc: ?Sized;
3139
}
@@ -45,8 +53,16 @@ where
4553
cast_same_meta(ptr)
4654
}
4755

48-
// normalize `<[T] as Pointee>::Metadata` -> `usize`, even if `[T]: Sized`
49-
fn sized_slice<T>(ptr: *const [T]) -> *const str
56+
// normalize `WrapperProject<T>::Metadata` -> `T::Assoc::Metadata` -> `()`
57+
fn wrapper_project_unit2<T: ?Sized + Project>(ptr: *const ()) -> *const WrapperProject<T>
58+
where
59+
WrapperProject<T>: Sized,
60+
{
61+
cast_same_meta(ptr)
62+
}
63+
64+
// if `[T]: Sized`, then normalize `<[T] as Pointee>::Metadata` -> `()`
65+
fn sized_slice<T>(ptr: *const ()) -> *const [T]
5066
where
5167
[T]: Sized,
5268
{
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//@ check-pass
2+
3+
#![feature(ptr_metadata)]
4+
5+
use std::ptr::Thin;
6+
7+
struct Wrapper<T: ?Sized>(T);
8+
9+
fn check_thin<T: ?Sized + Thin>() {}
10+
11+
// Test that normalization of `<Wrapper<[T]> as Pointee>::Metadata` respects the
12+
// `<[T] as Pointee>::Metadata == ()` bound from the param env.
13+
fn foo<T>()
14+
where
15+
[T]: Thin,
16+
{
17+
check_thin::<Wrapper<[T]>>();
18+
}
19+
20+
fn main() {}

0 commit comments

Comments
 (0)