Skip to content

Commit d42d952

Browse files
authored
Rollup merge of #106676 - oli-obk:tait_test, r=dtolnay
Test that we cannot use trait impl methods arguments as defining uses Addresses #63063 (comment) r? `@dtolnay`
2 parents db8301b + 44a5ce6 commit d42d952

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#![feature(type_alias_impl_trait)]
2+
3+
// This test ensures that unnameable types stay unnameable
4+
// https://github.com/rust-lang/rust/issues/63063#issuecomment-1360053614
5+
6+
// library
7+
mod private {
8+
pub struct Private;
9+
pub trait Trait {
10+
fn dont_define_this(_private: Private) {}
11+
}
12+
}
13+
14+
use private::Trait;
15+
16+
// downstream
17+
type MyPrivate = impl Sized;
18+
//~^ ERROR: unconstrained opaque type
19+
impl Trait for u32 {
20+
fn dont_define_this(_private: MyPrivate) {}
21+
//~^ ERROR: incompatible type for trait
22+
}
23+
24+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
error: unconstrained opaque type
2+
--> $DIR/unnameable_type.rs:17:18
3+
|
4+
LL | type MyPrivate = impl Sized;
5+
| ^^^^^^^^^^
6+
|
7+
= note: `MyPrivate` must be used in combination with a concrete type within the same module
8+
9+
error[E0053]: method `dont_define_this` has an incompatible type for trait
10+
--> $DIR/unnameable_type.rs:20:35
11+
|
12+
LL | type MyPrivate = impl Sized;
13+
| ---------- the found opaque type
14+
...
15+
LL | fn dont_define_this(_private: MyPrivate) {}
16+
| ^^^^^^^^^
17+
| |
18+
| expected struct `Private`, found opaque type
19+
| help: change the parameter type to match the trait: `Private`
20+
|
21+
note: type in trait
22+
--> $DIR/unnameable_type.rs:10:39
23+
|
24+
LL | fn dont_define_this(_private: Private) {}
25+
| ^^^^^^^
26+
= note: expected signature `fn(Private)`
27+
found signature `fn(MyPrivate)`
28+
29+
error: aborting due to 2 previous errors
30+
31+
For more information about this error, try `rustc --explain E0053`.

0 commit comments

Comments
 (0)