Skip to content

Commit 6eb6455

Browse files
committed
Add a test and several known bugs
1 parent 77ea90e commit 6eb6455

8 files changed

+127
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// known-bug: unknown
2+
// failure-status: 101
3+
// normalize-stderr-test "note: .*\n\n" -> ""
4+
// normalize-stderr-test "thread 'rustc' panicked.*\n" -> ""
5+
// rustc-env:RUST_BACKTRACE=0
6+
7+
// FIXME: I presume a type variable that couldn't be solved by `resolve_vars_if_possible`
8+
// escapes the InferCtxt snapshot.
9+
10+
#![feature(inherent_associated_types)]
11+
#![allow(incomplete_features)]
12+
13+
struct Cont<T>(T);
14+
15+
impl<T: Copy> Cont<T> {
16+
type Out = Vec<T>;
17+
}
18+
19+
pub fn weird<T: Copy>(x: T) {
20+
let _: Cont<_>::Out = vec![true];
21+
}
22+
23+
fn main() {}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
error: the compiler unexpectedly panicked. this is a bug.
2+
3+
query stack during panic:
4+
#0 [typeck] type-checking `weird`
5+
#1 [typeck_item_bodies] type-checking all item bodies
6+
end of query stack
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// known-bug: unknown
2+
3+
#![feature(inherent_associated_types)]
4+
#![allow(incomplete_features)]
5+
6+
struct S<T>(T);
7+
8+
impl S<()> {
9+
type P = i128;
10+
}
11+
12+
fn main() {
13+
// We fail to infer `_ == ()` here.
14+
let _: S<_>::P;
15+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/inference-fail.rs:14:14
3+
|
4+
LL | let _: S<_>::P;
5+
| ^ cannot infer type
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0282`.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// known-bug: unknown
2+
// check-pass
3+
4+
// We currently don't region-check inherent associated type projections at all.
5+
6+
#![feature(inherent_associated_types)]
7+
#![allow(incomplete_features, dead_code)]
8+
9+
struct S<T>(T);
10+
11+
impl S<&'static ()> {
12+
type T = ();
13+
}
14+
15+
fn usr<'a>() {
16+
let _: S::<&'a ()>::T; // this should *fail* but it doesn't!
17+
}
18+
19+
fn main() {}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#![feature(inherent_associated_types)]
2+
#![allow(incomplete_features)]
3+
4+
// Check that it's okay to report “[inherent] associated type […] not found” for inherent associated
5+
// type candidates that are not applicable (due to unsuitable Self type) even if there exists a
6+
// “shadowed” associated type from a trait with the same name since its use would be ambiguous
7+
// anyway if the IAT didn't exist.
8+
// FIXME(inherent_associated_types): Figure out which error would be more helpful here.
9+
10+
// revisions: shadowed uncovered
11+
12+
struct S<T>(T);
13+
14+
trait Tr {
15+
type Pr;
16+
}
17+
18+
impl<T> Tr for S<T> {
19+
type Pr = ();
20+
}
21+
22+
#[cfg(shadowed)]
23+
impl S<()> {
24+
type Pr = i32;
25+
}
26+
27+
fn main() {
28+
let _: S::<bool>::Pr = ();
29+
//[shadowed]~^ ERROR associated type `Pr` not found
30+
//[uncovered]~^^ ERROR ambiguous associated type
31+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0220]: associated type `Pr` not found for `S<bool>` in the current scope
2+
--> $DIR/not-found-self-type-differs-shadowing-trait-item.rs:28:23
3+
|
4+
LL | struct S<T>(T);
5+
| ----------- associated item `Pr` not found for this struct
6+
...
7+
LL | let _: S::<bool>::Pr = ();
8+
| ^^ associated item not found in `S<bool>`
9+
|
10+
= note: the associated type was found for
11+
- `S<()>`
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0220`.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0223]: ambiguous associated type
2+
--> $DIR/not-found-self-type-differs-shadowing-trait-item.rs:28:12
3+
|
4+
LL | let _: S::<bool>::Pr = ();
5+
| ^^^^^^^^^^^^^ help: use the fully-qualified path: `<S<bool> as Tr>::Pr`
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0223`.

0 commit comments

Comments
 (0)