Skip to content

Commit 4a377c9

Browse files
committed
Update tests for dropck normalization errors
Takes crash tests from rust-lang#135039, rust-lang#103899, rust-lang#91985 and rust-lang#105299 and turns them into ui tests
1 parent d8b60da commit 4a377c9

15 files changed

+154
-61
lines changed

tests/crashes/103899.rs

-27
This file was deleted.

tests/crashes/105299.rs

-19
This file was deleted.
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() {}
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 tests/ui/dropck/dropck-only-error-async.rs

+8-5
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() {}
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 tests/ui/dropck/dropck-only-error-gat.rs

+5-4
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
}
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

+23
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() {}
+9
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`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0277]: the trait bound `(): BaseWithAssoc` is not satisfied
2+
--> $DIR/issue-103899.rs:24:54
3+
|
4+
LL | fn trigger<L: WrapperWithAssoc<BaseAssoc = ()>>() -> DoubleProject<L> {
5+
| ^^^^^^^^^^^^^^^^ the trait `BaseWithAssoc` is not implemented for `()`
6+
|
7+
help: this trait has no implementations, consider adding one
8+
--> $DIR/issue-103899.rs:4:1
9+
|
10+
LL | trait BaseWithAssoc {
11+
| ^^^^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to 1 previous error
14+
15+
For more information about this error, try `rustc --explain E0277`.
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0277]: the trait bound `(): BaseWithAssoc` is not satisfied
2+
--> $DIR/issue-103899.rs:24:54
3+
|
4+
LL | fn trigger<L: WrapperWithAssoc<BaseAssoc = ()>>() -> DoubleProject<L> {
5+
| ^^^^^^^^^^^^^^^^ the trait `BaseWithAssoc` is not implemented for `()`
6+
|
7+
help: this trait has no implementations, consider adding one
8+
--> $DIR/issue-103899.rs:4:1
9+
|
10+
LL | trait BaseWithAssoc {
11+
| ^^^^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to 1 previous error
14+
15+
For more information about this error, try `rustc --explain E0277`.

tests/ui/typeck/issue-103899.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
//@ revisions: current next
22
//@ ignore-compare-mode-next-solver (explicit revisions)
3-
//@ check-fail
4-
//@ failure-status: 101
5-
//@ dont-check-compiler-stderr
6-
//@ known-bug: #103899
73

84
trait BaseWithAssoc {
95
type Assoc;
@@ -26,6 +22,7 @@ struct DoubleProject<L: WrapperWithAssoc> {
2622
}
2723

2824
fn trigger<L: WrapperWithAssoc<BaseAssoc = ()>>() -> DoubleProject<L> {
25+
//~^ ERROR the trait bound `(): BaseWithAssoc` is not satisfied [E0277]
2926
loop {}
3027
}
3128

tests/ui/wf/hir-wf-check-erase-regions.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ impl<'a, T, const N: usize> IntoIterator for &'a Table<T, N> {
88
//~^ ERROR `&'a T` is not an iterator
99
type Item = &'a T;
1010

11-
fn into_iter(self) -> Self::IntoIter { //~ ERROR `&'a T` is not an iterator
11+
fn into_iter(self) -> Self::IntoIter {
12+
//~^ ERROR `&'a T` is not an iterator
13+
//~| ERROR `&T` is not an iterator
1214
unimplemented!()
1315
}
1416
}

tests/ui/wf/hir-wf-check-erase-regions.stderr

+11-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ LL | fn into_iter(self) -> Self::IntoIter {
3434
note: required by a bound in `Flatten`
3535
--> $SRC_DIR/core/src/iter/adapters/flatten.rs:LL:COL
3636

37-
error: aborting due to 3 previous errors
37+
error[E0277]: `&T` is not an iterator
38+
--> $DIR/hir-wf-check-erase-regions.rs:11:27
39+
|
40+
LL | fn into_iter(self) -> Self::IntoIter {
41+
| ^^^^^^^^^^^^^^ `&T` is not an iterator
42+
|
43+
= help: the trait `Iterator` is not implemented for `&T`
44+
= help: the trait `Iterator` is implemented for `&mut I`
45+
= note: required for `&T` to implement `IntoIterator`
46+
47+
error: aborting due to 4 previous errors
3848

3949
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)