Skip to content

Commit b010dd8

Browse files
Update UI tests and add new UI tests for implementations on projections
1 parent 8ecab44 commit b010dd8

10 files changed

+152
-16
lines changed

tests/ui/privacy/private-in-public-ill-formed.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ mod aliases_pub {
1212
}
1313

1414
impl <Priv as PrivTr>::AssocAlias {
15-
//~^ ERROR no nominal type found for inherent implementation
16-
pub fn f(arg: Priv) {} // private type `aliases_pub::Priv` in public interface
15+
pub fn f(arg: Priv) {}
16+
//~^ ERROR private type `aliases_pub::Priv` in public interface
17+
//~| ERROR private type `aliases_pub::Priv` in public interface
18+
//~| ERROR private trait `aliases_pub::PrivTr` in public interface
1719
}
1820
}
1921

@@ -29,7 +31,6 @@ mod aliases_priv {
2931
}
3032

3133
impl <Priv as PrivTr>::AssocAlias {
32-
//~^ ERROR no nominal type found for inherent implementation
3334
pub fn f(arg: Priv) {} // OK
3435
}
3536
}
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
1-
error[E0118]: no nominal type found for inherent implementation
2-
--> $DIR/private-in-public-ill-formed.rs:14:10
1+
error[E0446]: private type `aliases_pub::Priv` in public interface
2+
--> $DIR/private-in-public-ill-formed.rs:15:9
33
|
4-
LL | impl <Priv as PrivTr>::AssocAlias {
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl requires a nominal type
6-
|
7-
= note: either implement a trait on it or create a newtype to wrap it instead
4+
LL | struct Priv;
5+
| ----------- `aliases_pub::Priv` declared as private
6+
...
7+
LL | pub fn f(arg: Priv) {}
8+
| ^^^^^^^^^^^^^^^^^^^ can't leak private type
89

9-
error[E0118]: no nominal type found for inherent implementation
10-
--> $DIR/private-in-public-ill-formed.rs:31:10
10+
error[E0445]: private trait `aliases_pub::PrivTr` in public interface
11+
--> $DIR/private-in-public-ill-formed.rs:15:9
1112
|
12-
LL | impl <Priv as PrivTr>::AssocAlias {
13-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl requires a nominal type
13+
LL | trait PrivTr {
14+
| ------------ `aliases_pub::PrivTr` declared as private
15+
...
16+
LL | pub fn f(arg: Priv) {}
17+
| ^^^^^^^^^^^^^^^^^^^ can't leak private trait
18+
19+
error[E0446]: private type `aliases_pub::Priv` in public interface
20+
--> $DIR/private-in-public-ill-formed.rs:15:9
1421
|
15-
= note: either implement a trait on it or create a newtype to wrap it instead
22+
LL | struct Priv;
23+
| ----------- `aliases_pub::Priv` declared as private
24+
...
25+
LL | pub fn f(arg: Priv) {}
26+
| ^^^^^^^^^^^^^^^^^^^ can't leak private type
1627

17-
error: aborting due to 2 previous errors
28+
error: aborting due to 3 previous errors
1829

19-
For more information about this error, try `rustc --explain E0118`.
30+
Some errors have detailed explanations: E0445, E0446.
31+
For more information about an error, try `rustc --explain E0445`.

tests/ui/projection/impl-foreign.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![crate_type = "lib"]
2+
3+
pub trait Identity {
4+
type Identity: ?Sized;
5+
}
6+
7+
impl<T: ?Sized> Identity for T {
8+
type Identity = Self;
9+
}
10+
11+
impl <String as Identity>::Identity { //~ ERROR
12+
pub fn foo(&self) {}
13+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0116]: cannot define inherent `impl` for a type outside of the crate where the type is defined
2+
--> $DIR/impl-foreign.rs:11:1
3+
|
4+
LL | / impl <String as Identity>::Identity {
5+
LL | | pub fn foo(&self) {}
6+
LL | | }
7+
| |_^ impl for type defined outside of crate.
8+
|
9+
= note: define and implement a trait or new type instead
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0116`.
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![crate_type = "lib"]
2+
3+
pub trait Identity {
4+
const Identity: u32;
5+
}
6+
7+
impl<T: ?Sized> Identity for T {
8+
const Identity: u32 = 0;
9+
}
10+
11+
pub struct S;
12+
13+
impl <S as Identity>::Identity { //~ ERROR
14+
pub fn foo(&self) {}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0575]: expected associated type, found associated constant `Identity::Identity`
2+
--> $DIR/impl-on-assoc-const.rs:13:6
3+
|
4+
LL | impl <S as Identity>::Identity {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ not a associated type
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0575`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![crate_type = "lib"]
2+
3+
pub trait Identity {
4+
type Identity: ?Sized;
5+
}
6+
7+
impl<T: ?Sized> Identity for T {
8+
type Identity = ();
9+
}
10+
11+
pub struct S;
12+
13+
impl <S as Identity>::Identity { //~ ERROR
14+
pub fn foo(&self) {}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0390]: cannot define inherent `impl` for primitive types
2+
--> $DIR/impl-projection-on-primitive.rs:13:6
3+
|
4+
LL | impl <S as Identity>::Identity {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: consider using an extension trait instead
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0390`.
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// check-pass
2+
3+
#![crate_type = "lib"]
4+
5+
pub trait Identity {
6+
type Identity: ?Sized;
7+
}
8+
9+
impl<T: ?Sized> Identity for T {
10+
type Identity = Self;
11+
}
12+
13+
pub struct S;
14+
15+
impl <S as Identity>::Identity {
16+
pub fn foo(&self) {}
17+
}
18+
19+
impl S {
20+
pub fn bar(&self) {
21+
self.foo();
22+
}
23+
}
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// check-pass
2+
3+
#![crate_type = "lib"]
4+
5+
pub trait Identity {
6+
type Identity: ?Sized;
7+
}
8+
9+
impl<T: ?Sized> Identity for T {
10+
type Identity = S;
11+
}
12+
13+
pub struct S;
14+
pub struct Bar;
15+
16+
impl <Bar as Identity>::Identity {
17+
pub fn foo(&self) {}
18+
}
19+
20+
impl S {
21+
pub fn bar(&self) {
22+
self.foo();
23+
}
24+
}

0 commit comments

Comments
 (0)