Skip to content

Commit fae6a31

Browse files
Add UI tests for inherent associated item import attempts
1 parent 4d5ce5d commit fae6a31

2 files changed

Lines changed: 105 additions & 0 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//! Check that when the feature `import_trait_associated_functions` is enabled,
2+
//! and one trys to import inherent associated items, the error message is
3+
//! updated to reflect that only trait associated items can be imported.
4+
//!
5+
//! Regression test for <https://github.com/rust-lang/rust/issues/148009>.
6+
7+
//@ check-fail
8+
9+
#![feature(import_trait_associated_functions, extern_types)]
10+
11+
pub struct TestStruct;
12+
13+
impl TestStruct {
14+
pub fn m1() {}
15+
pub const C1: usize = 0;
16+
}
17+
18+
pub use self::TestStruct::{C1, m1};
19+
//~^ ERROR unresolved import `self::TestStruct` [E0432]
20+
//~| NOTE `TestStruct` is a struct, not a module or a trait
21+
//~| NOTE cannot import inherent associated items, only trait associated items
22+
23+
pub union TestUnion {
24+
pub f: f32,
25+
pub i: i32,
26+
}
27+
28+
impl TestUnion {
29+
pub fn m2() {}
30+
pub const C2: usize = 0;
31+
}
32+
33+
pub use self::TestUnion::{C2, m2};
34+
//~^ ERROR unresolved import `self::TestUnion` [E0432]
35+
//~| NOTE `TestUnion` is a union, not a module or a trait
36+
//~| NOTE cannot import inherent associated items, only trait associated items
37+
38+
pub enum TestEnum {
39+
V1,
40+
V2,
41+
}
42+
43+
impl TestEnum {
44+
pub fn m3() {}
45+
pub const C3: usize = 0;
46+
}
47+
48+
pub use self::TestEnum::{C3, m3};
49+
//~^ ERROR unresolved imports `self::TestEnum::C3`, `self::TestEnum::m3` [E0432]
50+
//~| NOTE no `m3` in `TestEnum`
51+
//~| NOTE no `C3` in `TestEnum`
52+
//~| NOTE cannot import inherent associated items, only trait associated items
53+
54+
extern "C" {
55+
pub type TestForeignTy;
56+
}
57+
58+
impl TestForeignTy {
59+
pub fn m4() {}
60+
pub const C4: usize = 0;
61+
}
62+
63+
pub use self::TestForeignTy::{C4, m4};
64+
//~^ ERROR unresolved import `self::TestForeignTy` [E0432]
65+
//~| NOTE `TestForeignTy` is a foreign type, not a module or a trait
66+
//~| NOTE cannot import inherent associated items, only trait associated items
67+
68+
fn main() {}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
error[E0432]: unresolved import `self::TestStruct`
2+
--> $DIR/import-inherent-148009.rs:18:15
3+
|
4+
LL | pub use self::TestStruct::{C1, m1};
5+
| ^^^^^^^^^^ `TestStruct` is a struct, not a module or a trait
6+
|
7+
= note: cannot import inherent associated items, only trait associated items
8+
9+
error[E0432]: unresolved import `self::TestUnion`
10+
--> $DIR/import-inherent-148009.rs:33:15
11+
|
12+
LL | pub use self::TestUnion::{C2, m2};
13+
| ^^^^^^^^^ `TestUnion` is a union, not a module or a trait
14+
|
15+
= note: cannot import inherent associated items, only trait associated items
16+
17+
error[E0432]: unresolved imports `self::TestEnum::C3`, `self::TestEnum::m3`
18+
--> $DIR/import-inherent-148009.rs:48:26
19+
|
20+
LL | pub use self::TestEnum::{C3, m3};
21+
| ^^ ^^ no `m3` in `TestEnum`
22+
| |
23+
| no `C3` in `TestEnum`
24+
|
25+
= note: cannot import inherent associated items, only trait associated items
26+
27+
error[E0432]: unresolved import `self::TestForeignTy`
28+
--> $DIR/import-inherent-148009.rs:63:15
29+
|
30+
LL | pub use self::TestForeignTy::{C4, m4};
31+
| ^^^^^^^^^^^^^ `TestForeignTy` is a foreign type, not a module or a trait
32+
|
33+
= note: cannot import inherent associated items, only trait associated items
34+
35+
error: aborting due to 4 previous errors
36+
37+
For more information about this error, try `rustc --explain E0432`.

0 commit comments

Comments
 (0)