Skip to content

Commit defefbc

Browse files
committed
Update tests for dropck normalization errors
Takes crash tests from #135039, #103899, #91985 and #105299 and turns them into ui tests
1 parent 8195e8b commit defefbc

15 files changed

+154
-61
lines changed

tests/crashes/103899.rs

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

tests/crashes/105299.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+
// Test that we don't ICE for a typeck error that only shows up in dropck
2+
// Version where the normalization error is an ambiguous trait implementation.
3+
// <[T] as ToOwned>::Owned is ambiguous on whether to use T: Clone or [T]::Clone.
4+
// Regression test for #105299
5+
6+
pub trait Foo: Clone {}
7+
8+
pub struct Bar<'a, T: Clone> {
9+
pub cow: std::borrow::Cow<'a, [T]>,
10+
11+
pub THIS_CAUSES_ICE: (),
12+
}
13+
14+
impl<T> Bar<'_, T>
15+
where
16+
T: Clone,
17+
[T]: Foo,
18+
{
19+
pub fn MOVES_SELF(self) {}
20+
//~^ ERROR type annotations needed
21+
}
22+
23+
pub fn main() {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0284]: type annotations needed
2+
--> $DIR/dropck-only-error-ambiguity.rs:19:23
3+
|
4+
LL | pub fn MOVES_SELF(self) {}
5+
| ^^^^ cannot infer type
6+
|
7+
= note: cannot satisfy `<[T] as ToOwned>::Owned == _`
8+
9+
error: aborting due to 1 previous error
10+
11+
For more information about this error, try `rustc --explain E0284`.

tests/crashes/135039.rs renamed to tests/ui/dropck/dropck-only-error-async.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
//@ known-bug: #135039
2-
//@ edition:2021
3-
4-
pub type UserId<Backend> = <<Backend as AuthnBackend>::User as AuthUser>::Id;
1+
// Test that we don't ICE for a typeck error that only shows up in dropck
2+
// issue #135039
3+
//@ edition:2018
54

65
pub trait AuthUser {
76
type Id;
@@ -13,7 +12,7 @@ pub trait AuthnBackend {
1312

1413
pub struct AuthSession<Backend: AuthnBackend> {
1514
user: Option<Backend::User>,
16-
data: Option<UserId<Backend>>,
15+
data: Option<<<Backend as AuthnBackend>::User as AuthUser>::Id>,
1716
}
1817

1918
pub trait Authz: Sized {
@@ -27,8 +26,12 @@ pub trait Query<User: Authz> {
2726

2827
pub async fn run_query<User: Authz, Q: Query<User> + 'static>(
2928
auth: AuthSession<User::AuthnBackend>,
29+
//~^ ERROR the trait bound `User: AuthUser` is not satisfied [E0277]
30+
//~| ERROR the trait bound `User: AuthUser` is not satisfied [E0277]
3031
query: Q,
3132
) -> Result<Q::Output, ()> {
3233
let user = auth.user;
3334
query.run().await
3435
}
36+
37+
fn main() {}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0277]: the trait bound `User: AuthUser` is not satisfied
2+
--> $DIR/dropck-only-error-async.rs:28:5
3+
|
4+
LL | auth: AuthSession<User::AuthnBackend>,
5+
| ^^^^ the trait `AuthUser` is not implemented for `User`
6+
7+
error[E0277]: the trait bound `User: AuthUser` is not satisfied
8+
--> $DIR/dropck-only-error-async.rs:28:5
9+
|
10+
LL | auth: AuthSession<User::AuthnBackend>,
11+
| ^^^^ the trait `AuthUser` is not implemented for `User`
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0277`.

tests/crashes/91985.rs renamed to tests/ui/dropck/dropck-only-error-gat.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
//@ known-bug: #91985
2-
3-
#![feature(generic_associated_types)]
1+
// Test that we don't ICE for a typeck error that only shows up in dropck
2+
// Version that uses a generic associated type
3+
// Regression test for #91985
44

55
pub trait Trait1 {
66
type Associated: Ord;
@@ -22,7 +22,7 @@ impl GatTrait for GatStruct {
2222

2323
pub struct OuterStruct<T1: Trait1, T2: Trait2> {
2424
inner: InnerStruct<T2, GatStruct>,
25-
t1: T1,
25+
t1: T1,
2626
}
2727

2828
pub struct InnerStruct<T: Trait2, G: GatTrait> {
@@ -35,6 +35,7 @@ where
3535
T2: Trait2<Associated = T1::Associated>,
3636
{
3737
pub fn new() -> Self {
38+
//~^ ERROR the trait bound `<T1 as Trait1>::Associated: Clone` is not satisfied
3839
todo!()
3940
}
4041
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0277]: the trait bound `<T1 as Trait1>::Associated: Clone` is not satisfied
2+
--> $DIR/dropck-only-error-gat.rs:37:21
3+
|
4+
LL | pub fn new() -> Self {
5+
| ^^^^ the trait `Clone` is not implemented for `<T1 as Trait1>::Associated`
6+
|
7+
note: required by a bound in `GatTrait::Gat`
8+
--> $DIR/dropck-only-error-gat.rs:14:17
9+
|
10+
LL | type Gat<T: Clone>;
11+
| ^^^^^ required by this bound in `GatTrait::Gat`
12+
13+
error: aborting due to 1 previous error
14+
15+
For more information about this error, try `rustc --explain E0277`.

tests/ui/dropck/dropck-only-error.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Test that we don't ICE for a typeck error that only shows up in dropck
2+
// issue #135039
3+
4+
pub trait AuthUser {
5+
type Id;
6+
}
7+
8+
pub trait AuthnBackend {
9+
type User: AuthUser;
10+
}
11+
12+
pub struct AuthSession<Backend: AuthnBackend> {
13+
data: Option<<<Backend as AuthnBackend>::User as AuthUser>::Id>,
14+
}
15+
16+
pub trait Authz: Sized {
17+
type AuthnBackend: AuthnBackend<User = Self>;
18+
}
19+
20+
pub fn run_query<User: Authz>(auth: AuthSession<User::AuthnBackend>) {}
21+
//~^ ERROR the trait bound `User: AuthUser` is not satisfied [E0277]
22+
23+
fn main() {}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0277]: the trait bound `User: AuthUser` is not satisfied
2+
--> $DIR/dropck-only-error.rs:20:31
3+
|
4+
LL | pub fn run_query<User: Authz>(auth: AuthSession<User::AuthnBackend>) {}
5+
| ^^^^ the trait `AuthUser` is not implemented for `User`
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)