Skip to content

Commit cbc42a0

Browse files
committed
Auto merge of rust-lang#77956 - JohnTitor:more-tests, r=nagisa
Add some more regression tests This is another round of rust-lang#77741. Tested with `debug-assertions=true` and it passed on my local. Closes rust-lang#70877 Closes rust-lang#70944 Closes rust-lang#71659 Closes rust-lang#74816 Closes rust-lang#75707 Closes rust-lang#75983 (Skipped rust-lang#63355 because I'm not sure about the error.)
2 parents 3b0ef34 + d80f93d commit cbc42a0

File tree

10 files changed

+217
-0
lines changed

10 files changed

+217
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#![feature(associated_type_defaults)]
2+
#![feature(generic_associated_types)]
3+
#![allow(incomplete_features)]
4+
5+
trait Trait1 {
6+
fn foo();
7+
}
8+
9+
trait Trait2 {
10+
type Associated: Trait1 = Self;
11+
//~^ ERROR: the trait bound `Self: Trait1` is not satisfied
12+
//~| the size for values of type `Self` cannot be known
13+
}
14+
15+
impl Trait2 for () {}
16+
17+
fn call_foo<T: Trait2>() {
18+
T::Associated::foo()
19+
}
20+
21+
fn main() {
22+
call_foo::<()>()
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
error[E0277]: the trait bound `Self: Trait1` is not satisfied
2+
--> $DIR/issue-74816.rs:10:5
3+
|
4+
LL | type Associated: Trait1 = Self;
5+
| ^^^^^^^^^^^^^^^^^------^^^^^^^^
6+
| | |
7+
| | required by this bound in `Trait2::Associated`
8+
| the trait `Trait1` is not implemented for `Self`
9+
|
10+
help: consider further restricting `Self`
11+
|
12+
LL | trait Trait2: Trait1 {
13+
| ^^^^^^^^
14+
15+
error[E0277]: the size for values of type `Self` cannot be known at compilation time
16+
--> $DIR/issue-74816.rs:10:5
17+
|
18+
LL | type Associated: Trait1 = Self;
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20+
| |
21+
| doesn't have a size known at compile-time
22+
| required by this bound in `Trait2::Associated`
23+
|
24+
help: consider further restricting `Self`
25+
|
26+
LL | trait Trait2: Sized {
27+
| ^^^^^^^
28+
29+
error: aborting due to 2 previous errors
30+
31+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#![feature(type_alias_impl_trait)]
2+
#![feature(impl_trait_in_bindings)]
3+
#![allow(incomplete_features)]
4+
5+
type FooArg<'a> = &'a dyn ToString;
6+
type FooRet = impl std::fmt::Debug;
7+
8+
type FooItem = Box<dyn Fn(FooArg) -> FooRet>;
9+
type Foo = impl Iterator<Item = FooItem>; //~ ERROR: type mismatch
10+
11+
#[repr(C)]
12+
struct Bar(u8);
13+
14+
impl Iterator for Bar {
15+
type Item = FooItem;
16+
17+
fn next(&mut self) -> Option<Self::Item> {
18+
Some(Box::new(quux))
19+
}
20+
}
21+
22+
fn quux(st: FooArg) -> FooRet {
23+
Some(st.to_string())
24+
}
25+
26+
fn ham() -> Foo {
27+
Bar(1)
28+
}
29+
30+
fn oof() -> impl std::fmt::Debug {
31+
let mut bar = ham();
32+
let func = bar.next().unwrap();
33+
return func(&"oof");
34+
}
35+
36+
fn main() {
37+
let _ = oof();
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0271]: type mismatch resolving `<Bar as Iterator>::Item == Box<(dyn for<'r> Fn(&'r (dyn ToString + 'r)) -> Option<String> + 'static)>`
2+
--> $DIR/issue-70877.rs:9:12
3+
|
4+
LL | type FooRet = impl std::fmt::Debug;
5+
| -------------------- the expected opaque type
6+
...
7+
LL | type Foo = impl Iterator<Item = FooItem>;
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected opaque type, found enum `Option`
9+
|
10+
= note: expected struct `Box<(dyn for<'r> Fn(&'r (dyn ToString + 'r)) -> impl Debug + 'static)>`
11+
found struct `Box<(dyn for<'r> Fn(&'r (dyn ToString + 'r)) -> Option<String> + 'static)>`
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0271`.

src/test/ui/traits/issue-70944.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// check-pass
2+
// Regression test of #70944, should compile fine.
3+
4+
use std::ops::Index;
5+
6+
pub struct KeyA;
7+
pub struct KeyB;
8+
pub struct KeyC;
9+
10+
pub trait Foo: Index<KeyA> + Index<KeyB> + Index<KeyC> {}
11+
pub trait FooBuilder {
12+
type Inner: Foo;
13+
fn inner(&self) -> &Self::Inner;
14+
}
15+
16+
pub fn do_stuff(foo: &impl FooBuilder) {
17+
let inner = foo.inner();
18+
&inner[KeyA];
19+
&inner[KeyB];
20+
&inner[KeyC];
21+
}
22+
23+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// check-pass
2+
3+
#![feature(trait_alias)]
4+
5+
struct Bar;
6+
trait Foo {}
7+
impl Foo for Bar {}
8+
9+
trait Baz = Foo where Bar: Foo;
10+
11+
fn new() -> impl Baz {
12+
Bar
13+
}
14+
15+
fn main() {
16+
let _ = new();
17+
}

src/test/ui/unsized/issue-71659.rs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#![feature(unsize)]
2+
3+
use std::marker::Unsize;
4+
5+
pub trait CastTo<T: ?Sized>: Unsize<T> {
6+
fn cast_to(&self) -> &T;
7+
}
8+
9+
impl<T: ?Sized, U: ?Sized + Unsize<T>> CastTo<T> for U {
10+
fn cast_to(&self) -> &T {
11+
self
12+
}
13+
}
14+
15+
impl<T: ?Sized> Cast for T {}
16+
pub trait Cast {
17+
fn cast<T: ?Sized>(&self) -> &T
18+
where
19+
Self: CastTo<T>,
20+
{
21+
self
22+
}
23+
}
24+
25+
pub trait Foo: CastTo<[i32]> {}
26+
impl Foo for [i32; 0] {}
27+
28+
fn main() {
29+
let x: &dyn Foo = &[];
30+
let x = x.cast::<[i32]>();
31+
//~^ ERROR: the trait bound `dyn Foo: CastTo<[i32]>` is not satisfied
32+
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0277]: the trait bound `dyn Foo: CastTo<[i32]>` is not satisfied
2+
--> $DIR/issue-71659.rs:30:15
3+
|
4+
LL | let x = x.cast::<[i32]>();
5+
| ^^^^ the trait `CastTo<[i32]>` is not implemented for `dyn Foo`
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0277`.

src/test/ui/unsized/issue-75707.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
pub trait Callback {
2+
fn cb();
3+
}
4+
5+
pub trait Processing {
6+
type Call: Callback;
7+
}
8+
9+
fn f<P: Processing + ?Sized>() {
10+
P::Call::cb();
11+
}
12+
13+
fn main() {
14+
struct MyCall;
15+
f::<dyn Processing<Call = MyCall>>();
16+
//~^ ERROR: the trait bound `MyCall: Callback` is not satisfied
17+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0277]: the trait bound `MyCall: Callback` is not satisfied
2+
--> $DIR/issue-75707.rs:15:5
3+
|
4+
LL | fn f<P: Processing + ?Sized>() {
5+
| ---------- required by this bound in `f`
6+
...
7+
LL | f::<dyn Processing<Call = MyCall>>();
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Callback` is not implemented for `MyCall`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)