Skip to content

Commit 923001e

Browse files
committed
Add tests
1 parent 8dbab51 commit 923001e

File tree

4 files changed

+117
-0
lines changed

4 files changed

+117
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2016 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+
// Check that qualified paths with type parameters
12+
// fail during type checking and not during parsing
13+
14+
struct S;
15+
16+
trait Tr {
17+
type A;
18+
}
19+
20+
impl Tr for S {
21+
type A = S;
22+
}
23+
24+
impl S {
25+
fn f<T>() {}
26+
}
27+
28+
type A = <S as Tr>::A::f<u8>; //~ ERROR type parameters are not allowed on this type
29+
//~^ ERROR ambiguous associated type; specify the type using the syntax `<<S as Tr>::A as Trait>::f`
30+
31+
fn main() {}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2016 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+
// Check that qualified paths with type parameters
12+
// fail during type checking and not during parsing
13+
14+
struct S;
15+
16+
trait Tr {
17+
type A;
18+
}
19+
20+
impl Tr for S {
21+
type A = S;
22+
}
23+
24+
impl S {
25+
fn f<T>() {}
26+
}
27+
28+
fn main() {
29+
match 10 {
30+
<S as Tr>::A::f::<u8> => {} //~ ERROR `f` is not an associated const
31+
0 ... <S as Tr>::A::f::<u8> => {} //~ ERROR only char and numeric types are allowed in range
32+
}
33+
}

src/test/compile-fail/use-keyword.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2016 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+
// Check that imports with nakes super and self don't fail during parsing
12+
// FIXME: this shouldn't fail during name resolution either
13+
14+
mod a {
15+
mod b {
16+
use self as A; //~ ERROR `self` imports are only allowed within a { } list
17+
//~^ ERROR unresolved import `self`. There is no `self` in the crate root
18+
use super as B; //~ ERROR unresolved import `super`. There is no `super` in the crate root
19+
use super::{self as C}; //~ERROR unresolved import `super`. There is no `super` in the crate
20+
}
21+
}
22+
23+
fn main() {}

src/test/run-pass/use-keyword-2.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2016 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+
pub struct A;
12+
13+
mod test {
14+
pub use super :: A;
15+
16+
pub use self :: A as B;
17+
}
18+
19+
impl A {
20+
fn f() {}
21+
fn g() {
22+
Self :: f()
23+
}
24+
}
25+
26+
fn main() {
27+
let a: A = test::A;
28+
let b: A = test::B;
29+
let c: () = A::g();
30+
}

0 commit comments

Comments
 (0)