Skip to content

Commit f3b4492

Browse files
committed
Add some tests around associated types
1 parent fdd719a commit f3b4492

6 files changed

+112
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-pass
12+
13+
#![allow(warnings)]
14+
15+
#![feature(existential_type)]
16+
17+
fn main() {
18+
}
19+
20+
existential type Foo<V>: std::fmt::Debug;
21+
22+
trait Trait<U> {}
23+
24+
fn foo_desugared<T: Trait<[u32; {
25+
#[no_mangle]
26+
static FOO: usize = 42;
27+
3
28+
}]>>(_: T) -> Foo<T> {
29+
(42, std::marker::PhantomData::<T>)
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(existential_type)]
12+
13+
fn main() {
14+
}
15+
16+
trait TraitWithAssoc {
17+
type Assoc;
18+
}
19+
20+
existential type Foo<V>: Trait<V>;
21+
22+
trait Trait<U> {}
23+
24+
impl<W> Trait<W> for () {}
25+
26+
fn foo_desugared<T: TraitWithAssoc>(_: T) -> Foo<T::Assoc> { //~ ERROR non-defining
27+
()
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: non-defining existential type use in defining scope
2+
--> $DIR/bound_reduction2.rs:26:1
3+
|
4+
LL | / fn foo_desugared<T: TraitWithAssoc>(_: T) -> Foo<T::Assoc> { //~ ERROR non-defining
5+
LL | | ()
6+
LL | | }
7+
| |_^
8+
|
9+
note: used non-generic type <T as TraitWithAssoc>::Assoc for generic parameter
10+
--> $DIR/bound_reduction2.rs:20:22
11+
|
12+
LL | existential type Foo<V>: Trait<V>;
13+
| ^
14+
15+
error: aborting due to previous error
16+

src/test/ui/existential_types/no_revealing_outside_defining_module.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ fn bomp() -> boo::Boo {
3232

3333
fn bomp_loop() -> boo::Boo {
3434
loop {}
35-
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(existential_type)]
12+
13+
fn main() {
14+
}
15+
16+
trait TraitWithAssoc {
17+
type Assoc;
18+
}
19+
20+
existential type Foo<V>: Trait<V::Assoc>; //~ associated type `Assoc` not found for `V`
21+
22+
trait Trait<U> {}
23+
24+
impl<W> Trait<W> for () {}
25+
26+
fn foo_desugared<T: TraitWithAssoc>(_: T) -> Foo<T> {
27+
()
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0220]: associated type `Assoc` not found for `V`
2+
--> $DIR/not_well_formed.rs:20:32
3+
|
4+
LL | existential type Foo<V>: Trait<V::Assoc>; //~ associated type `Assoc` not found for `V`
5+
| ^^^^^^^^ associated type `Assoc` not found
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0220`.

0 commit comments

Comments
 (0)